private bool Register(RegisterBaseDTO registerBaseDTO, List <string> errors) { bool succeeded = ValidateCredentials(registerBaseDTO, errors); if (succeeded) { ApplicationUser applicationUser = new ApplicationUser { UserName = registerBaseDTO.Login, Email = registerBaseDTO.Email, FirstName = registerBaseDTO.FirstName, LastName = registerBaseDTO.LastName }; string password = registerBaseDTO.Password; IdentityResult identityResult = userManager.Create(applicationUser, password); if (!identityResult.Succeeded) { errors.AddRange(identityResult.Errors); succeeded = false; } } return(succeeded); }
public bool Validate(RegisterBaseDTO registerBaseDTO, ref string message) { bool isValid = true; string login = registerBaseDTO.Login; string password = registerBaseDTO.Password; string confirmPassword = registerBaseDTO.ConfirmPassword; if (String.IsNullOrEmpty(login)) { message = "Login can't be empty"; isValid = false; } else if (String.IsNullOrEmpty(password)) { message = "Password can't be empty"; isValid = false; } else if (String.IsNullOrEmpty(confirmPassword)) { message = "You haven't confirmed your password"; isValid = false; } else if (password != confirmPassword) { message = "Passwords are not equal"; isValid = false; } else if (login.Length < 3) { message = "Login must contain at least 3 characters"; isValid = false; } else if (!IsValidLogin(login)) { message = "Login must contain only letters and digits"; isValid = false; } else { isValid = ValidatePassword(password, ref message); } return(isValid); }
private bool ValidateCredentials(RegisterBaseDTO registerBaseDTO, ICollection <string> errors) { bool isValid = true; if (unitOfWork.Users.EmailExists(registerBaseDTO.Email)) { isValid = false; errors.Add("Such E-Mail is already registered"); } if (unitOfWork.Users.LoginExists(registerBaseDTO.Login)) { isValid = false; errors.Add("Such login is already taken"); } return(isValid); }
private bool ValidateRegisterBase(RegisterBaseDTO registerBaseDTO, ICollection <string> errors) { bool isValid = true; if (String.IsNullOrEmpty(registerBaseDTO.Login)) { isValid = false; errors.Add("Login cannot be empty"); } if (String.IsNullOrEmpty(registerBaseDTO.Email)) { isValid = false; errors.Add("E-Mail cannot be empty"); } if (String.IsNullOrEmpty(registerBaseDTO.Password)) { isValid = false; errors.Add("Password cannot be empty"); } if (String.IsNullOrEmpty(registerBaseDTO.FirstName)) { isValid = false; errors.Add("First name cannot be empty"); } if (String.IsNullOrEmpty(registerBaseDTO.LastName)) { isValid = false; errors.Add("Last name cannot be empty"); } return(isValid); }