|
|
@@ -17,7 +17,7 @@ import (
|
|
|
var TouristToken string = "c886a057f3d820d4dbc41473686c7c2d"
|
|
|
|
|
|
// CheckToken Token校验
|
|
|
-func CheckToken(loginid string, token string, group string) error {
|
|
|
+func CheckToken(loginid string, token string, group string) (string, error) {
|
|
|
key := ""
|
|
|
if len(group) == 0 {
|
|
|
key = fmt.Sprintf("monitor:online_loginid::%s", loginid)
|
|
|
@@ -29,14 +29,17 @@ func CheckToken(loginid string, token string, group string) error {
|
|
|
|
|
|
realToken, err := rediscli.GetRedisClient().HGet(key, field).Result()
|
|
|
if err != nil {
|
|
|
- return err
|
|
|
+ return "", err
|
|
|
}
|
|
|
|
|
|
if realToken != token {
|
|
|
- return errors.New("token is invalid")
|
|
|
+ return "", errors.New("token is invalid")
|
|
|
}
|
|
|
|
|
|
- return nil
|
|
|
+ // 获取UserID
|
|
|
+ userID, err := rediscli.GetRedisClient().HGet(key, "UserID").Result()
|
|
|
+
|
|
|
+ return userID, err
|
|
|
}
|
|
|
|
|
|
// CheckNewToken 新接入服务Token校验
|
|
|
@@ -74,6 +77,7 @@ func Auth() gin.HandlerFunc {
|
|
|
|
|
|
var code int
|
|
|
var data interface{}
|
|
|
+ userID := ""
|
|
|
|
|
|
code = e.SUCCESS
|
|
|
token := c.GetHeader("Authorization")
|
|
|
@@ -93,7 +97,9 @@ func Auth() gin.HandlerFunc {
|
|
|
if len(s) == 3 {
|
|
|
group = s[2]
|
|
|
}
|
|
|
- if err := CheckToken(loginid, token, group); err != nil {
|
|
|
+ var err error
|
|
|
+ userID, err = CheckToken(loginid, token, group)
|
|
|
+ if err != nil {
|
|
|
// Token错误
|
|
|
code = e.ERROR_AUTH_CHECK_TOKEN_FAIL
|
|
|
}
|
|
|
@@ -120,6 +126,9 @@ func Auth() gin.HandlerFunc {
|
|
|
}
|
|
|
|
|
|
// FIXME: - 针对POST接口,应判断传入TOKEN对应的用户是否正确(比如判断UserID或AccountID是否对得上等),后期处理
|
|
|
+ if c.Request.Method == "POST" {
|
|
|
+ c.Set("requserid", userID)
|
|
|
+ }
|
|
|
|
|
|
// Token检验成功
|
|
|
c.Next()
|
|
|
@@ -201,7 +210,7 @@ func realToken(c *gin.Context) {
|
|
|
if len(s) == 3 {
|
|
|
group = s[2]
|
|
|
}
|
|
|
- if err := CheckToken(loginid, token, group); err != nil {
|
|
|
+ if _, err := CheckToken(loginid, token, group); err != nil {
|
|
|
// Token错误
|
|
|
code = e.ERROR_AUTH_CHECK_TOKEN_FAIL
|
|
|
}
|