diff options
Diffstat (limited to 'code/api/Services/Admin')
| -rw-r--r-- | code/api/Services/Admin/UserService.cs | 26 |
1 files changed, 9 insertions, 17 deletions
diff --git a/code/api/Services/Admin/UserService.cs b/code/api/Services/Admin/UserService.cs index f149d73..decc5bd 100644 --- a/code/api/Services/Admin/UserService.cs +++ b/code/api/Services/Admin/UserService.cs @@ -1,25 +1,17 @@ using Microsoft.AspNetCore.Authentication; using Microsoft.AspNetCore.Authentication.Cookies; -namespace I2R.Storage.Api.Services.Admin; +namespace Quality.Storage.Api.Services.Admin; -public class UserService +public class UserService(AppDatabase database, ILogger<UserService> logger) { - private readonly AppDatabase _database; - private readonly ILogger<UserService> _logger; - - public UserService(AppDatabase database, ILogger<UserService> logger) { - _database = database; - _logger = logger; - } - - public bool CanCreateAccount(string username) { + public bool CanCreateAccount(string username) { if (username.IsNullOrWhiteSpace()) { return false; } var normalisedUsername = username.Trim(); - return _database.Users.All(c => c.Username != normalisedUsername); + return database.Users.All(c => c.Username != normalisedUsername); } public async Task LogInUserAsync(HttpContext httpContext, IEnumerable<Claim> claims) { @@ -31,22 +23,22 @@ public class UserService }; await httpContext.SignInAsync(principal, authenticationProperties); - _logger.LogInformation("Logged in user {userId}", principal.FindFirstValue(AppClaims.USER_ID)); + logger.LogInformation("Logged in user {userId}", principal.FindFirstValue(AppClaims.USER_ID)); } public async Task LogOutUserAsync(HttpContext httpContext, CancellationToken cancellationToken = default) { await httpContext.SignOutAsync(); - _logger.LogInformation("Logged out user {userId}", httpContext.User.FindFirstValue(AppClaims.USER_ID)); + logger.LogInformation("Logged out user {userId}", httpContext.User.FindFirstValue(AppClaims.USER_ID)); } public async Task MarkUserAsDeletedAsync(Guid userId, Guid actorId) { - var user = _database.Users.FirstOrDefault(c => c.Id == userId); + var user = database.Users.FirstOrDefault(c => c.Id == userId); if (user == default) { - _logger.LogInformation("Tried to delete unknown user {userId}", userId); + logger.LogInformation("Tried to delete unknown user {userId}", userId); return; } user.SetDeleted(actorId); - await _database.SaveChangesAsync(); + await database.SaveChangesAsync(); } }
\ No newline at end of file |
