|
1234567891011121314151617181920212223242526272829 |
- package mw
-
- import (
- "applet/app/e"
- "applet/app/svc"
- "github.com/gin-gonic/gin"
- )
-
- // 检查权限, 签名等等
- func Auth(c *gin.Context) {
- admin, newToken, err := svc.CheckUser(c)
- if err != nil {
- switch err.(type) {
- case e.E:
- err1 := err.(e.E)
- e.OutErr(c, err1.Code, err1.Error())
- return
- default:
- e.OutErr(c, e.ERR_TOKEN_AUTH, err.Error())
- return
- }
- }
- // 将当前请求的username信息保存到请求的上下文c上
- c.Set("admin", admin)
- if len(newToken) > 0 {
- c.Header("new-token", newToken) // TODO::将新Token添加到返回的Header里,方便前端使用
- }
- c.Next()
- }
|