From 23f74b3bdf21101441396b948fa1786c067ba8b8 Mon Sep 17 00:00:00 2001 From: Polianin Nikita Date: Sat, 2 Nov 2024 00:50:10 +0300 Subject: [PATCH] refactor: change name enums --- .../TwoFactorAuthentication.cs} | 4 ++-- Endpoint/Configuration/Model/Admin.cs | 2 +- Endpoint/Controllers/V1/AuthController.cs | 11 +++++------ Security/Common/Domain/FirstAuthToken.cs | 2 +- Security/Common/Domain/User.cs | 4 ++-- 5 files changed, 11 insertions(+), 12 deletions(-) rename ApiDto/{Responses/AuthenticationStep.cs => Common/TwoFactorAuthentication.cs} (83%) diff --git a/ApiDto/Responses/AuthenticationStep.cs b/ApiDto/Common/TwoFactorAuthentication.cs similarity index 83% rename from ApiDto/Responses/AuthenticationStep.cs rename to ApiDto/Common/TwoFactorAuthentication.cs index 8cab1ab..52dd09c 100644 --- a/ApiDto/Responses/AuthenticationStep.cs +++ b/ApiDto/Common/TwoFactorAuthentication.cs @@ -1,9 +1,9 @@ -namespace Mirea.Api.Dto.Responses; +namespace Mirea.Api.Dto.Common; /// /// Represents the steps required after a login attempt. /// -public enum AuthenticationStep +public enum TwoFactorAuthentication { /// /// No additional steps required; the user is successfully logged in. diff --git a/Endpoint/Configuration/Model/Admin.cs b/Endpoint/Configuration/Model/Admin.cs index 377b179..d31d7d0 100644 --- a/Endpoint/Configuration/Model/Admin.cs +++ b/Endpoint/Configuration/Model/Admin.cs @@ -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() diff --git a/Endpoint/Controllers/V1/AuthController.cs b/Endpoint/Controllers/V1/AuthController.cs index 737d9c5..e689d8a 100644 --- a/Endpoint/Controllers/V1/AuthController.cs +++ b/Endpoint/Controllers/V1/AuthController.cs @@ -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 user, AuthService auth, Pass [HttpPost("Login")] [BadRequestResponse] - public async Task> Login([FromBody] LoginRequest request) + public async Task> Login([FromBody] LoginRequest request) { var userEntity = user.Value; @@ -46,20 +45,20 @@ public class AuthController(IOptionsSnapshot 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> Login([FromQuery] string code) + public async Task> 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); } /// diff --git a/Security/Common/Domain/FirstAuthToken.cs b/Security/Common/Domain/FirstAuthToken.cs index a3a37e5..29f229d 100644 --- a/Security/Common/Domain/FirstAuthToken.cs +++ b/Security/Common/Domain/FirstAuthToken.cs @@ -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; } } \ No newline at end of file diff --git a/Security/Common/Domain/User.cs b/Security/Common/Domain/User.cs index 3465de2..bc8bf46 100644 --- a/Security/Common/Domain/User.cs +++ b/Security/Common/Domain/User.cs @@ -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; } } \ No newline at end of file