public async Task <UserDto> CreateUser(UserDto userDto) { var authenticationDto = new AuthenticationDto(); var userSpecification = new UserSpecification(). And(new UserNameSpecification()). And(new PasswordSpecification()). And(new UniqueUserSpecification(this.userRepository)); if (userSpecification.IsSatisfiedBy(userDto)) { string passwordSalt = ""; string passwordHash = ""; ECWRNGRfcSaltedHashManager.GenrateSaltedHash(userDto.Password, out passwordHash, out passwordSalt); var newUser = new Logins { UserName = userDto.UserName, PasswordSalt = passwordSalt, PasswordHash = passwordHash }; int identity = await this.userRepository.CreateLogin(newUser); if (identity <= 0) { userDto.AddRule("User", "Creation faild!"); } else { userDto.AddRule("Success", "Authentication is successfull."); } } return(userDto); }
public void RegisterUser(User user) { if (user == null) { throw new UserNullException(nameof(RegisterUser)); } var userSpec = new UserSpecification(); if (!userSpec.IsSatisfiedBy(user)) { throw new Exception("User did not pass validation. One or more arguments is null."); } _unitOfWork.Users.Add(user); _unitOfWork.SaveChanges(); }