1234567891011121314151617181920212223242526272829 |
- package middlewares
- import (
- "github.com/gin-gonic/gin"
- "project_management/app/e"
- "project_management/utils"
- "strings"
- )
- func LogonMiddeware() gin.HandlerFunc {
- return func(c *gin.Context) {
- header := c.GetHeader("Authorization")
- split := strings.Split(header, ":")
- if header == "" {
- e.ResponseWithMsg(c, e.TokenIsInvalid, e.TokenIsInvalid.GetMsg())
- c.Abort()
- } else {
- user, err := utils.ParseToken(split[1])
- if err != e.SUCCESS {
- e.ResponseWithMsg(c, err, err.GetMsg())
- c.Abort()
- } else {
- c.Set("phone", user.UserName)
- c.Next()
- }
- }
- }
- }
|