refactor: change name enums

This commit is contained in:
Polianin Nikita 2024-11-02 00:50:10 +03:00
parent eb272baa38
commit 23f74b3bdf
5 changed files with 11 additions and 12 deletions

View File

@ -1,9 +1,9 @@
namespace Mirea.Api.Dto.Responses;
namespace Mirea.Api.Dto.Common;
/// <summary>
/// Represents the steps required after a login attempt.
/// </summary>
public enum AuthenticationStep
public enum TwoFactorAuthentication
{
/// <summary>
/// No additional steps required; the user is successfully logged in.

View File

@ -17,7 +17,7 @@ public class Admin : ISaveSettings
public required string Email { get; set; }
public required string PasswordHash { get; set; }
public required string Salt { get; set; }
public SecondFactor SecondFactor { get; set; } = SecondFactor.None;
public TwoFactorAuthenticator TwoFactorAuthenticator { get; set; } = TwoFactorAuthenticator.None;
public string? Secret { get; set; }
public void SaveSetting()

View File

@ -5,7 +5,6 @@ using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Options;
using Mirea.Api.Dto.Common;
using Mirea.Api.Dto.Requests;
using Mirea.Api.Dto.Responses;
using Mirea.Api.Endpoint.Common.Attributes;
using Mirea.Api.Endpoint.Common.Exceptions;
using Mirea.Api.Endpoint.Common.Services;
@ -29,7 +28,7 @@ public class AuthController(IOptionsSnapshot<Admin> user, AuthService auth, Pass
[HttpPost("Login")]
[BadRequestResponse]
public async Task<ActionResult<AuthenticationStep>> Login([FromBody] LoginRequest request)
public async Task<ActionResult<TwoFactorAuthentication>> Login([FromBody] LoginRequest request)
{
var userEntity = user.Value;
@ -46,20 +45,20 @@ public class AuthController(IOptionsSnapshot<Admin> user, AuthService auth, Pass
Email = userEntity.Email,
PasswordHash = userEntity.PasswordHash,
Salt = userEntity.Salt,
SecondFactor = userEntity.SecondFactor,
TwoFactorAuthenticator = userEntity.TwoFactorAuthenticator,
SecondFactorToken = userEntity.Secret
},
HttpContext, request.Password);
return Ok(tokenResult ? AuthenticationStep.None : AuthenticationStep.TotpRequired);
return Ok(tokenResult ? TwoFactorAuthentication.None : TwoFactorAuthentication.TotpRequired);
}
[HttpGet("Login")]
[BadRequestResponse]
public async Task<ActionResult<AuthenticationStep>> Login([FromQuery] string code)
public async Task<ActionResult<TwoFactorAuthentication>> Login([FromQuery] string code)
{
var tokenResult = await auth.LoginAsync(GetCookieParams(), HttpContext, code);
return Ok(tokenResult ? AuthenticationStep.None : AuthenticationStep.TotpRequired);
return Ok(tokenResult ? TwoFactorAuthentication.None : TwoFactorAuthentication.TotpRequired);
}
/// <summary>

View File

@ -17,6 +17,6 @@ internal class FirstAuthToken
public string Ip { get; set; } = null!;
public string Fingerprint { get; set; } = null!;
public required string UserId { get; set; }
public required SecondFactor SecondFactor { get; set; }
public required TwoFactorAuthenticator TwoFactorAuthenticator { get; set; }
public string? Secret { get; set; }
}

View File

@ -1,6 +1,6 @@
namespace Mirea.Api.Security.Common.Domain;
public enum SecondFactor
public enum TwoFactorAuthenticator
{
None,
Totp
@ -13,6 +13,6 @@ public class User
public required string Email { get; set; }
public required string PasswordHash { get; set; }
public required string Salt { get; set; }
public required SecondFactor SecondFactor { get; set; }
public required TwoFactorAuthenticator TwoFactorAuthenticator { get; set; }
public string? SecondFactorToken { get; set; }
}