namespace IOL.GreatOffice.Api.Services; public class UserService { private readonly PasswordResetService _passwordResetService; private readonly ILogger _logger; public UserService(PasswordResetService passwordResetService, ILogger logger) { _passwordResetService = passwordResetService; _logger = logger; } public async Task LogInUserAsync(HttpContext httpContext, User user, bool persist = false) { var identity = new ClaimsIdentity(user.DefaultClaims(), 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); _logger.LogInformation("Logged in user {userId}", user.Id); } public async Task LogOutUser(HttpContext httpContext) { await httpContext.SignOutAsync(); _logger.LogInformation("Logged out user {userId}", httpContext.User.FindFirst(AppClaims.USER_ID)); } }