add listing user sessions cli

This commit is contained in:
MaysWind
2021-04-17 22:49:58 +08:00
parent 2c5b5839d7
commit bf1db401fe
2 changed files with 71 additions and 0 deletions
+24
View File
@@ -178,6 +178,30 @@ func (l *UserDataCli) DeleteUser(c *cli.Context, username string) error {
return nil
}
// ListUserTokens returns all tokens of the specified user
func (l *UserDataCli) ListUserTokens(c *cli.Context, username string) ([]*models.TokenRecord, error) {
if username == "" {
log.BootErrorf("[user_data.ListUserTokens] user name is empty")
return nil, errs.ErrUsernameIsEmpty
}
uid, err := l.getUserIdByUsername(c, username)
if err != nil {
log.BootErrorf("[user_data.ListUserTokens] error occurs when getting user id by user name")
return nil, err
}
tokens, err := l.tokens.GetAllUnexpiredNormalTokensByUid(uid)
if err != nil {
log.BootErrorf("[user_data.ListUserTokens] failed to get tokens of user \"%s\", because %s", username, err.Error())
return nil, err
}
return tokens, nil
}
// ClearUserTokens clears all tokens of the specified user
func (l *UserDataCli) ClearUserTokens(c *cli.Context, username string) error {
if username == "" {