support clearing user tokens by cli
This commit is contained in:
@@ -88,6 +88,18 @@ var UserData = &cli.Command{
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
Name: "user-token-clear",
|
||||||
|
Usage: "Clear user all tokens",
|
||||||
|
Action: clearUserTokens,
|
||||||
|
Flags: []cli.Flag{
|
||||||
|
&cli.StringFlag{
|
||||||
|
Name: "username",
|
||||||
|
Aliases: []string{"n"},
|
||||||
|
Usage: "Specific user name",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
{
|
{
|
||||||
Name: "transaction-check",
|
Name: "transaction-check",
|
||||||
Usage: "Check whether user all transactions and accounts are correct",
|
Usage: "Check whether user all transactions and accounts are correct",
|
||||||
@@ -206,6 +218,26 @@ func deleteUser(c *cli.Context) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func clearUserTokens(c *cli.Context) error {
|
||||||
|
_, err := initializeSystem(c)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
username := c.String("username")
|
||||||
|
err = clis.UserData.ClearUserTokens(c, username)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
log.BootErrorf("[user_data.clearUserTokens] error occurs when clearing user tokens")
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
log.BootInfof("[user_data.clearUserTokens] all tokens of user \"%s\" has been cleared", username)
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func checkUserTransactionAndAccount(c *cli.Context) error {
|
func checkUserTransactionAndAccount(c *cli.Context) error {
|
||||||
_, err := initializeSystem(c)
|
_, err := initializeSystem(c)
|
||||||
|
|
||||||
|
|||||||
@@ -176,6 +176,31 @@ func (l *UserDataCli) DeleteUser(c *cli.Context, username string) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ClearUserTokens clears all tokens of the specified user
|
||||||
|
func (l *UserDataCli) ClearUserTokens(c *cli.Context, username string) error {
|
||||||
|
if username == "" {
|
||||||
|
log.BootErrorf("[user_data.ClearUserTokens] user name is empty")
|
||||||
|
return errs.ErrUsernameIsEmpty
|
||||||
|
}
|
||||||
|
|
||||||
|
uid, err := l.getUserIdByUsername(c, username)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
log.BootErrorf("[user_data.ClearUserTokens] error occurs when getting user id by user name")
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
now := time.Now().Unix()
|
||||||
|
err = l.tokens.DeleteTokensBeforeTime(uid, now)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
log.BootErrorf("[user_data.ClearUserTokens] failed to delete tokens of user \"%s\", because %s", username, err.Error())
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
// CheckTransactionAndAccount checks whether all user transactions and all user accounts are correct
|
// CheckTransactionAndAccount checks whether all user transactions and all user accounts are correct
|
||||||
func (l *UserDataCli) CheckTransactionAndAccount(c *cli.Context, username string) (bool, error) {
|
func (l *UserDataCli) CheckTransactionAndAccount(c *cli.Context, username string) (bool, error) {
|
||||||
if username == "" {
|
if username == "" {
|
||||||
|
|||||||
Reference in New Issue
Block a user