|
|
@@ -16,8 +16,14 @@ import (
|
|
|
var TouristToken string = "c886a057f3d820d4dbc41473686c7c2d"
|
|
|
|
|
|
// CheckToken Token校验
|
|
|
-func CheckToken(loginid string, token string) error {
|
|
|
- key := fmt.Sprintf("monitor:online_loginid::%s", loginid)
|
|
|
+func CheckToken(loginid string, token string, group string) error {
|
|
|
+ key := ""
|
|
|
+ if len(group) == 0 {
|
|
|
+ key = fmt.Sprintf("monitor:online_loginid::%s", loginid)
|
|
|
+ } else {
|
|
|
+ key = fmt.Sprintf("monitor:online_loginid:%s:%s", loginid, group)
|
|
|
+ }
|
|
|
+
|
|
|
field := "Token"
|
|
|
|
|
|
realToken, err := rediscli.GetRedisClient().HGet(key, field).Result()
|
|
|
@@ -52,7 +58,12 @@ func Auth() gin.HandlerFunc {
|
|
|
// 获取loginid
|
|
|
s := strings.Split(token, "_")
|
|
|
loginid := s[0]
|
|
|
- if err := CheckToken(loginid, token); err != nil {
|
|
|
+ // 支持分组功能
|
|
|
+ group := ""
|
|
|
+ if len(s) == 3 {
|
|
|
+ group = s[2]
|
|
|
+ }
|
|
|
+ if err := CheckToken(loginid, token, group); err != nil {
|
|
|
// Token错误
|
|
|
code = e.ERROR_AUTH_CHECK_TOKEN_FAIL
|
|
|
}
|
|
|
@@ -147,7 +158,12 @@ func realToken(c *gin.Context) {
|
|
|
// 获取loginid
|
|
|
s := strings.Split(token, "_")
|
|
|
loginid := s[0]
|
|
|
- if err := CheckToken(loginid, token); err != nil {
|
|
|
+ // 支持分组功能
|
|
|
+ group := ""
|
|
|
+ if len(s) == 3 {
|
|
|
+ group = s[2]
|
|
|
+ }
|
|
|
+ if err := CheckToken(loginid, token, group); err != nil {
|
|
|
// Token错误
|
|
|
code = e.ERROR_AUTH_CHECK_TOKEN_FAIL
|
|
|
}
|