|
|
@@ -3,6 +3,7 @@ package token
|
|
|
import (
|
|
|
"errors"
|
|
|
"fmt"
|
|
|
+ "mtp2_if/ex"
|
|
|
"mtp2_if/rediscli"
|
|
|
"net/http"
|
|
|
"strings"
|
|
|
@@ -31,21 +32,20 @@ func CheckToken(loginid string, token string) error {
|
|
|
func Auth() gin.HandlerFunc {
|
|
|
return func(c *gin.Context) {
|
|
|
var code int
|
|
|
- var msg string
|
|
|
var data interface{}
|
|
|
|
|
|
- code = 0
|
|
|
+ code = ex.SUCCESS
|
|
|
token := c.GetHeader("token")
|
|
|
if token == "" {
|
|
|
- code = 3001
|
|
|
- msg = "缺少token"
|
|
|
+ // Token缺失
|
|
|
+ code = ex.ERROR_AUTH_CHECK_TOKEN_MISSING
|
|
|
} else {
|
|
|
// 获取loginid
|
|
|
s := strings.Split(token, "_")
|
|
|
loginid := s[0]
|
|
|
if err := CheckToken(loginid, token); err != nil {
|
|
|
- code = 3002
|
|
|
- msg = "token校验失败"
|
|
|
+ // Token错误
|
|
|
+ code = ex.ERROR_AUTH_CHECK_TOKEN_FAIL
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -53,7 +53,7 @@ func Auth() gin.HandlerFunc {
|
|
|
if code != 0 {
|
|
|
c.JSON(http.StatusUnauthorized, gin.H{
|
|
|
"code": code,
|
|
|
- "msg": msg,
|
|
|
+ "msg": ex.GetMsg(code),
|
|
|
"data": data,
|
|
|
})
|
|
|
|