| | |
| | | import ( |
| | | "log" |
| | | "os" |
| | | "wms/constvar" |
| | | "wms/pkg/logx" |
| | | "wms/pkg/mysqlx" |
| | | |
| | |
| | | JWTSecret string |
| | | FileServer string //文件服务器地址 |
| | | ServerId string //服务ID |
| | | Env constvar.Env |
| | | GrpcPort string //grpc端口号 |
| | | CompanyName string //公司名 |
| | | } |
New file |
| | |
| | | package constvar |
| | | |
| | | type Env string |
| | | |
| | | const ( |
| | | EnvDev = "dev" |
| | | EnvTest = "test" |
| | | EnvProd = "prod" |
| | | ) |
| | | |
| | | func (e Env) IsProd() bool { |
| | | return e == EnvProd |
| | | } |
| | | |
| | | func (e Env) IsDev() bool { |
| | | return e == EnvDev |
| | | } |
| | | |
| | | func (e Env) IsTest() bool { |
| | | return e == EnvTest |
| | | } |
| | |
| | | import ( |
| | | "github.com/gin-gonic/gin" |
| | | "strings" |
| | | "wms/conf" |
| | | "wms/pkg/contextx" |
| | | "wms/pkg/ecode" |
| | | ) |
| | | |
| | | func JWTAuth() gin.HandlerFunc { |
| | | return func(c *gin.Context) { |
| | | if conf.WebConf.Env.IsDev() { |
| | | c.Next() |
| | | return |
| | | } |
| | | ctx := new(contextx.Context).SetCtx(c) |
| | | // 我们这里jwt鉴权取头部信息 Authorization 登录时回返回token信息 这里前端需要把token存储到cookie或者本地localStorage中 不过需要跟后端协商过期时间 可以约定刷新令牌或者重新登录 |
| | | token := c.Request.Header.Get("Authorization") |
| | |
| | | |
| | | import ( |
| | | "github.com/gin-gonic/gin" |
| | | "wms/conf" |
| | | "wms/pkg/contextx" |
| | | "wms/pkg/ecode" |
| | | "wms/request" |
| | |
| | | |
| | | func VerifyResetPwd() gin.HandlerFunc { |
| | | return func(c *gin.Context) { |
| | | if conf.WebConf.Env.IsDev() { |
| | | c.Next() |
| | | return |
| | | } |
| | | ctx := new(contextx.Context).SetCtx(c) |
| | | params, ok := c.Get("claims") |
| | | if !ok { |
| | | c.Abort() |
| | | c.Next() |
| | | return |
| | | } |
| | | claims := params.(*request.CustomClaims) |