From e343e4638f194bdad21b652bbf5f6ca79a8916c6 Mon Sep 17 00:00:00 2001 From: dasha Date: Wed, 17 May 2023 14:43:35 +0400 Subject: [PATCH] =?UTF-8?q?=D0=B2=D0=B0=D0=BB=D0=B8=D0=B4=D0=B0=D1=86?= =?UTF-8?q?=D0=B8=D1=8F=3F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BusinessLogics/UserLogic.cs | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/HardwareShop/HardwareShopBusinessLogic/BusinessLogics/UserLogic.cs b/HardwareShop/HardwareShopBusinessLogic/BusinessLogics/UserLogic.cs index de4e507..701f6f5 100644 --- a/HardwareShop/HardwareShopBusinessLogic/BusinessLogics/UserLogic.cs +++ b/HardwareShop/HardwareShopBusinessLogic/BusinessLogics/UserLogic.cs @@ -4,6 +4,7 @@ using HardwareShopContracts.SearchModels; using HardwareShopContracts.StoragesContracts; using HardwareShopContracts.ViewModels; using Microsoft.Extensions.Logging; +using System.Text.RegularExpressions; namespace HardwareShopBusinessLogic.BusinessLogics { @@ -93,17 +94,21 @@ namespace HardwareShopBusinessLogic.BusinessLogics { return; } - if (string.IsNullOrEmpty(model.Login)) + if (string.IsNullOrEmpty(model.Login) || model.Login.Length > 20) { - throw new ArgumentNullException("Нет логина пользователя", nameof(model.Login)); + throw new ArgumentNullException("Нет логина пользователя или длина превышает 20 символов", nameof(model.Login)); } - if (string.IsNullOrEmpty(model.Email)) + if (string.IsNullOrEmpty(model.Email) || model.Email.Length > 30) { - throw new ArgumentNullException("Нет почты пользователя", nameof(model.Email)); + throw new ArgumentNullException("Нет почты пользователя или длина превышает 30 символов", nameof(model.Email)); } - if (string.IsNullOrEmpty(model.Password)) + if (!Regex.IsMatch(model.Email, @"^[^@\s]+@[^@\s]+\.[^@\s]+$", RegexOptions.IgnoreCase)) { - throw new ArgumentNullException("Нет пароля пользователя", nameof(model.Password)); + throw new ArgumentException("Неправильно введенная почта", nameof(model.Email)); + } + if (string.IsNullOrEmpty(model.Password) || model.Password.Length > 30 || model.Password.Contains(' ')) + { + throw new ArgumentNullException("Нет пароля пользователя или пароль содержит пробелы", nameof(model.Password)); } _logger.LogInformation("User. Login: {Login}. Email: {Email}. Id: {Id}", model.Login, model.Email, model.Id);