You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

46 lines
1.4 KiB

  1. package service
  2. import (
  3. "gin-vue-admin/global"
  4. "gin-vue-admin/model"
  5. )
  6. // @title JsonInBlacklist
  7. // @description create jwt blacklist
  8. // @auth (2020/04/05 20:22 )
  9. // @return err error
  10. func JsonInBlacklist(j *model.JwtBlacklist) (err error) {
  11. err = global.GVA_DB.Create(j).Error
  12. return
  13. }
  14. // @title IsBlacklist
  15. // @description check if the Jwt is in the blacklist or not, 判断JWT是否在黑名单内部
  16. // @auth (2020/04/05 20:22 )
  17. // @param newPassword string
  18. // @return err error
  19. func IsBlacklist(Jwt string, j model.JwtBlacklist) bool {
  20. isNotFound := global.GVA_DB.Where("jwt = ?", Jwt).First(j).RecordNotFound()
  21. return !isNotFound
  22. }
  23. // @title GetRedisJWT
  24. // @description Get user info in redis
  25. // @auth (2020/04/05 20:22 )
  26. // @param newPassword string
  27. // @return err error
  28. func GetRedisJWT(userName string) (err error, RedisJWT string) {
  29. RedisJWT, err = global.GVA_REDIS.Get(userName).Result()
  30. return err, RedisJWT
  31. }
  32. // @title SetRedisJWT
  33. // @description set jwt into the Redis
  34. // @auth (2020/04/05 20:22 )
  35. // @param userName string
  36. // @return err error
  37. func SetRedisJWT(j model.JwtBlacklist, userName string) (err error) {
  38. err = global.GVA_REDIS.Set(userName, j.Jwt, 1000*1000*1000*60*60*24*7).Err()
  39. return err
  40. }