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.

35 lines
881 B

  1. package sysModel
  2. import (
  3. "gin-vue-admin/init/initRedis"
  4. "gin-vue-admin/init/qmsql"
  5. "github.com/jinzhu/gorm"
  6. )
  7. type JwtBlacklist struct {
  8. gorm.Model
  9. Jwt string `gorm:"type:text"`
  10. }
  11. func (j *JwtBlacklist) JsonInBlacklist() (err error) {
  12. err = qmsql.DEFAULTDB.Create(j).Error
  13. return
  14. }
  15. //判断JWT是否在黑名单内部
  16. func (j *JwtBlacklist) IsBlacklist(Jwt string) bool {
  17. isNotFound := qmsql.DEFAULTDB.Where("jwt = ?", Jwt).First(j).RecordNotFound()
  18. return !isNotFound
  19. }
  20. //判断当前用户是否在线
  21. func (j *JwtBlacklist) GetRedisJWT(userName string) (err error, RedisJWT string) {
  22. RedisJWT, err = initRedis.DEFAULTREDIS.Get(userName).Result()
  23. return err, RedisJWT
  24. }
  25. //设置当前用户在线
  26. func (j *JwtBlacklist) SetRedisJWT(userName string) (err error) {
  27. err = initRedis.DEFAULTREDIS.Set(userName, j.Jwt, 1000*1000*1000*60*60*24*7).Err()
  28. return err
  29. }