蛋蛋星球-客户端
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.

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