mirror of
https://github.com/grafana/grafana.git
synced 2026-08-18 17:15:08 -05:00
Chore: Add user service method ChangePassword (#53303)
* Chore: Add user service method ChangePassword * Fix lint
This commit is contained in:
@@ -137,10 +137,6 @@ func (m *SQLStoreMock) CreateUser(ctx context.Context, cmd user.CreateUserComman
|
||||
return nil, m.ExpectedError
|
||||
}
|
||||
|
||||
func (m *SQLStoreMock) ChangeUserPassword(ctx context.Context, cmd *models.ChangeUserPasswordCommand) error {
|
||||
return m.ExpectedError
|
||||
}
|
||||
|
||||
func (m *SQLStoreMock) UpdateUserLastSeenAt(ctx context.Context, cmd *models.UpdateUserLastSeenAtCommand) error {
|
||||
return m.ExpectedError
|
||||
}
|
||||
|
||||
@@ -31,7 +31,6 @@ type Store interface {
|
||||
GetUserLoginAttemptCount(ctx context.Context, query *models.GetUserLoginAttemptCountQuery) error
|
||||
DeleteOldLoginAttempts(ctx context.Context, cmd *models.DeleteOldLoginAttemptsCommand) error
|
||||
CreateUser(ctx context.Context, cmd user.CreateUserCommand) (*user.User, error)
|
||||
ChangeUserPassword(ctx context.Context, cmd *models.ChangeUserPasswordCommand) error
|
||||
UpdateUserLastSeenAt(ctx context.Context, cmd *models.UpdateUserLastSeenAtCommand) error
|
||||
SetUsingOrg(ctx context.Context, cmd *models.SetUsingOrgCommand) error
|
||||
GetUserProfile(ctx context.Context, query *models.GetUserProfileQuery) error
|
||||
|
||||
@@ -75,6 +75,13 @@ type UpdateUserCommand struct {
|
||||
UserID int64 `json:"-"`
|
||||
}
|
||||
|
||||
type ChangeUserPasswordCommand struct {
|
||||
OldPassword string `json:"oldPassword"`
|
||||
NewPassword string `json:"newPassword"`
|
||||
|
||||
UserID int64 `json:"-"`
|
||||
}
|
||||
|
||||
func (u *User) NameOrFallback() string {
|
||||
if u.Name != "" {
|
||||
return u.Name
|
||||
|
||||
@@ -11,4 +11,5 @@ type Service interface {
|
||||
GetByLogin(context.Context, *GetUserByLoginQuery) (*User, error)
|
||||
GetByEmail(context.Context, *GetUserByEmailQuery) (*User, error)
|
||||
Update(context.Context, *UpdateUserCommand) error
|
||||
ChangePassword(context.Context, *ChangeUserPasswordCommand) error
|
||||
}
|
||||
|
||||
@@ -279,3 +279,13 @@ func (s *Service) Update(ctx context.Context, cmd *user.UpdateUserCommand) error
|
||||
}
|
||||
return s.sqlStore.UpdateUser(ctx, q)
|
||||
}
|
||||
|
||||
// TODO: remove wrapper around sqlstore
|
||||
func (s *Service) ChangePassword(ctx context.Context, cmd *user.ChangeUserPasswordCommand) error {
|
||||
q := &models.ChangeUserPasswordCommand{
|
||||
UserId: cmd.UserID,
|
||||
NewPassword: cmd.NewPassword,
|
||||
OldPassword: cmd.OldPassword,
|
||||
}
|
||||
return s.sqlStore.ChangeUserPassword(ctx, q)
|
||||
}
|
||||
|
||||
@@ -38,3 +38,7 @@ func (f *FakeUserService) GetByEmail(ctx context.Context, query *user.GetUserByE
|
||||
func (f *FakeUserService) Update(ctx context.Context, cmd *user.UpdateUserCommand) error {
|
||||
return f.ExpectedError
|
||||
}
|
||||
|
||||
func (f *FakeUserService) ChangePassword(ctx context.Context, cmd *user.ChangeUserPasswordCommand) error {
|
||||
return f.ExpectedError
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user