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.

50 lines
1.5 KiB

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