add resetPassword
This commit is contained in:
parent
445cacc540
commit
4d4bf4db8f
|
@ -44,6 +44,11 @@ func (s Service) ChangeUserPassword(userID string, payload model.ChangePasswordO
|
||||||
return user.ChangeUserPassword(userID, payload)
|
return user.ChangeUserPassword(userID, payload)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ResetUserPassword ...
|
||||||
|
func (s Service) ResetUserPassword(userID string, password string) error {
|
||||||
|
return user.ResetUserPassword(userID, password)
|
||||||
|
}
|
||||||
|
|
||||||
// ChangeUserStatus ...
|
// ChangeUserStatus ...
|
||||||
func (s Service) ChangeUserStatus(userID, newStatus string) error {
|
func (s Service) ChangeUserStatus(userID, newStatus string) error {
|
||||||
return user.ChangeUserStatus(userID, newStatus)
|
return user.ChangeUserStatus(userID, newStatus)
|
||||||
|
|
|
@ -349,6 +349,43 @@ func ChangeUserPassword(userID string, opt model.ChangePasswordOptions) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ResetUserPassword ...
|
||||||
|
func ResetUserPassword(userID string, password string) error {
|
||||||
|
var (
|
||||||
|
ctx = context.Background()
|
||||||
|
)
|
||||||
|
|
||||||
|
// Validate Password
|
||||||
|
if password == "" {
|
||||||
|
return errors.New("password cannot be empty")
|
||||||
|
}
|
||||||
|
|
||||||
|
// Validate userID
|
||||||
|
if _, isValid := mongodb.NewIDFromString(userID); !isValid {
|
||||||
|
return errors.New("invalid user id data")
|
||||||
|
}
|
||||||
|
|
||||||
|
// Find user
|
||||||
|
id, _ := mongodb.NewIDFromString(userID)
|
||||||
|
user, _ := findByID(ctx, id)
|
||||||
|
if user.ID.IsZero() {
|
||||||
|
return errors.New("user not found")
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update password
|
||||||
|
if err := updateOneByCondition(ctx, bson.M{"_id": user.ID}, bson.M{
|
||||||
|
"$set": bson.M{
|
||||||
|
"hashedPassword": internal.HashPassword(password),
|
||||||
|
"requireToChangePassword": false,
|
||||||
|
"updatedAt": internal.Now(),
|
||||||
|
},
|
||||||
|
}); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
// ChangeUserStatus ...
|
// ChangeUserStatus ...
|
||||||
func ChangeUserStatus(userID, newStatus string) error {
|
func ChangeUserStatus(userID, newStatus string) error {
|
||||||
var (
|
var (
|
||||||
|
|
Loading…
Reference in New Issue