diff options
Diffstat (limited to 'server/src/Services/UserService.cs')
| -rw-r--r-- | server/src/Services/UserService.cs | 50 |
1 files changed, 0 insertions, 50 deletions
diff --git a/server/src/Services/UserService.cs b/server/src/Services/UserService.cs deleted file mode 100644 index 6db663a..0000000 --- a/server/src/Services/UserService.cs +++ /dev/null @@ -1,50 +0,0 @@ -namespace IOL.GreatOffice.Api.Services; - -public class UserService -{ - private readonly PasswordResetService _passwordResetService; - - /// <summary> - /// Provides methods to perform common operations on user data. - /// </summary> - /// <param name="passwordResetService"></param> - public UserService(PasswordResetService passwordResetService) { - _passwordResetService = passwordResetService; - } - - /// <summary> - /// Log in a user. - /// </summary> - /// <param name="httpContext"></param> - /// <param name="user"></param> - /// <param name="persist"></param> - public async Task LogInUser(HttpContext httpContext, User user, bool persist = false) { - var claims = new List<Claim> { - new(AppClaims.USER_ID, user.Id.ToString()), - new(AppClaims.NAME, user.Username), - }; - - var identity = new ClaimsIdentity(claims, CookieAuthenticationDefaults.AuthenticationScheme); - var principal = new ClaimsPrincipal(identity); - var authenticationProperties = new AuthenticationProperties { - AllowRefresh = true, - IssuedUtc = DateTimeOffset.UtcNow, - }; - - if (persist) { - authenticationProperties.ExpiresUtc = DateTimeOffset.UtcNow.AddMonths(6); - authenticationProperties.IsPersistent = true; - } - - await httpContext.SignInAsync(principal, authenticationProperties); - await _passwordResetService.DeleteRequestsForUserAsync(user.Id); - } - - /// <summary> - /// Log out a user. - /// </summary> - /// <param name="httpContext"></param> - public async Task LogOutUser(HttpContext httpContext) { - await httpContext.SignOutAsync(); - } -} |
