diff --git a/AsbCloudInfrastructure/Services/AuthService.cs b/AsbCloudInfrastructure/Services/AuthService.cs index f552d92c..04c0621c 100644 --- a/AsbCloudInfrastructure/Services/AuthService.cs +++ b/AsbCloudInfrastructure/Services/AuthService.cs @@ -84,9 +84,14 @@ namespace AsbCloudInfrastructure.Services if (userDto.Position?.Length > 255) return -5; + var user = db.Users.FirstOrDefault(u => u.Login == userDto.Login); + + if(user is not null) + return -6; + var salt = GenerateSalt(); - var user = new User + var newUser = new User { IdCompany = userDto.IdCompany, IdRole = 2, // simple user @@ -102,14 +107,14 @@ namespace AsbCloudInfrastructure.Services PasswordHash = salt + ComputeHash(salt, userDto.Password), }; - db.Users.Add(user); + db.Users.Add(newUser); try { db.SaveChanges(); } catch //(Exception ex) { - return -6; + return -7; } return 0; diff --git a/AsbCloudWebApi/Controllers/AuthController.cs b/AsbCloudWebApi/Controllers/AuthController.cs index 09f34522..08db1c7e 100644 --- a/AsbCloudWebApi/Controllers/AuthController.cs +++ b/AsbCloudWebApi/Controllers/AuthController.cs @@ -70,6 +70,7 @@ namespace AsbCloudWebApi.Controllers -3 => BadRequest("Email не должен быть длиннее 255 знаков."), -4 => BadRequest("Телефон не должен быть длиннее 50 знаков."), -5 => BadRequest("Название должности не должно быть длиннее 255 символов."), + -6 => BadRequest("Пользователь с таким логином уже зарегистрирован."), _ => BadRequest(), }; }