feat: complete Kra admin backend migration
This commit is contained in:
@@ -162,13 +162,17 @@ func (s *SettingsService) CreateAPIToken(ctx context.Context, userID, authorityI
|
||||
return "", errors.New("有效天数必须大于0或为-1")
|
||||
}
|
||||
secret, issuer := "", "kra"
|
||||
buffer := 24 * time.Hour
|
||||
if s.config != nil && s.config.Jwt != nil {
|
||||
secret = s.config.Jwt.SigningKey
|
||||
if s.config.Jwt.Issuer != "" {
|
||||
issuer = s.config.Jwt.Issuer
|
||||
}
|
||||
if s.config.Jwt.BufferTime != nil {
|
||||
buffer = s.config.Jwt.BufferTime.AsDuration()
|
||||
}
|
||||
}
|
||||
token, _, err := adminauth.Generate(secret, issuer, duration, user.ID, authorityID, user.UUID, user.Username, user.NickName, false)
|
||||
token, _, err := adminauth.Generate(secret, issuer, duration, buffer, user.ID, authorityID, user.UUID, user.Username, user.NickName, false)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
@@ -190,8 +194,14 @@ func (s *SettingsService) APITokens(ctx context.Context, page, size int, userID
|
||||
return out, total, nil
|
||||
}
|
||||
func (s *SettingsService) DisableAPIToken(ctx context.Context, id uint) error {
|
||||
_, err := s.Repo().DisableAPIToken(ctx, id)
|
||||
return err
|
||||
token, err := s.Repo().DisableAPIToken(ctx, id)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return s.Repo().BlacklistToken(ctx, token)
|
||||
}
|
||||
func (s *SettingsService) BlacklistToken(ctx context.Context, token string) error {
|
||||
return s.Repo().BlacklistToken(ctx, token)
|
||||
}
|
||||
func (s *SettingsService) IsTokenDisabled(ctx context.Context, token string) (bool, error) {
|
||||
return s.Repo().IsTokenDisabled(ctx, token)
|
||||
|
||||
Reference in New Issue
Block a user