LoginAttempts: Reset attempts on successfull password reset (#59215)

* LoginAttempt: Add function to reset attemtps for username

* PasswordReset: Reset attempts on successful password reset
This commit is contained in:
Karl Persson
2022-11-23 16:57:18 +01:00
committed by GitHub
parent 9d88e14f01
commit 83c101dc34
8 changed files with 41 additions and 34 deletions
+8
View File
@@ -60,7 +60,11 @@ func (hs *HTTPServer) ResetPassword(c *models.ReqContext) response.Response {
}
query := models.ValidateResetPasswordCodeQuery{Code: form.Code}
// For now the only way to know the username to clear login attempts for is
// to set it in the function provided to NotificationService
var username string
getUserByLogin := func(ctx context.Context, login string) (*user.User, error) {
username = login
userQuery := user.GetUserByLoginQuery{LoginOrEmail: login}
usr, err := hs.userService.GetByLogin(ctx, &userQuery)
return usr, err
@@ -94,5 +98,9 @@ func (hs *HTTPServer) ResetPassword(c *models.ReqContext) response.Response {
return response.Error(500, "Failed to change user password", err)
}
if err := hs.loginAttemptService.Reset(c.Req.Context(), username); err != nil {
c.Logger.Warn("could not reset login attempts", "err", err, "username", username)
}
return response.Success("User password changed")
}