banning a user now removes their roles
banned users can't be deleted completely signing up for banned users is no longer possible
This commit is contained in:
parent
de351e167c
commit
5d05430b89
3 changed files with 31 additions and 2 deletions
|
@ -416,6 +416,12 @@ namespace Lieb.Data
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(user.BannedUntil > DateTimeOffset.UtcNow)
|
||||||
|
{
|
||||||
|
errorMessage = $"You are banned until {user.BannedUntil}.";
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -135,19 +135,41 @@ namespace Lieb.Data
|
||||||
await _guildWars2AccountService.DeleteAccount(account.GuildWars2AccountId);
|
await _guildWars2AccountService.DeleteAccount(account.GuildWars2AccountId);
|
||||||
}
|
}
|
||||||
user.GuildWars2Accounts.Clear();
|
user.GuildWars2Accounts.Clear();
|
||||||
|
|
||||||
|
if(user.BannedUntil > DateTime.Now)
|
||||||
|
{
|
||||||
|
LiebUser contextUser = context.LiebUsers.First(u => u.Id == userId);
|
||||||
|
contextUser.Name = "Deleted and Banned";
|
||||||
|
contextUser.MainGW2Account = 0;
|
||||||
|
contextUser.Pronouns = string.Empty;
|
||||||
|
contextUser.Birthday = null;
|
||||||
|
contextUser.AlwaysSignUpWithMainAccount = false;
|
||||||
|
LiebRole standardRole = await context.LiebRoles.FirstOrDefaultAsync(m => m.RoleName == Constants.Roles.User.Name);
|
||||||
|
context.RemoveRange(user.RoleAssignments.Where(a => a.LiebRoleId != standardRole.LiebRoleId));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
context.Remove(user);
|
context.Remove(user);
|
||||||
|
}
|
||||||
await context.SaveChangesAsync();
|
await context.SaveChangesAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task UpdateBannedUntil(ulong userId, DateTime? date)
|
public async Task UpdateBannedUntil(ulong userId, DateTime? date)
|
||||||
{
|
{
|
||||||
using var context = _contextFactory.CreateDbContext();
|
using var context = _contextFactory.CreateDbContext();
|
||||||
LiebUser? user = await context.LiebUsers.FirstOrDefaultAsync(u => u.Id == userId);
|
LiebUser? user = await context.LiebUsers
|
||||||
|
.Include(u => u.RoleAssignments)
|
||||||
|
.FirstOrDefaultAsync(u => u.Id == userId);
|
||||||
|
|
||||||
if (user == null)
|
if (user == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
user.BannedUntil = date;
|
user.BannedUntil = date;
|
||||||
|
if(user.BannedUntil > DateTime.UtcNow)
|
||||||
|
{
|
||||||
|
LiebRole standardRole = await context.LiebRoles.FirstOrDefaultAsync(m => m.RoleName == Constants.Roles.User.Name);
|
||||||
|
context.RemoveRange(user.RoleAssignments.Where(a => a.LiebRoleId != standardRole.LiebRoleId));
|
||||||
|
}
|
||||||
|
|
||||||
await context.SaveChangesAsync();
|
await context.SaveChangesAsync();
|
||||||
}
|
}
|
||||||
|
|
|
@ -128,5 +128,6 @@
|
||||||
{
|
{
|
||||||
_submitMessage = "user unbanned successfully";
|
_submitMessage = "user unbanned successfully";
|
||||||
}
|
}
|
||||||
|
_user = UserService.GetLiebUser(_user.Id);
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Add table
Add a link
Reference in a new issue