From 832ecaaed0529a2470b2a59c30b7f30ad92cf35c Mon Sep 17 00:00:00 2001
From: liuxiaolong <736321739@qq.com>
Date: 星期五, 22 十一月 2019 15:08:59 +0800
Subject: [PATCH] update license
---
extend/code/code.go | 1
middlewares/auth/auth.go | 2 +
go.sum | 4 +-
go.mod | 2
controllers/license.go | 97 ++++++++++++++++++++++++++++++++++++++++++++++++
router/router.go | 12 +++++-
6 files changed, 113 insertions(+), 5 deletions(-)
diff --git a/controllers/license.go b/controllers/license.go
new file mode 100644
index 0000000..0ae0a1f
--- /dev/null
+++ b/controllers/license.go
@@ -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,"")
+ }
+
+ }
+}
\ No newline at end of file
diff --git a/extend/code/code.go b/extend/code/code.go
index da54881..3ef6457 100644
--- a/extend/code/code.go
+++ b/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, "娣诲姞鎴愬姛"}
diff --git a/go.mod b/go.mod
index 47fa31b..bceffb6 100644
--- a/go.mod
+++ b/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
diff --git a/go.sum b/go.sum
index ccd2a7a..88b6dbf 100644
--- a/go.sum
+++ b/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=
diff --git a/middlewares/auth/auth.go b/middlewares/auth/auth.go
index d897b00..8ffd4e2 100644
--- a/middlewares/auth/auth.go
+++ b/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 {
diff --git a/router/router.go b/router/router.go
index dced050..bb66024 100644
--- a/router/router.go
+++ b/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")
--
Gitblit v1.8.0