From 6eca1b9b8773c3eaeecfbe69fe715abc3740fc7a Mon Sep 17 00:00:00 2001 From: pixel <303176530@qq.com> Date: Sat, 9 May 2020 17:48:31 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=A0=A1=E9=AA=8C=E5=B7=A5?= =?UTF-8?q?=E5=85=B7=E4=BB=A5=E5=8F=8A=E5=90=8E=E5=8F=B0=E6=A0=A1=E9=AA=8C?= =?UTF-8?q?=E6=8B=A6=E6=88=AA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/api/v1/exa_customer.go | 56 ++++++++++++++++++ server/api/v1/sys_api.go | 48 ++++++++++++++++ server/api/v1/sys_authority.go | 64 +++++++++++++++++++++ server/api/v1/sys_auto_code.go | 12 ++++ server/api/v1/sys_casbin.go | 17 ++++++ server/api/v1/sys_menu.go | 66 +++++++++++++++++++++- server/api/v1/sys_user.go | 58 +++++++++++++++++++ server/api/v1/sys_work_flow.go | 12 ++++ server/utils/{verify.go => validator.go} | 0 web/src/view/example/customer/customer.vue | 2 +- 10 files changed, 331 insertions(+), 4 deletions(-) rename server/utils/{verify.go => validator.go} (100%) diff --git a/server/api/v1/exa_customer.go b/server/api/v1/exa_customer.go index bb244c41..a98824a0 100644 --- a/server/api/v1/exa_customer.go +++ b/server/api/v1/exa_customer.go @@ -7,6 +7,7 @@ import ( "gin-vue-admin/model/request" resp "gin-vue-admin/model/response" "gin-vue-admin/service" + "gin-vue-admin/utils" "github.com/gin-gonic/gin" ) @@ -21,6 +22,17 @@ import ( func CreateExaCustomer(c *gin.Context) { var cu model.ExaCustomer _ = c.ShouldBindJSON(&cu) + CustomerVerify := utils.Rules{ + "CustomerName": {utils.NotEmpty()}, + "CustomerPhoneData": {utils.NotEmpty()}, + "SysUserID": {utils.NotEmpty()}, + "SysUserAuthorityID": {utils.NotEmpty()}, + } + CustomerVerifyErr := utils.Verify(cu, CustomerVerify) + if CustomerVerifyErr!=nil { + response.FailWithMessage(CustomerVerifyErr.Error(), c) + return + } claims, _ := c.Get("claims") waitUse := claims.(*request.CustomClaims) cu.SysUserID = waitUse.ID @@ -44,6 +56,14 @@ func CreateExaCustomer(c *gin.Context) { func DeleteExaCustomer(c *gin.Context) { var cu model.ExaCustomer _ = c.ShouldBindJSON(&cu) + CustomerVerify := utils.Rules{ + "ID": {utils.NotEmpty()}, + } + CustomerVerifyErr := utils.Verify(cu.Model, CustomerVerify) + if CustomerVerifyErr!=nil { + response.FailWithMessage(CustomerVerifyErr.Error(), c) + return + } err := service.DeleteExaCustomer(cu) if err != nil { response.FailWithMessage(fmt.Sprintf("删除失败:%v", err), c) @@ -63,6 +83,25 @@ func DeleteExaCustomer(c *gin.Context) { func UpdateExaCustomer(c *gin.Context) { var cu model.ExaCustomer _ = c.ShouldBindJSON(&cu) + IdCustomerVerify := utils.Rules{ + "ID": {utils.NotEmpty()}, + } + IdCustomerVerifyErr := utils.Verify(cu.Model, IdCustomerVerify) + if IdCustomerVerifyErr!=nil { + response.FailWithMessage(IdCustomerVerifyErr.Error(), c) + return + } + CustomerVerify := utils.Rules{ + "CustomerName": {utils.NotEmpty()}, + "CustomerPhoneData": {utils.NotEmpty()}, + "SysUserID": {utils.NotEmpty()}, + "SysUserAuthorityID": {utils.NotEmpty()}, + } + CustomerVerifyErr := utils.Verify(cu, CustomerVerify) + if CustomerVerifyErr!=nil { + response.FailWithMessage(CustomerVerifyErr.Error(), c) + return + } err := service.UpdateExaCustomer(&cu) if err != nil { response.FailWithMessage(fmt.Sprintf("更新失败:%v", err), c) @@ -82,6 +121,14 @@ func UpdateExaCustomer(c *gin.Context) { func GetExaCustomer(c *gin.Context) { var cu model.ExaCustomer _ = c.ShouldBindQuery(&cu) + IdCustomerVerify := utils.Rules{ + "ID": {utils.NotEmpty()}, + } + IdCustomerVerifyErr := utils.Verify(cu.Model, IdCustomerVerify) + if IdCustomerVerifyErr!=nil { + response.FailWithMessage(IdCustomerVerifyErr.Error(), c) + return + } err, customer := service.GetExaCustomer(cu.ID) if err != nil { response.FailWithMessage(fmt.Sprintf("获取失败:%v", err), c) @@ -103,6 +150,15 @@ func GetExaCustomerList(c *gin.Context) { waitUse := claims.(*request.CustomClaims) var pageInfo request.PageInfo _ = c.ShouldBindQuery(&pageInfo) + CustomerVerify := utils.Rules{ + "Page": {utils.NotEmpty()}, + "PageSize": {utils.NotEmpty()}, + } + CustomerVerifyErr := utils.Verify(pageInfo, CustomerVerify) + if CustomerVerifyErr!=nil { + response.FailWithMessage(CustomerVerifyErr.Error(), c) + return + } err, customerList, total := service.GetCustomerInfoList(waitUse.AuthorityId, pageInfo) if err != nil { response.FailWithMessage(fmt.Sprintf("获取失败:%v", err), c) diff --git a/server/api/v1/sys_api.go b/server/api/v1/sys_api.go index 7fb6926a..e4bd5a0d 100644 --- a/server/api/v1/sys_api.go +++ b/server/api/v1/sys_api.go @@ -7,6 +7,7 @@ import ( "gin-vue-admin/model/request" resp "gin-vue-admin/model/response" "gin-vue-admin/service" + "gin-vue-admin/utils" "github.com/gin-gonic/gin" ) @@ -21,6 +22,17 @@ import ( func CreateApi(c *gin.Context) { var api model.SysApi _ = c.ShouldBindJSON(&api) + ApiVerify := utils.Rules{ + "Path": {utils.NotEmpty()}, + "Description": {utils.NotEmpty()}, + "ApiGroup": {utils.NotEmpty()}, + "Method": {utils.NotEmpty()}, + } + ApiVerifyErr := utils.Verify(api, ApiVerify) + if ApiVerifyErr!=nil { + response.FailWithMessage(ApiVerifyErr.Error(), c) + return + } err := service.CreateApi(api) if err != nil { response.FailWithMessage(fmt.Sprintf("创建失败,%v", err), c) @@ -40,6 +52,14 @@ func CreateApi(c *gin.Context) { func DeleteApi(c *gin.Context) { var a model.SysApi _ = c.ShouldBindJSON(&a) + ApiVerify := utils.Rules{ + "ID": {utils.NotEmpty()}, + } + ApiVerifyErr := utils.Verify(a.Model, ApiVerify) + if ApiVerifyErr!=nil { + response.FailWithMessage(ApiVerifyErr.Error(), c) + return + } err := service.DeleteApi(a) if err != nil { response.FailWithMessage(fmt.Sprintf("删除失败,%v", err), c) @@ -62,6 +82,15 @@ func GetApiList(c *gin.Context) { // 此结构体仅本方法使用 var sp request.SearchApiParams _ = c.ShouldBindJSON(&sp) + ApiVerify := utils.Rules{ + "Page": {utils.NotEmpty()}, + "PageSize": {utils.NotEmpty()}, + } + ApiVerifyErr := utils.Verify(sp.PageInfo, ApiVerify) + if ApiVerifyErr!=nil { + response.FailWithMessage(ApiVerifyErr.Error(), c) + return + } err, list, total := service.GetAPIInfoList(sp.SysApi, sp.PageInfo, sp.OrderKey, sp.Desc) if err != nil { response.FailWithMessage(fmt.Sprintf("获取数据失败,%v", err), c) @@ -86,6 +115,14 @@ func GetApiList(c *gin.Context) { func GetApiById(c *gin.Context) { var idInfo request.GetById _ = c.ShouldBindJSON(&idInfo) + ApiVerify := utils.Rules{ + "Id": {utils.NotEmpty()}, + } + ApiVerifyErr := utils.Verify(idInfo, ApiVerify) + if ApiVerifyErr!=nil { + response.FailWithMessage(ApiVerifyErr.Error(), c) + return + } err, api := service.GetApiById(idInfo.Id) if err != nil { response.FailWithMessage(fmt.Sprintf("获取数据失败,%v", err), c) @@ -105,6 +142,17 @@ func GetApiById(c *gin.Context) { func UpdateApi(c *gin.Context) { var api model.SysApi _ = c.ShouldBindJSON(&api) + ApiVerify := utils.Rules{ + "Path": {utils.NotEmpty()}, + "Description": {utils.NotEmpty()}, + "ApiGroup": {utils.NotEmpty()}, + "Method": {utils.NotEmpty()}, + } + ApiVerifyErr := utils.Verify(api, ApiVerify) + if ApiVerifyErr!=nil { + response.FailWithMessage(ApiVerifyErr.Error(), c) + return + } err := service.UpdateApi(api) if err != nil { response.FailWithMessage(fmt.Sprintf("修改数据失败,%v", err), c) diff --git a/server/api/v1/sys_authority.go b/server/api/v1/sys_authority.go index 842efe14..a2781198 100644 --- a/server/api/v1/sys_authority.go +++ b/server/api/v1/sys_authority.go @@ -7,6 +7,7 @@ import ( "gin-vue-admin/model/request" resp "gin-vue-admin/model/response" "gin-vue-admin/service" + "gin-vue-admin/utils" "github.com/gin-gonic/gin" ) @@ -21,6 +22,16 @@ import ( func CreateAuthority(c *gin.Context) { var auth model.SysAuthority _ = c.ShouldBindJSON(&auth) + AuthorityVerify := utils.Rules{ + "AuthorityId": {utils.NotEmpty()}, + "AuthorityName": {utils.NotEmpty()}, + "ParentId": {utils.NotEmpty()}, + } + AuthorityVerifyErr := utils.Verify(auth, AuthorityVerify) + if AuthorityVerifyErr!=nil { + response.FailWithMessage(AuthorityVerifyErr.Error(), c) + return + } err, authBack := service.CreateAuthority(auth) if err != nil { response.FailWithMessage(fmt.Sprintf("创建失败,%v", err), c) @@ -40,6 +51,24 @@ func CreateAuthority(c *gin.Context) { func CopyAuthority(c *gin.Context) { var copyInfo resp.SysAuthorityCopyResponse _ = c.ShouldBindJSON(©Info) + OldAuthorityVerify := utils.Rules{ + "OldAuthorityId": {utils.NotEmpty()}, + } + OldAuthorityVerifyErr := utils.Verify(copyInfo, OldAuthorityVerify) + if OldAuthorityVerifyErr!=nil { + response.FailWithMessage(OldAuthorityVerifyErr.Error(), c) + return + } + AuthorityVerify := utils.Rules{ + "AuthorityId": {utils.NotEmpty()}, + "AuthorityName": {utils.NotEmpty()}, + "ParentId": {utils.NotEmpty()}, + } + AuthorityVerifyErr := utils.Verify(copyInfo.Authority, AuthorityVerify) + if AuthorityVerifyErr!=nil { + response.FailWithMessage(AuthorityVerifyErr.Error(), c) + return + } err, authBack := service.CopyAuthority(copyInfo) if err != nil { response.FailWithMessage(fmt.Sprintf("拷贝失败,%v", err), c) @@ -59,6 +88,14 @@ func CopyAuthority(c *gin.Context) { func DeleteAuthority(c *gin.Context) { var a model.SysAuthority _ = c.ShouldBindJSON(&a) + AuthorityVerify := utils.Rules{ + "AuthorityId": {utils.NotEmpty()}, + } + AuthorityVerifyErr := utils.Verify(a, AuthorityVerify) + if AuthorityVerifyErr!=nil { + response.FailWithMessage(AuthorityVerifyErr.Error(), c) + return + } //删除角色之前需要判断是否有用户正在使用此角色 err := service.DeleteAuthority(&a) if err != nil { @@ -79,6 +116,16 @@ func DeleteAuthority(c *gin.Context) { func UpdateAuthority(c *gin.Context) { var auth model.SysAuthority _ = c.ShouldBindJSON(&auth) + AuthorityVerify := utils.Rules{ + "AuthorityId": {utils.NotEmpty()}, + "AuthorityName": {utils.NotEmpty()}, + "ParentId": {utils.NotEmpty()}, + } + AuthorityVerifyErr := utils.Verify(auth, AuthorityVerify) + if AuthorityVerifyErr!=nil { + response.FailWithMessage(AuthorityVerifyErr.Error(), c) + return + } err, authority := service.UpdateAuthority(auth) if err != nil { response.FailWithMessage(fmt.Sprintf("更新失败,%v", err), c) @@ -98,6 +145,15 @@ func UpdateAuthority(c *gin.Context) { func GetAuthorityList(c *gin.Context) { var pageInfo request.PageInfo _ = c.ShouldBindJSON(&pageInfo) + AuthorityVerify := utils.Rules{ + "Page": {utils.NotEmpty()}, + "PageSize": {utils.NotEmpty()}, + } + AuthorityVerifyErr := utils.Verify(pageInfo, AuthorityVerify) + if AuthorityVerifyErr!=nil { + response.FailWithMessage(AuthorityVerifyErr.Error(), c) + return + } err, list, total := service.GetAuthorityInfoList(pageInfo) if err != nil { response.FailWithMessage(fmt.Sprintf("获取数据失败,%v", err), c) @@ -122,6 +178,14 @@ func GetAuthorityList(c *gin.Context) { func SetDataAuthority(c *gin.Context) { var auth model.SysAuthority _ = c.ShouldBindJSON(&auth) + AuthorityVerify := utils.Rules{ + "AuthorityId": {utils.NotEmpty()}, + } + AuthorityVerifyErr := utils.Verify(auth, AuthorityVerify) + if AuthorityVerifyErr!=nil { + response.FailWithMessage(AuthorityVerifyErr.Error(), c) + return + } err := service.SetDataAuthority(auth) if err != nil { response.FailWithMessage(fmt.Sprintf("设置关联失败,%v", err), c) diff --git a/server/api/v1/sys_auto_code.go b/server/api/v1/sys_auto_code.go index a4a146ff..7b9934d9 100644 --- a/server/api/v1/sys_auto_code.go +++ b/server/api/v1/sys_auto_code.go @@ -5,6 +5,7 @@ import ( "gin-vue-admin/global/response" "gin-vue-admin/model" "gin-vue-admin/service" + "gin-vue-admin/utils" "github.com/gin-gonic/gin" "net/url" "os" @@ -21,6 +22,17 @@ import ( func CreateTemp(c *gin.Context) { var a model.AutoCodeStruct _ = c.ShouldBindJSON(&a) + AutoCodeVerify := utils.Rules{ + "Abbreviation": {utils.NotEmpty()}, + "StructName": {utils.NotEmpty()}, + "PackageName": {utils.NotEmpty()}, + "Fields": {utils.NotEmpty()}, + } + WKVerifyErr := utils.Verify(a, AutoCodeVerify) + if WKVerifyErr!=nil { + response.FailWithMessage(WKVerifyErr.Error(), c) + return + } if a.AutoCreateApiToSql { apiList := [5]model.SysApi{ { diff --git a/server/api/v1/sys_casbin.go b/server/api/v1/sys_casbin.go index c6f7a3e1..f3dd14ae 100644 --- a/server/api/v1/sys_casbin.go +++ b/server/api/v1/sys_casbin.go @@ -6,6 +6,7 @@ import ( "gin-vue-admin/model/request" resp "gin-vue-admin/model/response" "gin-vue-admin/service" + "gin-vue-admin/utils" "github.com/gin-gonic/gin" ) @@ -20,6 +21,14 @@ import ( func UpdateCasbin(c *gin.Context) { var cmr request.CasbinInReceive _ = c.ShouldBindJSON(&cmr) + CasbinVerify := utils.Rules{ + "AuthorityId": {utils.NotEmpty()}, + } + WKVerifyErr := utils.Verify(cmr, CasbinVerify) + if WKVerifyErr!=nil { + response.FailWithMessage(WKVerifyErr.Error(), c) + return + } err := service.UpdateCasbin(cmr.AuthorityId, cmr.CasbinInfos) if err != nil { response.FailWithMessage(fmt.Sprintf("添加规则失败,%v", err), c) @@ -39,6 +48,14 @@ func UpdateCasbin(c *gin.Context) { func GetPolicyPathByAuthorityId(c *gin.Context) { var cmr request.CasbinInReceive _ = c.ShouldBindJSON(&cmr) + CasbinVerify := utils.Rules{ + "AuthorityId": {utils.NotEmpty()}, + } + WKVerifyErr := utils.Verify(cmr, CasbinVerify) + if WKVerifyErr!=nil { + response.FailWithMessage(WKVerifyErr.Error(), c) + return + } paths := service.GetPolicyPathByAuthorityId(cmr.AuthorityId) response.OkWithData(resp.PolicyPathResponse{Paths: paths}, c) } diff --git a/server/api/v1/sys_menu.go b/server/api/v1/sys_menu.go index ec345ee1..a60468a9 100644 --- a/server/api/v1/sys_menu.go +++ b/server/api/v1/sys_menu.go @@ -40,6 +40,15 @@ func GetMenu(c *gin.Context) { func GetMenuList(c *gin.Context) { var pageInfo request.PageInfo _ = c.ShouldBindJSON(&pageInfo) + PageVerify := utils.Rules{ + "Page": {utils.NotEmpty()}, + "PageSize": {utils.NotEmpty()}, + } + PageVerifyErr := utils.Verify(pageInfo, PageVerify) + if PageVerifyErr!=nil{ + response.FailWithMessage(PageVerifyErr.Error(), c) + return + } err, menuList, total := service.GetInfoList() if err != nil { response.FailWithMessage(fmt.Sprintf("获取数据失败,%v", err), c) @@ -65,11 +74,11 @@ func AddBaseMenu(c *gin.Context) { var menu model.SysBaseMenu _ = c.ShouldBindJSON(&menu) MenuVerify := utils.Rules{ - "Path": {utils.NotEmpty()}, + "Path": {"notEmpty"}, "ParentId": {utils.NotEmpty()}, "Name": {utils.NotEmpty()}, "Component": {utils.NotEmpty()}, - "Sort": {utils.Ge("0")}, + "Sort": {utils.Ge("0"),"ge=0"}, } MenuVerifyErr := utils.Verify(menu, MenuVerify) if MenuVerifyErr != nil { @@ -119,7 +128,14 @@ func GetBaseMenuTree(c *gin.Context) { func AddMenuAuthority(c *gin.Context) { var addMenuAuthorityInfo request.AddMenuAuthorityInfo _ = c.ShouldBindJSON(&addMenuAuthorityInfo) - + MenuVerify := utils.Rules{ + "AuthorityId": {"notEmpty"}, + } + MenuVerifyErr := utils.Verify(addMenuAuthorityInfo, MenuVerify) + if MenuVerifyErr != nil { + response.FailWithMessage(MenuVerifyErr.Error(), c) + return + } err := service.AddMenuAuthority(addMenuAuthorityInfo.Menus, addMenuAuthorityInfo.AuthorityId) if err != nil { response.FailWithMessage(fmt.Sprintf("添加失败,%v", err), c) @@ -139,6 +155,14 @@ func AddMenuAuthority(c *gin.Context) { func GetMenuAuthority(c *gin.Context) { var authorityIdInfo request.AuthorityIdInfo _ = c.ShouldBindJSON(&authorityIdInfo) + MenuVerify := utils.Rules{ + "AuthorityId": {"notEmpty"}, + } + MenuVerifyErr := utils.Verify(authorityIdInfo, MenuVerify) + if MenuVerifyErr != nil { + response.FailWithMessage(MenuVerifyErr.Error(), c) + return + } err, menus := service.GetMenuAuthority(authorityIdInfo.AuthorityId) if err != nil { response.FailWithDetailed(response.ERROR, resp.SysMenusResponse{Menus: menus}, fmt.Sprintf("添加失败,%v", err), c) @@ -158,6 +182,14 @@ func GetMenuAuthority(c *gin.Context) { func DeleteBaseMenu(c *gin.Context) { var idInfo request.GetById _ = c.ShouldBindJSON(&idInfo) + MenuVerify := utils.Rules{ + "Id": {"notEmpty"}, + } + MenuVerifyErr := utils.Verify(idInfo, MenuVerify) + if MenuVerifyErr != nil { + response.FailWithMessage(MenuVerifyErr.Error(), c) + return + } err := service.DeleteBaseMenu(idInfo.Id) if err != nil { response.FailWithMessage(fmt.Sprintf("删除失败:%v", err), c) @@ -178,6 +210,26 @@ func DeleteBaseMenu(c *gin.Context) { func UpdateBaseMenu(c *gin.Context) { var menu model.SysBaseMenu _ = c.ShouldBindJSON(&menu) + MenuVerify := utils.Rules{ + "Path": {"notEmpty"}, + "ParentId": {utils.NotEmpty()}, + "Name": {utils.NotEmpty()}, + "Component": {utils.NotEmpty()}, + "Sort": {utils.Ge("0"),"ge=0"}, + } + MenuVerifyErr := utils.Verify(menu, MenuVerify) + if MenuVerifyErr != nil { + response.FailWithMessage(MenuVerifyErr.Error(), c) + return + } + MetaVerify := utils.Rules{ + "Title": {utils.NotEmpty()}, + } + MetaVerifyErr := utils.Verify(menu.Meta, MetaVerify) + if MetaVerifyErr != nil { + response.FailWithMessage(MetaVerifyErr.Error(), c) + return + } err := service.UpdateBaseMenu(menu) if err != nil { response.FailWithMessage(fmt.Sprintf("修改失败:%v", err), c) @@ -197,6 +249,14 @@ func UpdateBaseMenu(c *gin.Context) { func GetBaseMenuById(c *gin.Context) { var idInfo request.GetById _ = c.ShouldBindJSON(&idInfo) + MenuVerify := utils.Rules{ + "Id": {"notEmpty"}, + } + MenuVerifyErr := utils.Verify(idInfo, MenuVerify) + if MenuVerifyErr != nil { + response.FailWithMessage(MenuVerifyErr.Error(), c) + return + } err, menu := service.GetBaseMenuById(idInfo.Id) if err != nil { response.FailWithMessage(fmt.Sprintf("查询失败:%v", err), c) diff --git a/server/api/v1/sys_user.go b/server/api/v1/sys_user.go index 90b1db15..70967676 100644 --- a/server/api/v1/sys_user.go +++ b/server/api/v1/sys_user.go @@ -27,6 +27,17 @@ import ( func Register(c *gin.Context) { var R request.RegisterStruct _ = c.ShouldBindJSON(&R) + UserVerify := utils.Rules{ + "Username": {utils.NotEmpty()}, + "NickName": {utils.NotEmpty()}, + "Password": {utils.NotEmpty()}, + "AuthorityId": {utils.NotEmpty()}, + } + UserVerifyErr := utils.Verify(R, UserVerify) + if UserVerifyErr!=nil { + response.FailWithMessage(UserVerifyErr.Error(), c) + return + } user := &model.SysUser{Username: R.Username, NickName: R.NickName, Password: R.Password, HeaderImg: R.HeaderImg, AuthorityId: R.AuthorityId} err, userReturn := service.Register(*user) if err != nil { @@ -45,6 +56,17 @@ func Register(c *gin.Context) { func Login(c *gin.Context) { var L request.RegisterAndLoginStruct _ = c.ShouldBindJSON(&L) + UserVerify := utils.Rules{ + "CaptchaId": {utils.NotEmpty()}, + "Captcha": {utils.NotEmpty()}, + "Username": {utils.NotEmpty()}, + "Password": {utils.NotEmpty()}, + } + UserVerifyErr := utils.Verify(L, UserVerify) + if UserVerifyErr!=nil { + response.FailWithMessage(UserVerifyErr.Error(), c) + return + } if captcha.VerifyString(L.CaptchaId, L.Captcha) { U := &model.SysUser{Username: L.Username, Password: L.Password} if err, user := service.Login(U); err != nil { @@ -134,6 +156,16 @@ func tokenNext(c *gin.Context, user model.SysUser) { func ChangePassword(c *gin.Context) { var params request.ChangePasswordStruct _ = c.ShouldBindJSON(¶ms) + UserVerify := utils.Rules{ + "Username": {utils.NotEmpty()}, + "Password": {utils.NotEmpty()}, + "NewPassword": {utils.NotEmpty()}, + } + UserVerifyErr := utils.Verify(params, UserVerify) + if UserVerifyErr!=nil { + response.FailWithMessage(UserVerifyErr.Error(), c) + return + } U := &model.SysUser{Username: params.Username, Password: params.Password} if err, _ := service.ChangePassword(U, params.NewPassword); err != nil { response.FailWithMessage("修改失败,请检查用户名密码", c) @@ -193,6 +225,15 @@ func UploadHeaderImg(c *gin.Context) { func GetUserList(c *gin.Context) { var pageInfo request.PageInfo _ = c.ShouldBindJSON(&pageInfo) + UserVerify := utils.Rules{ + "Page": {utils.NotEmpty()}, + "PageSize": {utils.NotEmpty()}, + } + UserVerifyErr := utils.Verify(pageInfo, UserVerify) + if UserVerifyErr!=nil { + response.FailWithMessage(UserVerifyErr.Error(), c) + return + } err, list, total := service.GetUserInfoList(pageInfo) if err != nil { response.FailWithMessage(fmt.Sprintf("获取数据失败,%v", err), c) @@ -217,6 +258,15 @@ func GetUserList(c *gin.Context) { func SetUserAuthority(c *gin.Context) { var sua request.SetUserAuth _ = c.ShouldBindJSON(&sua) + UserVerify := utils.Rules{ + "UUID": {utils.NotEmpty()}, + "AuthorityId": {utils.NotEmpty()}, + } + UserVerifyErr := utils.Verify(sua, UserVerify) + if UserVerifyErr!=nil { + response.FailWithMessage(UserVerifyErr.Error(), c) + return + } err := service.SetUserAuthority(sua.UUID, sua.AuthorityId) if err != nil { response.FailWithMessage(fmt.Sprintf("修改失败,%v", err), c) @@ -236,6 +286,14 @@ func SetUserAuthority(c *gin.Context) { func DeleteUser(c *gin.Context) { var reqId request.GetById _ = c.ShouldBindJSON(&reqId) + UserVerify := utils.Rules{ + "Id": {utils.NotEmpty()}, + } + UserVerifyErr := utils.Verify(reqId, UserVerify) + if UserVerifyErr!=nil { + response.FailWithMessage(UserVerifyErr.Error(), c) + return + } err := service.DeleteUser(reqId.Id) if err != nil { response.FailWithMessage(fmt.Sprintf("删除失败,%v", err), c) diff --git a/server/api/v1/sys_work_flow.go b/server/api/v1/sys_work_flow.go index 9e59c715..e9261df6 100644 --- a/server/api/v1/sys_work_flow.go +++ b/server/api/v1/sys_work_flow.go @@ -5,6 +5,7 @@ import ( "gin-vue-admin/global/response" "gin-vue-admin/model" "gin-vue-admin/service" + "gin-vue-admin/utils" "github.com/gin-gonic/gin" ) @@ -17,6 +18,17 @@ import ( func CreateWorkFlow(c *gin.Context) { var wk model.SysWorkflow _ = c.ShouldBindJSON(&wk) + WKVerify := utils.Rules{ + "WorkflowNickName": {utils.NotEmpty()}, + "WorkflowName": {utils.NotEmpty()}, + "WorkflowDescription": {utils.NotEmpty()}, + "WorkflowStepInfo": {utils.NotEmpty()}, + } + WKVerifyErr := utils.Verify(wk, WKVerify) + if WKVerifyErr!=nil { + response.FailWithMessage(WKVerifyErr.Error(), c) + return + } err := service.Create(wk) if err != nil { response.FailWithMessage(fmt.Sprintf("获取失败:%v", err), c) diff --git a/server/utils/verify.go b/server/utils/validator.go similarity index 100% rename from server/utils/verify.go rename to server/utils/validator.go diff --git a/web/src/view/example/customer/customer.vue b/web/src/view/example/customer/customer.vue index e445f4d2..e9ac9075 100644 --- a/web/src/view/example/customer/customer.vue +++ b/web/src/view/example/customer/customer.vue @@ -48,7 +48,7 @@ layout="total, sizes, prev, pager, next, jumper" > - +