public void ChangePassword(User user, string password, string confirm) { if (user.Registration.Type == RegistrationType.Google) { throw new ActionCannotBeExecutedException(ExceptionMessages.ForbiddenToChangeEmail); } _passwordSetter.SetPassword(user, password, confirm); }
public async Task <Registration> RegisterAsync(RegistrationType registrationType, string email = null, string password = null, string confirm = null, string firstName = null, string lastName = null, DateTime?birthDt = null, Gender?gender = null, Role role = Role.User) { ValidateData(email, firstName, lastName, birthDt); Registration registration = new Registration { CreateDt = DateTimeOffset.Now, Guid = Guid.NewGuid(), Status = RegistrationStatus.Pending, Type = registrationType }; if (registrationType == RegistrationType.Email) { ValidatePassword(password, confirm); User user = new User { FirstName = firstName, LastName = lastName, Role = role, Gender = gender, Registration = registration, Status = UserStatus.Pending, Email = email, }; _passwordSetter.SetPassword(user, password, confirm); _unitOfWork.GetUserRepository().Insert(user); string emailBody = MailTemplates.Confirmation.Replace("[Confirmation_Link]", _currentHost + "registration/confirm?guid=" + registration.Guid); await _mailSender.SendAsync(new Letter { Topic = "Registration confirmation", Email = new string[] { user.Email }, Body = emailBody }); } if (registrationType == RegistrationType.Google) { User user = new User { FirstName = firstName, LastName = lastName, Role = Role.User, Gender = gender, Registration = registration, Status = UserStatus.Active, Email = email, }; registration.Status = RegistrationStatus.Accepted; _unitOfWork.GetUserRepository().Insert(user); string emailBody = MailTemplates.Confirmation.Replace("[Confirmation_Link]", _currentHost + "registration/confirm?guid=" + registration.Guid); await _mailSender.SendAsync(new Letter { Topic = "Registration confirmation", Email = new string[] { user.Email }, Body = emailBody }); } return(registration); }