public ActionResult ResetPassword(ResetPasswordRequestDTO model) { try { if (_userService.ResetPassword(model)) { return(Ok(new { message = "Password reset successful, you can now login" })); } } catch (AppException ex) { return(BadRequest(new { message = ex.Message })); } return(BadRequest(new { message = "Invalid token" })); }
public bool ResetPassword(ResetPasswordRequestDTO model) { var user = _userData.GetByResetToken(model.Token); if (user == null) { throw new AppException("Invalid token"); } if (user.ResetTokenExpiresAt < DateTime.UtcNow) { throw new AppException("Invalid token"); } user.Password = BC.HashPassword(model.Password); user.PasswordResetAt = DateTime.UtcNow; user.ResetToken = null; user.ResetTokenExpiresAt = DateTime.MinValue; return(_userData.Update(user)); }
public async Task ResetPasswordAsync(ResetPasswordRequestDTO model) { var account = await this._repository.GetByAsync((e => e.ResetToken == model.Token && e.ResetTokenExpires > DateTime.UtcNow)); if (account == null) { throw new ApplicationException("Invalid token"); } if (!account.Active) { throw new ApplicationException("Conta desativada!"); } account.PasswordHash = BC.HashPassword(model.Password); account.PasswordReset = DateTime.UtcNow; account.ResetToken = null; account.ResetTokenExpires = null; await this._repository.UpdateAsync(account.ID, account); await this._repository.SaveChangesAsync(); }
public IObservable <APIResponse <string> > resetPassword(ResetPasswordRequestDTO resetPasswordRequest) { return(Observable.FromAsync(() => PostData <APIResponse <string>, ResetPasswordRequestDTO>(ApiEndpoints.RESET_PASSWORD, resetPasswordRequest))); }