From ddd97d5a9e1b9e889405faa069a7d4532bb1c583 Mon Sep 17 00:00:00 2001 From: zhangwenjian Date: Wed, 9 Nov 2022 17:35:16 +0800 Subject: [PATCH] =?UTF-8?q?fix=F0=9F=90=9B:=20Adjust=20the=20demo=20enviro?= =?UTF-8?q?nment=20configuration?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/admin/apis/sys_user.go | 21 +++------------------ common/middleware/handler/auth.go | 6 +----- common/middleware/init.go | 4 ++-- common/middleware/logger.go | 6 +----- 4 files changed, 7 insertions(+), 30 deletions(-) diff --git a/app/admin/apis/sys_user.go b/app/admin/apis/sys_user.go index ed932ff3..64eb5013 100644 --- a/app/admin/apis/sys_user.go +++ b/app/admin/apis/sys_user.go @@ -2,7 +2,6 @@ package apis import ( "github.com/gin-gonic/gin/binding" - "github.com/go-admin-team/go-admin-core/sdk/config" "go-admin/app/admin/models" "golang.org/x/crypto/bcrypt" "net/http" @@ -313,19 +312,12 @@ func (e SysUser) ResetPwd(c *gin.Context) { //数据权限检查 p := actions.GetPermissionFromContext(c) - if req.UserId == 1 && config.ApplicationConfig.Mode == "demo" { - req.Password = "123456" - } err = s.ResetPwd(&req, p) if err != nil { e.Logger.Error(err) return } - if req.UserId == 1 && config.ApplicationConfig.Mode == "demo" { - e.OK(req.GetId(), "admin:现在使用的预览环境,休想改掉我!否则会影响其他朋友体验的哦!可以创建其他用户体验该功能!") - } else { - e.OK(req.GetId(), "更新成功") - } + e.OK(req.GetId(), "更新成功") } // UpdatePwd @@ -354,10 +346,6 @@ func (e SysUser) UpdatePwd(c *gin.Context) { // 数据权限检查 p := actions.GetPermissionFromContext(c) - if user.GetUserId(c) == 1 && config.ApplicationConfig.Mode == "demo" { - req.NewPassword = "123456" - } - var hash []byte if hash, err = bcrypt.GenerateFromPassword([]byte(req.NewPassword), bcrypt.DefaultCost); err != nil { req.NewPassword = string(hash) @@ -369,11 +357,8 @@ func (e SysUser) UpdatePwd(c *gin.Context) { e.Error(http.StatusForbidden, err, "密码修改失败") return } - if user.GetUserId(c) == 1 && config.ApplicationConfig.Mode == "demo" { - e.OK(nil, "admin:现在使用的预览环境,休想改掉我!否则会影响其他朋友体验的哦!可以创建其他用户体验该功能!") - } else { - e.OK(nil, "密码修改成功") - } + + e.OK(nil, "密码修改成功") } // GetProfile diff --git a/common/middleware/handler/auth.go b/common/middleware/handler/auth.go index 222bd65d..910c3cda 100644 --- a/common/middleware/handler/auth.go +++ b/common/middleware/handler/auth.go @@ -1,7 +1,6 @@ package handler import ( - "fmt" "go-admin/app/admin/models" "go-admin/common" "net/http" @@ -16,8 +15,6 @@ import ( "github.com/go-admin-team/go-admin-core/sdk/pkg/jwtauth/user" "github.com/go-admin-team/go-admin-core/sdk/pkg/response" "github.com/mssola/user_agent" - gaConfig "go-admin/config" - "go-admin/common/global" ) @@ -119,8 +116,7 @@ func LoginLogToDB(c *gin.Context, status string, msg string, username string) { ua := user_agent.New(c.Request.UserAgent()) l["ipaddr"] = common.GetClientIP(c) - fmt.Println("gaConfig.ExtConfig.AMap.Key", gaConfig.ExtConfig.AMap.Key) - l["loginLocation"] = pkg.GetLocation(common.GetClientIP(c),gaConfig.ExtConfig.AMap.Key) + l["loginLocation"] = "" // pkg.GetLocation(common.GetClientIP(c),gaConfig.ExtConfig.AMap.Key) l["loginTime"] = pkg.GetCurrentTime() l["status"] = status l["remark"] = c.Request.UserAgent() diff --git a/common/middleware/init.go b/common/middleware/init.go index c82521ad..99026981 100644 --- a/common/middleware/init.go +++ b/common/middleware/init.go @@ -14,6 +14,7 @@ const ( ) func InitMiddleware(r *gin.Engine) { + r.Use(DemoEvn()) // 数据库链接 r.Use(WithContextDb) // 日志处理 @@ -26,10 +27,9 @@ func InitMiddleware(r *gin.Engine) { r.Use(Options) // Secure is a middleware function that appends security r.Use(Secure) - //r.Use(DemoEvn()) // 链路追踪 //r.Use(middleware.Trace()) sdk.Runtime.SetMiddleware(JwtTokenCheck, (*jwt.GinJWTMiddleware).MiddlewareFunc) sdk.Runtime.SetMiddleware(RoleCheck, AuthCheckRole()) sdk.Runtime.SetMiddleware(PermissionCheck, actions.PermissionAction()) -} \ No newline at end of file +} diff --git a/common/middleware/logger.go b/common/middleware/logger.go index fe2596a4..89c2c070 100644 --- a/common/middleware/logger.go +++ b/common/middleware/logger.go @@ -4,10 +4,8 @@ import ( "bufio" "bytes" "encoding/json" - "fmt" "go-admin/app/admin/service/dto" "go-admin/common" - gaConfig "go-admin/config" "io" "io/ioutil" "net/http" @@ -18,7 +16,6 @@ import ( "github.com/go-admin-team/go-admin-core/sdk" "github.com/go-admin-team/go-admin-core/sdk/api" "github.com/go-admin-team/go-admin-core/sdk/config" - "github.com/go-admin-team/go-admin-core/sdk/pkg" "github.com/go-admin-team/go-admin-core/sdk/pkg/jwtauth/user" "go-admin/common/global" @@ -109,8 +106,7 @@ func SetDBOperLog(c *gin.Context, clientIP string, statusCode int, reqUri string l["_fullPath"] = c.FullPath() l["operUrl"] = reqUri l["operIp"] = clientIP - fmt.Println("gaConfig.ExtConfig.AMap.Key", gaConfig.ExtConfig.AMap.Key) - l["operLocation"] = pkg.GetLocation(clientIP, gaConfig.ExtConfig.AMap.Key) + l["operLocation"] = "" // pkg.GetLocation(clientIP, gaConfig.ExtConfig.AMap.Key) l["operName"] = user.GetUserName(c) l["requestMethod"] = reqMethod l["operParam"] = body