广告平台(总站长使用)
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.
 
 
 
 
 
 

30 lines
615 B

  1. package mw
  2. import (
  3. "applet/app/e"
  4. "applet/app/svc"
  5. "github.com/gin-gonic/gin"
  6. )
  7. // 检查权限, 签名等等
  8. func Auth(c *gin.Context) {
  9. admin, newToken, err := svc.CheckUser(c)
  10. if err != nil {
  11. switch err.(type) {
  12. case e.E:
  13. err1 := err.(e.E)
  14. e.OutErr(c, err1.Code, err1.Error())
  15. return
  16. default:
  17. e.OutErr(c, e.ERR_TOKEN_AUTH, err.Error())
  18. return
  19. }
  20. }
  21. // 将当前请求的username信息保存到请求的上下文c上
  22. c.Set("admin", admin)
  23. if len(newToken) > 0 {
  24. c.Header("new-token", newToken) // TODO::将新Token添加到返回的Header里,方便前端使用
  25. }
  26. c.Next()
  27. }