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.
|
|
|
package cache
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
|
|
"github.com/go-redis/redis"
|
|
|
|
"recook/internal/dbc"
|
|
|
|
"recook/internal/model/user"
|
|
|
|
user2 "recook/internal/v2/model/recook/user"
|
|
|
|
)
|
|
|
|
|
|
|
|
// SetUserLoginCache 缓存登录令牌
|
|
|
|
func SetUserLoginCache(l *user.Login) {
|
|
|
|
k := fmt.Sprintf("login:%d:user_%d", l.DeviceType, l.ID)
|
|
|
|
err := dbc.Rds.Set(k, l.Token, 0).Err()
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func GetUserLoginCache(id uint, deviceType int) string {
|
|
|
|
k := fmt.Sprintf("login:%d:user_%d", deviceType, id)
|
|
|
|
val, err := dbc.Rds.Get(k).Result()
|
|
|
|
if err != nil {
|
|
|
|
if err == redis.Nil {
|
|
|
|
return ""
|
|
|
|
} else {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return val
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetDeviceType 获取登录设备类型
|
|
|
|
func GetDeviceType(c *gin.Context) int {
|
|
|
|
deviceType := c.Request.Header.Get("Device-Type")
|
|
|
|
|
|
|
|
dType := user2.RecookUserLoginDeviceTypeDefault
|
|
|
|
switch deviceType {
|
|
|
|
case user2.RecookUserLoginDeviceTypeStrWxApp:
|
|
|
|
dType = user2.RecookUserLoginDeviceTypeWxApp
|
|
|
|
case user2.RecookUserLoginDeviceTypeStrAndroid:
|
|
|
|
dType = user2.RecookUserLoginDeviceTypeApp
|
|
|
|
case user2.RecookUserLoginDeviceTypeStrIos:
|
|
|
|
dType = user2.RecookUserLoginDeviceTypeApp
|
|
|
|
}
|
|
|
|
return dType
|
|
|
|
}
|