controllers/license.go | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
extend/code/code.go | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
go.mod | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
go.sum | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
middlewares/auth/auth.go | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
router/router.go | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 |
controllers/license.go
New file @@ -0,0 +1,97 @@ package controllers import ( "basic.com/dbapi.git" "github.com/gin-gonic/gin" "webserver/extend/code" "webserver/extend/util" ) type LicenseController struct { } type LicenseRegister struct { Company string `json:"company" binding:"required"` Email string `json:"email" binding:"required"` Phone string `json:"phone" binding:"required"` } // @Summary 获取注册码 // @Description 获取注册码 // @Accept json // @Produce json // @Tags license // @Param reqBody body controllers.LicenseRegister true "注册参数:公司、邮箱、手机号" // @Success 200 {string} json "{"code":200, success:true, msg:"", data:""}" // @Failure 500 {string} json "{"code":500, success:false, msg:"",data:""}" // @Router /data/api-v/license/getRegisterCode [post] func (lc LicenseController) GetRegisterCode(c *gin.Context) { var reqBody LicenseRegister err := c.BindJSON(&reqBody) if err !=nil { util.ResponseFormat(c,code.RequestParamError,"公司、邮箱和手机号必填") return } var api dbapi.LicenseApi paramBody := util.Struct2Map(reqBody) b, d := api.GetRegisterCode(paramBody) if b { util.ResponseFormat(c,code.Success,d) } else { util.ResponseFormat(c,code.ComError,"") } } type LicenseSaveArg struct { License string `json:"license" binding:"required"` } // @Summary 保存license // @Description 保存license // @Accept json // @Produce json // @Tags license // @Param reqBody body controllers.LicenseSaveArg true "license字符串" // @Success 200 {string} json "{"code":200, success:true, msg:"", data:""}" // @Failure 500 {string} json "{"code":500, success:false, msg:"",data:""}" // @Router /data/api-v/license/save [post] func (lc LicenseController) Save(c *gin.Context) { var reqBody LicenseSaveArg err := c.BindJSON(&reqBody) if err !=nil { util.ResponseFormat(c,code.RequestParamError,"参数有误") return } var api dbapi.LicenseApi paramBody := util.Struct2Map(reqBody) b, d := api.Save(paramBody) if b { util.ResponseFormat(c,code.Success,d) } else { util.ResponseFormat(c,code.UpdateFail,"") } } // @Summary 显示license注册信息 // @Description 显示license注册信息 // @Produce json // @Tags license // @Success 200 {string} json "{"code":200, success:true, msg:"", data:""}" // @Failure 500 {string} json "{"code":500, success:false, msg:"",data:""}" // @Router /data/api-v/license/show [get] func (lc LicenseController) Show(c *gin.Context) { var api dbapi.LicenseApi status,b, d := api.Show() if b { util.ResponseFormat(c,code.Success,d) } else { if status == 403 { util.ResponseFormat(c,code.Success, d) } else { util.ResponseFormat(c,code.ComError,"") } } } extend/code/code.go
@@ -10,6 +10,7 @@ } var ( LicenseExpired = &Code{http.StatusForbidden, false, "license expired"} // Success 请求处理成功 Success = &Code{http.StatusOK, true, "请求处理成功"} AddSuccess = &Code{http.StatusOK, true, "添加成功"} go.mod
@@ -3,7 +3,7 @@ go 1.12 require ( basic.com/dbapi.git v0.0.0-20191114063413-a251b5d8b758 // indirect basic.com/dbapi.git v0.0.0-20191122064621-1675117bdb57 // indirect basic.com/fileServer/WeedFSClient.git v0.0.0-20190919054037-0182b6c3f5cb // indirect basic.com/gb28181api.git v0.0.0-20191028082253-472438a8407b // indirect basic.com/pubsub/cache.git v0.0.0-20190718093725-6a413e1d7d48 // indirect go.sum
@@ -1,5 +1,5 @@ basic.com/dbapi.git v0.0.0-20191114063413-a251b5d8b758 h1:pVQV59Q26COk55JJGum+KSuOvvl2v5fF8ymkcdu0xp8= basic.com/dbapi.git v0.0.0-20191114063413-a251b5d8b758/go.mod h1:eDXPnxaz6jZPDvBSk7ya7oSASWPCuUEgRTJCjsfKt/Q= basic.com/dbapi.git v0.0.0-20191122064621-1675117bdb57 h1:RHd4ZKtKR9oEJ0zNUwz/hHSpqPS63LFe7CxRqRJWFWc= basic.com/dbapi.git v0.0.0-20191122064621-1675117bdb57/go.mod h1:eDXPnxaz6jZPDvBSk7ya7oSASWPCuUEgRTJCjsfKt/Q= basic.com/fileServer/WeedFSClient.git v0.0.0-20190919054037-0182b6c3f5cb h1:fM6DojeInFSCFO+wkba1jtyPiSDqw0jYKi4Tk+e+ka4= basic.com/fileServer/WeedFSClient.git v0.0.0-20190919054037-0182b6c3f5cb/go.mod h1:FTryK8BsVLfUplx8a3+l8hJWub6VbAWZCUH7sPRZaso= basic.com/gb28181api.git v0.0.0-20191028082253-472438a8407b h1:Qh7x2PY3HA9B404Llq+olY5/YlGYrM58bpOHa2CGcro= middlewares/auth/auth.go
@@ -61,6 +61,7 @@ if !jwtDriver.Check(c) { util.ResponseFormat(c,code.TokenNotFound,"尚未登录,请登录") c.Abort() return } userM := (*jwtDriver).User(c) if userM == nil { @@ -72,6 +73,7 @@ if OutUser(userId) { util.ResponseFormat(c,code.TokenNotFound,"尚未登录,请登录") c.Abort() return } c.Next() } else { router/router.go
@@ -44,6 +44,16 @@ clusterController := new(controllers.ClusterController) sysRoleController := new(controllers.RoleController) ptzController := new(controllers.PanTiltZoomController) licenseController := new(controllers.LicenseController) urlPrefix := "/data/api-v" // wp 添加 路径 前缀 licenseApi :=r.Group(urlPrefix+"/license") { licenseApi.POST("/getRegisterCode", licenseController.GetRegisterCode) licenseApi.POST("/save", licenseController.Save) licenseApi.GET("/show", licenseController.Show) } sysApi := r.Group("/data/api-u/sys") { @@ -68,8 +78,6 @@ userApi.POST("/saveAuth", userController.SaveAuth) userApi.POST("/updatePwd", userController.UpdatePwd) } urlPrefix := "/data/api-v" // wp 添加 路径 前缀 //区域管理 area := r.Group(urlPrefix + "/area")