feat: implement password reset functionality
- Added PasswordResetPage component for user password reset. - Integrated password reset link in LoginPage with a router link. - Created API endpoints for requesting and confirming password resets. - Added email templates for password reset notifications. - Updated database schema to support password reset tokens. - Enhanced ProfilePage and EditProfileDialog to include personal data fields. - Introduced layout store to manage body dimensions for responsive design. - Added validation for personal data fields in profile management.
This commit is contained in:
@@ -36,6 +36,11 @@ type SetPasswordParams struct {
|
||||
Password string `json:"password" encore:"sensitive"`
|
||||
}
|
||||
|
||||
type SetUserPasswordParams struct {
|
||||
UserID uuid.UUID `json:"user_id"`
|
||||
Password string `json:"password" encore:"sensitive"`
|
||||
}
|
||||
|
||||
// SetPassword changes the password for the authenticated user.
|
||||
//
|
||||
//encore:api auth method=PUT path=/auth/password
|
||||
@@ -60,3 +65,28 @@ func SetPassword(ctx context.Context, p *SetPasswordParams) error {
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// SetUserPassword changes a user's password from trusted internal flows.
|
||||
//
|
||||
//encore:api private method=PUT path=/auth/internal/users/:userID/password
|
||||
func SetUserPassword(ctx context.Context, userID uuid.UUID, p *SetUserPasswordParams) error {
|
||||
if p.UserID != uuid.Nil && p.UserID != userID {
|
||||
return &errs.Error{Code: errs.InvalidArgument, Message: "user id mismatch"}
|
||||
}
|
||||
|
||||
hash, err := hashPassword(p.Password)
|
||||
if err != nil {
|
||||
return errs.WrapCode(err, errs.Internal, "failed to hash password")
|
||||
}
|
||||
|
||||
res, err := db.Exec(ctx, `
|
||||
UPDATE credentials SET password_hash = $2, updated_at = NOW() WHERE user_id = $1
|
||||
`, userID, hash)
|
||||
if err != nil {
|
||||
return errs.WrapCode(err, errs.Internal, "failed to update password")
|
||||
}
|
||||
if res.RowsAffected() == 0 {
|
||||
return &errs.Error{Code: errs.NotFound, Message: "credentials not found"}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user