2026-07-22 20:05:59 +00:00
|
|
|
using Heimdall.Application.Services;
|
|
|
|
|
using Heimdall.Domain.Entities;
|
|
|
|
|
using Microsoft.AspNetCore.Identity;
|
|
|
|
|
|
|
|
|
|
namespace Heimdall.Infrastructure.Security;
|
|
|
|
|
|
|
|
|
|
public class AuthSignInService : IAuthSignInService
|
|
|
|
|
{
|
|
|
|
|
private readonly SignInManager<AppUser> _signInManager;
|
|
|
|
|
|
|
|
|
|
public AuthSignInService(SignInManager<AppUser> signInManager)
|
|
|
|
|
{
|
|
|
|
|
_signInManager = signInManager;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async Task<SignInServiceResult> PasswordSignInAsync(AppUser user, string password, bool lockoutOnFailure)
|
|
|
|
|
{
|
2026-07-27 18:59:12 +00:00
|
|
|
var result = await _signInManager.PasswordSignInAsync(user, password, false, lockoutOnFailure).ConfigureAwait(false);
|
2026-07-22 20:05:59 +00:00
|
|
|
return result switch
|
|
|
|
|
{
|
|
|
|
|
{ Succeeded: true } => new SignInServiceResult(SignInResultType.Success),
|
|
|
|
|
{ IsLockedOut: true } => new SignInServiceResult(SignInResultType.LockedOut),
|
|
|
|
|
{ RequiresTwoFactor: true } => new SignInServiceResult(SignInResultType.RequiresTwoFactor),
|
|
|
|
|
_ => new SignInServiceResult(SignInResultType.Failed)
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async Task SignOutAsync()
|
|
|
|
|
{
|
2026-07-27 18:59:12 +00:00
|
|
|
await _signInManager.SignOutAsync().ConfigureAwait(false);
|
2026-07-22 20:05:59 +00:00
|
|
|
}
|
|
|
|
|
}
|