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.

53 lines
1.6 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. // @param jwtList model.JwtBlacklist
  9. // @auth (2020/04/05 20:22)
  10. // @return err error
  11. func JsonInBlacklist(jwtList model.JwtBlacklist) (err error) {
  12. err = global.GVA_DB.Create(&jwtList).Error
  13. return
  14. }
  15. // @title IsBlacklist
  16. // @description check if the Jwt is in the blacklist or not, 判断JWT是否在黑名单内部
  17. // @auth (2020/04/05 20:22)
  18. // @param jwt string
  19. // @param jwtList model.JwtBlacklist
  20. // @return err error
  21. func IsBlacklist(jwt string, jwtList model.JwtBlacklist) bool {
  22. isNotFound := global.GVA_DB.Where("jwt = ?", jwt).First(&jwtList).RecordNotFound()
  23. return !isNotFound
  24. }
  25. // @title GetRedisJWT
  26. // @description Get user info in redis
  27. // @auth (2020/04/05 20:22)
  28. // @param userName string
  29. // @return err error
  30. // @return redisJWT string
  31. func GetRedisJWT(userName string) (err error, redisJWT string) {
  32. redisJWT, err = global.GVA_REDIS.Get(userName).Result()
  33. return err, redisJWT
  34. }
  35. // @title SetRedisJWT
  36. // @description set jwt into the Redis
  37. // @auth (2020/04/05 20:22)
  38. // @param jwtList model.JwtBlacklist
  39. // @param userName string
  40. // @return err error
  41. func SetRedisJWT(jwtList model.JwtBlacklist, userName string) (err error) {
  42. err = global.GVA_REDIS.Set(userName, jwtList.Jwt, 1000*1000*1000*60*60*24*7).Err()
  43. return err
  44. }