feat: add admin apis
This commit is contained in:
@@ -35,6 +35,7 @@ var (
|
||||
ErrEmailAlreadyVerified = errors.New("email already verified")
|
||||
ErrWeakPassword = errors.New("password must be at least 8 characters")
|
||||
ErrHandleTaken = errors.New("handle already in use")
|
||||
ErrAccountSuspended = errors.New("this account has been suspended")
|
||||
)
|
||||
|
||||
// AuthService bundles every flow that mutates auth state.
|
||||
@@ -193,6 +194,11 @@ func (s *AuthService) LogIn(ctx context.Context, email, password string) (*Login
|
||||
if err := bcrypt.CompareHashAndPassword([]byte(*u.PasswordHash), []byte(password)); err != nil {
|
||||
return nil, ErrInvalidCredentials
|
||||
}
|
||||
// Suspended accounts can't sign in (checked after the password so we don't
|
||||
// reveal ban status to someone who doesn't know the password).
|
||||
if u.BannedAt != nil {
|
||||
return nil, ErrAccountSuspended
|
||||
}
|
||||
|
||||
// OTP gate — unverified email AND account is older than the grace
|
||||
// window. Mint an OTP and signal the caller to collect it. We do NOT
|
||||
@@ -233,6 +239,9 @@ func (s *AuthService) VerifyLoginOTP(ctx context.Context, email, password, otp s
|
||||
if err := bcrypt.CompareHashAndPassword([]byte(*u.PasswordHash), []byte(password)); err != nil {
|
||||
return nil, ErrInvalidCredentials
|
||||
}
|
||||
if u.BannedAt != nil {
|
||||
return nil, ErrAccountSuspended
|
||||
}
|
||||
|
||||
otpHash := hashToken(otp)
|
||||
tok, err := s.tokens.FindValidForUser(ctx, u.ID, otpHash, model.PurposeLoginOTP)
|
||||
|
||||
Reference in New Issue
Block a user