feat(authctl): support password reset
This commit is contained in:
@@ -74,6 +74,11 @@ type SetUserActiveCommand struct {
|
||||
Active bool
|
||||
}
|
||||
|
||||
type ResetUserPasswordCommand struct {
|
||||
Username string
|
||||
Password string
|
||||
}
|
||||
|
||||
type SetDeviceEnabledCommand struct {
|
||||
DeviceID string
|
||||
Enabled bool
|
||||
@@ -396,6 +401,49 @@ func (s *AuthService) SetUserActive(
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *AuthService) ResetUserPassword(
|
||||
ctx context.Context,
|
||||
command ResetUserPasswordCommand,
|
||||
) error {
|
||||
username := domain.NormalizeUsername(command.Username)
|
||||
user, err := s.repository.FindUserByUsername(ctx, username)
|
||||
if err != nil {
|
||||
return wrapAuthRepositoryError(err)
|
||||
}
|
||||
if err := domain.ValidateUserInput(
|
||||
username,
|
||||
command.Password,
|
||||
user.Role,
|
||||
); err != nil {
|
||||
var validation *domain.AuthValidationError
|
||||
if errors.As(err, &validation) {
|
||||
return invalidError(
|
||||
"AUTH_VALIDATION_FAILED",
|
||||
"authentication input is invalid",
|
||||
validation.Fields,
|
||||
)
|
||||
}
|
||||
return invalidError(
|
||||
"AUTH_VALIDATION_FAILED",
|
||||
"authentication input is invalid",
|
||||
map[string]string{},
|
||||
)
|
||||
}
|
||||
passwordHash, err := s.passwords.Hash(command.Password)
|
||||
if err != nil {
|
||||
return internalAuthFailure(err)
|
||||
}
|
||||
if err := s.repository.ResetUserPassword(
|
||||
ctx,
|
||||
username,
|
||||
passwordHash,
|
||||
s.clock.Now().UTC(),
|
||||
); err != nil {
|
||||
return wrapAuthRepositoryError(err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *AuthService) SetDeviceEnabled(
|
||||
ctx context.Context,
|
||||
command SetDeviceEnabledCommand,
|
||||
|
||||
Reference in New Issue
Block a user