DTOs
This commit is contained in:
Submodule LightlessAPI updated: 4918a2c4e3...4ce70bee83
@@ -1,4 +1,5 @@
|
|||||||
using LightlessSync.API.Routes;
|
using LightlessSync.API.Dto.User;
|
||||||
|
using LightlessSync.API.Routes;
|
||||||
using LightlessSyncShared.Data;
|
using LightlessSyncShared.Data;
|
||||||
using Microsoft.AspNetCore.Authorization;
|
using Microsoft.AspNetCore.Authorization;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
@@ -20,14 +21,14 @@ public class UserController : Controller
|
|||||||
|
|
||||||
[Route(LightlessAuth.Ban_Uid)]
|
[Route(LightlessAuth.Ban_Uid)]
|
||||||
[HttpPost]
|
[HttpPost]
|
||||||
public async Task MarkForBanUid([FromBody] string uid)
|
public async Task MarkForBanUid([FromBody] BanRequest request)
|
||||||
{
|
{
|
||||||
using var dbContext = await LightlessDbContextFactory.CreateDbContextAsync();
|
using var dbContext = await LightlessDbContextFactory.CreateDbContextAsync();
|
||||||
|
|
||||||
Logger.LogInformation("Banning user with UID {UID}", uid);
|
Logger.LogInformation("Banning user with UID {UID}", request.Uid);
|
||||||
|
|
||||||
//Mark User as banned, and not marked for ban
|
//Mark User as banned, and not marked for ban
|
||||||
var auth = await dbContext.Auth.FirstOrDefaultAsync(f => f.UserUID == uid);
|
var auth = await dbContext.Auth.FirstOrDefaultAsync(f => f.UserUID == request.Uid);
|
||||||
if (auth != null)
|
if (auth != null)
|
||||||
{
|
{
|
||||||
auth.MarkForBan = true;
|
auth.MarkForBan = true;
|
||||||
@@ -38,14 +39,14 @@ public class UserController : Controller
|
|||||||
|
|
||||||
[Route(LightlessAuth.User_Unban_Uid)]
|
[Route(LightlessAuth.User_Unban_Uid)]
|
||||||
[HttpPost]
|
[HttpPost]
|
||||||
public async Task UnBanUserByUid([FromBody] string uid)
|
public async Task UnBanUserByUid([FromBody] UnbanRequest request)
|
||||||
{
|
{
|
||||||
using var dbContext = await LightlessDbContextFactory.CreateDbContextAsync();
|
using var dbContext = await LightlessDbContextFactory.CreateDbContextAsync();
|
||||||
|
|
||||||
Logger.LogInformation("Unbanning user with UID {UID}", uid);
|
Logger.LogInformation("Unbanning user with UID {UID}", request.Uid);
|
||||||
|
|
||||||
//Mark User as not banned, and not marked for ban (if marked)
|
//Mark User as not banned, and not marked for ban (if marked)
|
||||||
var auth = await dbContext.Auth.FirstOrDefaultAsync(f => f.UserUID == uid);
|
var auth = await dbContext.Auth.FirstOrDefaultAsync(f => f.UserUID == request.Uid);
|
||||||
if (auth != null)
|
if (auth != null)
|
||||||
{
|
{
|
||||||
auth.IsBanned = false;
|
auth.IsBanned = false;
|
||||||
@@ -53,11 +54,11 @@ public class UserController : Controller
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Remove all bans associated with this user
|
// Remove all bans associated with this user
|
||||||
var bannedFromLightlessIds = dbContext.BannedUsers.Where(b => b.BannedUid == uid);
|
var bannedFromLightlessIds = dbContext.BannedUsers.Where(b => b.BannedUid == request.Uid);
|
||||||
dbContext.BannedUsers.RemoveRange(bannedFromLightlessIds);
|
dbContext.BannedUsers.RemoveRange(bannedFromLightlessIds);
|
||||||
|
|
||||||
// Remove all character/discord bans associated with this user
|
// Remove all character/discord bans associated with this user
|
||||||
var lodestoneAuths = dbContext.LodeStoneAuth.Where(l => l.User != null && l.User.UID == uid).ToList();
|
var lodestoneAuths = dbContext.LodeStoneAuth.Where(l => l.User != null && l.User.UID == request.Uid).ToList();
|
||||||
foreach (var lodestoneAuth in lodestoneAuths)
|
foreach (var lodestoneAuth in lodestoneAuths)
|
||||||
{
|
{
|
||||||
var bannedRegs = dbContext.BannedRegistrations.Where(b => b.DiscordIdOrLodestoneAuth == lodestoneAuth.HashedLodestoneId || b.DiscordIdOrLodestoneAuth == lodestoneAuth.DiscordId.ToString());
|
var bannedRegs = dbContext.BannedRegistrations.Where(b => b.DiscordIdOrLodestoneAuth == lodestoneAuth.HashedLodestoneId || b.DiscordIdOrLodestoneAuth == lodestoneAuth.DiscordId.ToString());
|
||||||
@@ -69,19 +70,19 @@ public class UserController : Controller
|
|||||||
|
|
||||||
[Route(LightlessAuth.User_Unban_Discord)]
|
[Route(LightlessAuth.User_Unban_Discord)]
|
||||||
[HttpPost]
|
[HttpPost]
|
||||||
public async Task UnBanUserByDiscordId([FromBody] string discordId)
|
public async Task UnBanUserByDiscordId([FromBody] UnbanRequest request)
|
||||||
{
|
{
|
||||||
Logger.LogInformation("Unbanning user with discordId: {discordId}", discordId);
|
Logger.LogInformation("Unbanning user with discordId: {discordId}", request.DiscordId);
|
||||||
using var dbContext = await LightlessDbContextFactory.CreateDbContextAsync();
|
using var dbContext = await LightlessDbContextFactory.CreateDbContextAsync();
|
||||||
|
|
||||||
var userByDiscord = await dbContext.LodeStoneAuth.Include(l => l.User).FirstOrDefaultAsync(l => l.DiscordId.ToString() == discordId);
|
var userByDiscord = await dbContext.LodeStoneAuth.Include(l => l.User).FirstOrDefaultAsync(l => l.DiscordId.ToString() == request.DiscordId);
|
||||||
|
|
||||||
if (userByDiscord?.User == null)
|
if (userByDiscord?.User == null)
|
||||||
{
|
{
|
||||||
Logger.LogInformation("Unbanning user with discordId: {discordId} but no user found", discordId);
|
Logger.LogInformation("Unbanning user with discordId: {discordId} but no user found", request.DiscordId);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var bannedRegs = dbContext.BannedRegistrations.Where(b => b.DiscordIdOrLodestoneAuth == discordId || b.DiscordIdOrLodestoneAuth == userByDiscord.HashedLodestoneId);
|
var bannedRegs = dbContext.BannedRegistrations.Where(b => b.DiscordIdOrLodestoneAuth == request.DiscordId || b.DiscordIdOrLodestoneAuth == userByDiscord.HashedLodestoneId);
|
||||||
//Mark User as not banned, and not marked for ban (if marked)
|
//Mark User as not banned, and not marked for ban (if marked)
|
||||||
var auth = await dbContext.Auth.FirstOrDefaultAsync(f => f.UserUID == userByDiscord.User.UID);
|
var auth = await dbContext.Auth.FirstOrDefaultAsync(f => f.UserUID == userByDiscord.User.UID);
|
||||||
if (auth != null)
|
if (auth != null)
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ using LightlessSyncShared.Services;
|
|||||||
using StackExchange.Redis;
|
using StackExchange.Redis;
|
||||||
using LightlessSync.API.Data.Enum;
|
using LightlessSync.API.Data.Enum;
|
||||||
using LightlessSyncShared.Utils.Configuration;
|
using LightlessSyncShared.Utils.Configuration;
|
||||||
|
using LightlessSync.API.Dto.User;
|
||||||
|
|
||||||
namespace LightlessSyncServices.Discord;
|
namespace LightlessSyncServices.Discord;
|
||||||
|
|
||||||
@@ -146,7 +147,7 @@ public class LightlessModule : InteractionModuleBase
|
|||||||
}
|
}
|
||||||
|
|
||||||
[SlashCommand("unbanbydiscord", "ADMIN ONLY: Unban a user by their discord ID")]
|
[SlashCommand("unbanbydiscord", "ADMIN ONLY: Unban a user by their discord ID")]
|
||||||
public async Task UnbanByDiscord([Summary("discord_id", "Discord ID to unban")] ulong discordId)
|
public async Task UnbanByDiscord([Summary("discord_id", "Discord ID to unban")] string discordId)
|
||||||
{
|
{
|
||||||
_logger.LogInformation("SlashCommand:{userId}:{Method}:{params}",
|
_logger.LogInformation("SlashCommand:{userId}:{Method}:{params}",
|
||||||
Context.Interaction.User.Id, nameof(UnbanByDiscord),
|
Context.Interaction.User.Id, nameof(UnbanByDiscord),
|
||||||
@@ -157,7 +158,7 @@ public class LightlessModule : InteractionModuleBase
|
|||||||
|
|
||||||
c.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", _serverTokenGenerator.Token);
|
c.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", _serverTokenGenerator.Token);
|
||||||
await c.PostAsJsonAsync(new Uri(_lightlessServicesConfiguration.GetValue<Uri>
|
await c.PostAsJsonAsync(new Uri(_lightlessServicesConfiguration.GetValue<Uri>
|
||||||
(nameof(ServicesConfiguration.MainServerAddress)), "/user/unbanDiscord"), new { discordId })
|
(nameof(ServicesConfiguration.MainServerAddress)), "/user/unbanDiscord"), new UnbanRequest(string.Empty, discordId))
|
||||||
.ConfigureAwait(false);
|
.ConfigureAwait(false);
|
||||||
var discordChannelForMessages = _lightlessServicesConfiguration.GetValueOrDefault<ulong?>(nameof(ServicesConfiguration.DiscordChannelForMessages), null);
|
var discordChannelForMessages = _lightlessServicesConfiguration.GetValueOrDefault<ulong?>(nameof(ServicesConfiguration.DiscordChannelForMessages), null);
|
||||||
if (discordChannelForMessages != null)
|
if (discordChannelForMessages != null)
|
||||||
@@ -201,7 +202,7 @@ public class LightlessModule : InteractionModuleBase
|
|||||||
_logger.LogInformation("UnbanByDiscord:URI:{uri}", testUri);
|
_logger.LogInformation("UnbanByDiscord:URI:{uri}", testUri);
|
||||||
c.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", _serverTokenGenerator.Token);
|
c.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", _serverTokenGenerator.Token);
|
||||||
await c.PostAsJsonAsync(new Uri(_lightlessServicesConfiguration.GetValue<Uri>
|
await c.PostAsJsonAsync(new Uri(_lightlessServicesConfiguration.GetValue<Uri>
|
||||||
(nameof(ServicesConfiguration.MainServerAddress)), "/user/unbanUID"), new { uid })
|
(nameof(ServicesConfiguration.MainServerAddress)), "/user/unbanUID"), new UnbanRequest(uid, string.Empty))
|
||||||
.ConfigureAwait(false);
|
.ConfigureAwait(false);
|
||||||
var discordChannelForMessages = _lightlessServicesConfiguration.GetValueOrDefault<ulong?>(nameof(ServicesConfiguration.DiscordChannelForMessages), null);
|
var discordChannelForMessages = _lightlessServicesConfiguration.GetValueOrDefault<ulong?>(nameof(ServicesConfiguration.DiscordChannelForMessages), null);
|
||||||
if (discordChannelForMessages != null)
|
if (discordChannelForMessages != null)
|
||||||
@@ -243,7 +244,7 @@ public class LightlessModule : InteractionModuleBase
|
|||||||
|
|
||||||
c.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", _serverTokenGenerator.Token);
|
c.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", _serverTokenGenerator.Token);
|
||||||
await c.PostAsJsonAsync(new Uri(_lightlessServicesConfiguration.GetValue<Uri>
|
await c.PostAsJsonAsync(new Uri(_lightlessServicesConfiguration.GetValue<Uri>
|
||||||
(nameof(ServicesConfiguration.MainServerAddress)), "/user/ban"), new { uid })
|
(nameof(ServicesConfiguration.MainServerAddress)), "/user/ban"), new BanRequest(uid))
|
||||||
.ConfigureAwait(false);
|
.ConfigureAwait(false);
|
||||||
var discordChannelForMessages = _lightlessServicesConfiguration.GetValueOrDefault<ulong?>(nameof(ServicesConfiguration.DiscordChannelForMessages), null);
|
var discordChannelForMessages = _lightlessServicesConfiguration.GetValueOrDefault<ulong?>(nameof(ServicesConfiguration.DiscordChannelForMessages), null);
|
||||||
if (discordChannelForMessages != null)
|
if (discordChannelForMessages != null)
|
||||||
|
|||||||
Reference in New Issue
Block a user