Chore: Add user service method ChangePassword (#53303)

* Chore: Add user service method ChangePassword

* Fix lint
This commit is contained in:
idafurjes
2022-08-04 15:05:05 +02:00
committed by GitHub
parent 6fdb6ea6f6
commit 20f4191e56
10 changed files with 34 additions and 17 deletions
@@ -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
}
-1
View File
@@ -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
+7
View File
@@ -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
+1
View File
@@ -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
}
+10
View File
@@ -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)
}
+4
View File
@@ -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
}