public Result CreateAccount(UserAccountCreationInfo userInfo, out User user) { // Validate dto ValidationHelper.ValidateModel(userInfo); // Create user object user = Mapper.Map <User>(userInfo); user.PasswordHash = PasswordHashHelper.CreateHash(userInfo.Password); user.LastLoginDate = DateTime.Now; // Validate user ValidationHelper.ValidateModel(user); // Other validations string email = user.Email; if (dataAccessor.Users.Any(other => email == other.Email)) { throw new ValidationException(MsgAccountWithEmailExists); } // Do save dataAccessor.Create(user); dataAccessor.SaveChanges(); return(Login(new LoginInfo { Email = userInfo.Email, Password = userInfo.Password })); }
public Result ResetPassword(string tokenString, string userEmail, string newPassword) { // Re-validate token first Result <PasswordResetInfo> passwordResetInfo = GetPasswordResetInfo(tokenString); // Remove token from cache cache.Remove(CacheKeys.ForgotPasswordGuid(passwordResetInfo.Value.Token)); // Get the user object User user = dataAccessor.Users.SingleOrDefault(x => x.Email == userEmail); if (user == null) { throw new ValidationException(MsgInvalidEmail); } // Reset password if we have a valid user user.PasswordHash = PasswordHashHelper.CreateHash(newPassword); dataAccessor.Update(user); dataAccessor.SaveChanges(); // Return a success message return(new Result(new LogMessage(MessageType.Success, MsgPasswordResetSuccess))); }