diff --git a/Endpoint/Controllers/Configuration/SetupController.cs b/Endpoint/Controllers/Configuration/SetupController.cs index 1c9d275..adc1695 100644 --- a/Endpoint/Controllers/Configuration/SetupController.cs +++ b/Endpoint/Controllers/Configuration/SetupController.cs @@ -8,19 +8,23 @@ using Mirea.Api.Dto.Requests.Configuration; using Mirea.Api.Endpoint.Common.Attributes; using Mirea.Api.Endpoint.Common.Exceptions; using Mirea.Api.Endpoint.Common.Interfaces; +using Mirea.Api.Endpoint.Common.Model; using Mirea.Api.Endpoint.Common.Services; using Mirea.Api.Endpoint.Configuration.General; using Mirea.Api.Endpoint.Configuration.General.Settings; using Mirea.Api.Endpoint.Configuration.General.Validators; +using Mirea.Api.Security.Services; using MySqlConnector; using Npgsql; using StackExchange.Redis; using System; using System.Data; using System.IO; +using System.Net.Mail; using System.Runtime.InteropServices; using System.Security.Cryptography; using System.Text.Json; +using System.Text.RegularExpressions; namespace Mirea.Api.Endpoint.Controllers.Configuration; @@ -199,8 +203,11 @@ public class SetupController(ISetupToken setupToken, IMaintenanceModeNotConfigur [BadRequestResponse] public ActionResult CreateAdmin([FromBody] CreateUserRequest user) { - // todo: change CreateUserRequest to Domain entity - cache.Set(CacheAdminKey, user); + if (user.Password.Length < 8 || !Regex.IsMatch(user.Password, "[A-Z]+") || !Regex.IsMatch(user.Password, "[!@#$%^&*]+")) + throw new ControllerArgumentException("The password must be at least 8 characters long and contain at least one uppercase letter and one special character."); + + if (!MailAddress.TryCreate(user.Email, out _)) + throw new ControllerArgumentException("The email address is incorrect."); return Ok(true); }