replace static status definition by const
This commit is contained in:
+8
-8
@@ -70,7 +70,7 @@ func (s *Service) CreateUser(ctx context.Context, params CreateUserParams) (*Aut
|
||||
ID: userID,
|
||||
Kind: identity.KindUser,
|
||||
Name: display,
|
||||
Status: "active",
|
||||
Status: identity.StatusActive,
|
||||
CreatedAt: now,
|
||||
}); err != nil {
|
||||
return err
|
||||
@@ -89,7 +89,7 @@ func (s *Service) CreateUser(ctx context.Context, params CreateUserParams) (*Aut
|
||||
Valid: true,
|
||||
},
|
||||
MustChangePassword: 0,
|
||||
State: "active",
|
||||
State: AccountStateActive,
|
||||
FailedAttempts: 0,
|
||||
CreatedAt: now,
|
||||
}); err != nil {
|
||||
@@ -135,23 +135,23 @@ func (s *Service) Authenticate(ctx context.Context, login, password string) (*Au
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
if principal.Status != "active" {
|
||||
if principal.Status != identity.StatusActive {
|
||||
return nil, ErrInvalidCredentials
|
||||
}
|
||||
|
||||
now := time.Now().UnixMilli()
|
||||
|
||||
switch account.State {
|
||||
case "disabled":
|
||||
case AccountStateDisabled:
|
||||
return nil, ErrAccountDisabled
|
||||
case "locked":
|
||||
case AccountStateLocked:
|
||||
if !account.LockedUntil.Valid || account.LockedUntil.Int64 > now {
|
||||
return nil, ErrAccountLocked
|
||||
}
|
||||
if _, err := s.db.WriteQueries.UnlockAccount(ctx, account.PrincipalID); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
account.State = "active"
|
||||
account.State = AccountStateActive
|
||||
account.FailedAttempts = 0
|
||||
account.LockedUntil = sql.NullInt64{}
|
||||
}
|
||||
@@ -177,7 +177,7 @@ func (s *Service) Authenticate(ctx context.Context, login, password string) (*Au
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if updated.State == "locked" {
|
||||
if updated.State == AccountStateLocked {
|
||||
return nil, ErrAccountLocked
|
||||
}
|
||||
return nil, ErrInvalidCredentials
|
||||
@@ -241,7 +241,7 @@ func (s *Service) loadAuthenticatedUser(ctx context.Context, id ident.UUID) (*Au
|
||||
Account: Account{
|
||||
PrincipalID: id,
|
||||
Login: principal.Name,
|
||||
State: "active",
|
||||
State: AccountStateActive,
|
||||
},
|
||||
}, nil
|
||||
default:
|
||||
|
||||
Reference in New Issue
Block a user