refactor: change name enums
This commit is contained in:
parent
eb272baa38
commit
23f74b3bdf
@ -1,9 +1,9 @@
|
|||||||
namespace Mirea.Api.Dto.Responses;
|
namespace Mirea.Api.Dto.Common;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Represents the steps required after a login attempt.
|
/// Represents the steps required after a login attempt.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public enum AuthenticationStep
|
public enum TwoFactorAuthentication
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// No additional steps required; the user is successfully logged in.
|
/// No additional steps required; the user is successfully logged in.
|
@ -17,7 +17,7 @@ public class Admin : ISaveSettings
|
|||||||
public required string Email { get; set; }
|
public required string Email { get; set; }
|
||||||
public required string PasswordHash { get; set; }
|
public required string PasswordHash { get; set; }
|
||||||
public required string Salt { 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 string? Secret { get; set; }
|
||||||
|
|
||||||
public void SaveSetting()
|
public void SaveSetting()
|
||||||
|
@ -5,7 +5,6 @@ using Microsoft.AspNetCore.Mvc;
|
|||||||
using Microsoft.Extensions.Options;
|
using Microsoft.Extensions.Options;
|
||||||
using Mirea.Api.Dto.Common;
|
using Mirea.Api.Dto.Common;
|
||||||
using Mirea.Api.Dto.Requests;
|
using Mirea.Api.Dto.Requests;
|
||||||
using Mirea.Api.Dto.Responses;
|
|
||||||
using Mirea.Api.Endpoint.Common.Attributes;
|
using Mirea.Api.Endpoint.Common.Attributes;
|
||||||
using Mirea.Api.Endpoint.Common.Exceptions;
|
using Mirea.Api.Endpoint.Common.Exceptions;
|
||||||
using Mirea.Api.Endpoint.Common.Services;
|
using Mirea.Api.Endpoint.Common.Services;
|
||||||
@ -29,7 +28,7 @@ public class AuthController(IOptionsSnapshot<Admin> user, AuthService auth, Pass
|
|||||||
|
|
||||||
[HttpPost("Login")]
|
[HttpPost("Login")]
|
||||||
[BadRequestResponse]
|
[BadRequestResponse]
|
||||||
public async Task<ActionResult<AuthenticationStep>> Login([FromBody] LoginRequest request)
|
public async Task<ActionResult<TwoFactorAuthentication>> Login([FromBody] LoginRequest request)
|
||||||
{
|
{
|
||||||
var userEntity = user.Value;
|
var userEntity = user.Value;
|
||||||
|
|
||||||
@ -46,20 +45,20 @@ public class AuthController(IOptionsSnapshot<Admin> user, AuthService auth, Pass
|
|||||||
Email = userEntity.Email,
|
Email = userEntity.Email,
|
||||||
PasswordHash = userEntity.PasswordHash,
|
PasswordHash = userEntity.PasswordHash,
|
||||||
Salt = userEntity.Salt,
|
Salt = userEntity.Salt,
|
||||||
SecondFactor = userEntity.SecondFactor,
|
TwoFactorAuthenticator = userEntity.TwoFactorAuthenticator,
|
||||||
SecondFactorToken = userEntity.Secret
|
SecondFactorToken = userEntity.Secret
|
||||||
},
|
},
|
||||||
HttpContext, request.Password);
|
HttpContext, request.Password);
|
||||||
|
|
||||||
return Ok(tokenResult ? AuthenticationStep.None : AuthenticationStep.TotpRequired);
|
return Ok(tokenResult ? TwoFactorAuthentication.None : TwoFactorAuthentication.TotpRequired);
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpGet("Login")]
|
[HttpGet("Login")]
|
||||||
[BadRequestResponse]
|
[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);
|
var tokenResult = await auth.LoginAsync(GetCookieParams(), HttpContext, code);
|
||||||
return Ok(tokenResult ? AuthenticationStep.None : AuthenticationStep.TotpRequired);
|
return Ok(tokenResult ? TwoFactorAuthentication.None : TwoFactorAuthentication.TotpRequired);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -17,6 +17,6 @@ internal class FirstAuthToken
|
|||||||
public string Ip { get; set; } = null!;
|
public string Ip { get; set; } = null!;
|
||||||
public string Fingerprint { get; set; } = null!;
|
public string Fingerprint { get; set; } = null!;
|
||||||
public required string UserId { get; set; }
|
public required string UserId { get; set; }
|
||||||
public required SecondFactor SecondFactor { get; set; }
|
public required TwoFactorAuthenticator TwoFactorAuthenticator { get; set; }
|
||||||
public string? Secret { get; set; }
|
public string? Secret { get; set; }
|
||||||
}
|
}
|
@ -1,6 +1,6 @@
|
|||||||
namespace Mirea.Api.Security.Common.Domain;
|
namespace Mirea.Api.Security.Common.Domain;
|
||||||
|
|
||||||
public enum SecondFactor
|
public enum TwoFactorAuthenticator
|
||||||
{
|
{
|
||||||
None,
|
None,
|
||||||
Totp
|
Totp
|
||||||
@ -13,6 +13,6 @@ public class User
|
|||||||
public required string Email { get; set; }
|
public required string Email { get; set; }
|
||||||
public required string PasswordHash { get; set; }
|
public required string PasswordHash { get; set; }
|
||||||
public required string Salt { 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; }
|
public string? SecondFactorToken { get; set; }
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user