Skip to content

Commit 5c19ea5

Browse files
committed
refactor: optimize user status
1 parent b71e538 commit 5c19ea5

File tree

3 files changed

+9
-9
lines changed

3 files changed

+9
-9
lines changed

internal/nightwatch/watcher/user/fsm.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@ import (
1111
// The FSM is configured with the following events and callbacks:
1212
//
1313
// Events:
14-
// - UserStatusRegistered -> UserStatusActive
14+
// - UserStatusRegistered -> UserStatusActived
1515
// - UserStatusBlacklisted -> UserStatusDisabled
1616
// - UserStatusDisabled -> UserStatusDeleted
1717
//
1818
// Callbacks:
19-
// - UserStatusActive: Calls the NewActiveUserCallback function to handle the "active user" event.
19+
// - UserStatusActived: Calls the NewActiveUserCallback function to handle the "active user" event.
2020
// - UserStatusDisabled: Calls the NewDisableUserCallback function to handle the "disable user" event.
2121
// - UserStatusDeleted: Calls the NewDeleteUserCallback function to handle the "delete user" event.
2222
// - UserEventAfterEvent: Calls the NewUserEventAfterEvent function after any user-related event is handled.
@@ -27,17 +27,17 @@ func NewFSM(initial string, w *userWatcher) *fsm.FSM {
2727
initial,
2828
fsm.Events{
2929
// Define status events.
30-
{Name: known.UserStatusRegistered, Src: []string{known.UserStatusRegistered}, Dst: known.UserStatusActive},
30+
{Name: known.UserStatusRegistered, Src: []string{known.UserStatusRegistered}, Dst: known.UserStatusActived},
3131
{Name: known.UserStatusBlacklisted, Src: []string{known.UserStatusBlacklisted}, Dst: known.UserStatusDisabled},
3232
// Define need events.
33-
{Name: known.UserStatusNeedActive, Src: []string{known.UserStatusNeedActive}, Dst: known.UserStatusActive},
33+
{Name: known.UserStatusNeedActive, Src: []string{known.UserStatusNeedActive}, Dst: known.UserStatusActived},
3434
{Name: known.UserStatusNeedDisable, Src: []string{known.UserStatusNeedDisable}, Dst: known.UserStatusDisabled},
3535
// After disabling the user, they can be deleted, and the FSM will automatically transition to the next deleted state.
3636
// I have decided not to delete the user in the code, so the state transition here is commented out.
3737
// {Name: known.UserStatusDisabled, Src: []string{known.UserStatusDisabled}, Dst: known.UserStatusDeleted},
3838
},
3939
fsm.Callbacks{
40-
known.UserStatusActive: NewActiveUserCallback(w.store),
40+
known.UserStatusActived: NewActiveUserCallback(w.store),
4141
known.UserStatusDisabled: NewDisableUserCallback(w.store),
4242
known.UserStatusDeleted: NewDeleteUserCallback(w.store),
4343
// log, alert, save to stoer, etc for all events.

internal/pkg/known/usercenter/status.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const (
88
UserStatusRegistered = "registered"
99
// The user has registered and been verified, and can use the system normally.
1010
// Most user operations are performed in this state.
11-
UserStatusActive = "active"
11+
UserStatusActived = "actived"
1212
// The user has entered the incorrect password too many times, and the account has been locked by the system.
1313
// The user needs to recover the password or contact the administrator to unlock the account.
1414
UserStatusLocked = "locked"
@@ -24,8 +24,8 @@ const (
2424
)
2525

2626
// Define need status.
27-
// We can directly update the database to the "Need" state to inform
28-
// onex-nightwatch of what needs to be done.
27+
// We can directly update the database to the "Need" state to inform onex-nightwatch of what needs to be done.
28+
// These statuses are only used for operation and maintenance purposes.
2929
const (
3030
// UserStatusNeedActive informs onex-nightwatch that the user needs to be activated.
3131
UserStatusNeedActive = "need_active"

internal/usercenter/model/hook.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ func (u *UserM) BeforeCreate(tx *gorm.DB) (err error) {
4747
return err // Return error if there's a problem with encryption.
4848
}
4949

50-
u.Status = known.UserStatusActive // Set the default status for the user as active.
50+
u.Status = known.UserStatusActived // Set the default status for the user as active.
5151

5252
return nil
5353
}

0 commit comments

Comments
 (0)