mirror of
https://github.com/grafana/grafana.git
synced 2024-11-25 10:20:29 -06:00
Chore: Remove result field from notifications (#65170)
* remove result field from notifications * fix test
This commit is contained in:
parent
352967f092
commit
b2ab57d14b
@ -70,7 +70,8 @@ func (hs *HTTPServer) ResetPassword(c *contextmodel.ReqContext) response.Respons
|
|||||||
return usr, err
|
return usr, err
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := hs.NotificationService.ValidateResetPasswordCode(c.Req.Context(), &query, getUserByLogin); err != nil {
|
userResult, err := hs.NotificationService.ValidateResetPasswordCode(c.Req.Context(), &query, getUserByLogin)
|
||||||
|
if err != nil {
|
||||||
if errors.Is(err, notifications.ErrInvalidEmailCode) {
|
if errors.Is(err, notifications.ErrInvalidEmailCode) {
|
||||||
return response.Error(400, "Invalid or expired reset password code", nil)
|
return response.Error(400, "Invalid or expired reset password code", nil)
|
||||||
}
|
}
|
||||||
@ -87,9 +88,8 @@ func (hs *HTTPServer) ResetPassword(c *contextmodel.ReqContext) response.Respons
|
|||||||
}
|
}
|
||||||
|
|
||||||
cmd := user.ChangeUserPasswordCommand{}
|
cmd := user.ChangeUserPasswordCommand{}
|
||||||
cmd.UserID = query.Result.ID
|
cmd.UserID = userResult.ID
|
||||||
var err error
|
cmd.NewPassword, err = util.EncodePassword(form.NewPassword, userResult.Salt)
|
||||||
cmd.NewPassword, err = util.EncodePassword(form.NewPassword, query.Result.Salt)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return response.Error(500, "Failed to encode password", err)
|
return response.Error(500, "Failed to encode password", err)
|
||||||
}
|
}
|
||||||
|
@ -49,6 +49,5 @@ type SendResetPasswordEmailCommand struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type ValidateResetPasswordCodeQuery struct {
|
type ValidateResetPasswordCodeQuery struct {
|
||||||
Code string
|
Code string
|
||||||
Result *user.User
|
|
||||||
}
|
}
|
||||||
|
@ -235,27 +235,26 @@ func (ns *NotificationService) SendResetPasswordEmail(ctx context.Context, cmd *
|
|||||||
|
|
||||||
type GetUserByLoginFunc = func(c context.Context, login string) (*user.User, error)
|
type GetUserByLoginFunc = func(c context.Context, login string) (*user.User, error)
|
||||||
|
|
||||||
func (ns *NotificationService) ValidateResetPasswordCode(ctx context.Context, query *ValidateResetPasswordCodeQuery, userByLogin GetUserByLoginFunc) error {
|
func (ns *NotificationService) ValidateResetPasswordCode(ctx context.Context, query *ValidateResetPasswordCodeQuery, userByLogin GetUserByLoginFunc) (*user.User, error) {
|
||||||
login := getLoginForEmailCode(query.Code)
|
login := getLoginForEmailCode(query.Code)
|
||||||
if login == "" {
|
if login == "" {
|
||||||
return ErrInvalidEmailCode
|
return nil, ErrInvalidEmailCode
|
||||||
}
|
}
|
||||||
|
|
||||||
user, err := userByLogin(ctx, login)
|
user, err := userByLogin(ctx, login)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
validEmailCode, err := validateUserEmailCode(ns.Cfg, user, query.Code)
|
validEmailCode, err := validateUserEmailCode(ns.Cfg, user, query.Code)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return nil, err
|
||||||
}
|
}
|
||||||
if !validEmailCode {
|
if !validEmailCode {
|
||||||
return ErrInvalidEmailCode
|
return nil, ErrInvalidEmailCode
|
||||||
}
|
}
|
||||||
|
|
||||||
query.Result = user
|
return user, nil
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ns *NotificationService) signUpStartedHandler(ctx context.Context, evt *events.SignUpStarted) error {
|
func (ns *NotificationService) signUpStartedHandler(ctx context.Context, evt *events.SignUpStarted) error {
|
||||||
|
@ -216,7 +216,7 @@ func TestSendEmailAsync(t *testing.T) {
|
|||||||
getUserByLogin := func(ctx context.Context, login string) (*user.User, error) {
|
getUserByLogin := func(ctx context.Context, login string) (*user.User, error) {
|
||||||
return &testuser, nil
|
return &testuser, nil
|
||||||
}
|
}
|
||||||
err = sut.ValidateResetPasswordCode(context.Background(), &query, getUserByLogin)
|
_, err = sut.ValidateResetPasswordCode(context.Background(), &query, getUserByLogin)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user