From 9ff0f51e19762f8b4a088357d3cd3c482b9ded13 Mon Sep 17 00:00:00 2001 From: Polianin Nikita Date: Wed, 25 Dec 2024 05:44:15 +0300 Subject: [PATCH] refactor: add data annotations --- ApiDto/Requests/CreateUserRequest.cs | 3 +++ Endpoint/Controllers/Configuration/SetupController.cs | 5 ----- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/ApiDto/Requests/CreateUserRequest.cs b/ApiDto/Requests/CreateUserRequest.cs index e1b3a4c..2d6fecf 100644 --- a/ApiDto/Requests/CreateUserRequest.cs +++ b/ApiDto/Requests/CreateUserRequest.cs @@ -11,17 +11,20 @@ public class CreateUserRequest /// Gets or sets the email address of the user. /// [Required] + [EmailAddress] public required string Email { get; set; } /// /// Gets or sets the username of the user. /// [Required] + [MinLength(2)] public required string Username { get; set; } /// /// Gets or sets the password of the user. /// [Required] + [MinLength(2)] public required string Password { get; set; } } diff --git a/Endpoint/Controllers/Configuration/SetupController.cs b/Endpoint/Controllers/Configuration/SetupController.cs index e92ca2b..2d64f7d 100644 --- a/Endpoint/Controllers/Configuration/SetupController.cs +++ b/Endpoint/Controllers/Configuration/SetupController.cs @@ -29,7 +29,6 @@ using System.Collections.Generic; using System.Data; using System.IO; using System.Linq; -using System.Net.Mail; using System.Runtime.InteropServices; using System.Security; using System.Security.Cryptography; @@ -305,10 +304,6 @@ public class SetupController( public ActionResult CreateAdmin([FromBody] CreateUserRequest userRequest) { new PasswordPolicyService(GeneralConfig.PasswordPolicy).ValidatePasswordOrThrow(userRequest.Password); - - if (!MailAddress.TryCreate(userRequest.Email, out _)) - throw new ControllerArgumentException("The email address is incorrect."); - var (salt, hash) = passwordHashService.HashPassword(userRequest.Password); var admin = new Admin