fix🐛: Adjust the demo environment configuration

This commit is contained in:
zhangwenjian
2022-11-09 17:35:16 +08:00
parent 42f3025217
commit ddd97d5a9e
4 changed files with 7 additions and 30 deletions
+3 -18
View File
@@ -2,7 +2,6 @@ package apis
import ( import (
"github.com/gin-gonic/gin/binding" "github.com/gin-gonic/gin/binding"
"github.com/go-admin-team/go-admin-core/sdk/config"
"go-admin/app/admin/models" "go-admin/app/admin/models"
"golang.org/x/crypto/bcrypt" "golang.org/x/crypto/bcrypt"
"net/http" "net/http"
@@ -313,19 +312,12 @@ func (e SysUser) ResetPwd(c *gin.Context) {
//数据权限检查 //数据权限检查
p := actions.GetPermissionFromContext(c) p := actions.GetPermissionFromContext(c)
if req.UserId == 1 && config.ApplicationConfig.Mode == "demo" {
req.Password = "123456"
}
err = s.ResetPwd(&req, p) err = s.ResetPwd(&req, p)
if err != nil { if err != nil {
e.Logger.Error(err) e.Logger.Error(err)
return return
} }
if req.UserId == 1 && config.ApplicationConfig.Mode == "demo" { e.OK(req.GetId(), "更新成功")
e.OK(req.GetId(), "admin:现在使用的预览环境,休想改掉我!否则会影响其他朋友体验的哦!可以创建其他用户体验该功能!")
} else {
e.OK(req.GetId(), "更新成功")
}
} }
// UpdatePwd // UpdatePwd
@@ -354,10 +346,6 @@ func (e SysUser) UpdatePwd(c *gin.Context) {
// 数据权限检查 // 数据权限检查
p := actions.GetPermissionFromContext(c) p := actions.GetPermissionFromContext(c)
if user.GetUserId(c) == 1 && config.ApplicationConfig.Mode == "demo" {
req.NewPassword = "123456"
}
var hash []byte var hash []byte
if hash, err = bcrypt.GenerateFromPassword([]byte(req.NewPassword), bcrypt.DefaultCost); err != nil { if hash, err = bcrypt.GenerateFromPassword([]byte(req.NewPassword), bcrypt.DefaultCost); err != nil {
req.NewPassword = string(hash) req.NewPassword = string(hash)
@@ -369,11 +357,8 @@ func (e SysUser) UpdatePwd(c *gin.Context) {
e.Error(http.StatusForbidden, err, "密码修改失败") e.Error(http.StatusForbidden, err, "密码修改失败")
return return
} }
if user.GetUserId(c) == 1 && config.ApplicationConfig.Mode == "demo" {
e.OK(nil, "admin:现在使用的预览环境,休想改掉我!否则会影响其他朋友体验的哦!可以创建其他用户体验该功能!") e.OK(nil, "密码修改成功")
} else {
e.OK(nil, "密码修改成功")
}
} }
// GetProfile // GetProfile
+1 -5
View File
@@ -1,7 +1,6 @@
package handler package handler
import ( import (
"fmt"
"go-admin/app/admin/models" "go-admin/app/admin/models"
"go-admin/common" "go-admin/common"
"net/http" "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/jwtauth/user"
"github.com/go-admin-team/go-admin-core/sdk/pkg/response" "github.com/go-admin-team/go-admin-core/sdk/pkg/response"
"github.com/mssola/user_agent" "github.com/mssola/user_agent"
gaConfig "go-admin/config"
"go-admin/common/global" "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()) ua := user_agent.New(c.Request.UserAgent())
l["ipaddr"] = common.GetClientIP(c) 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["loginTime"] = pkg.GetCurrentTime()
l["status"] = status l["status"] = status
l["remark"] = c.Request.UserAgent() l["remark"] = c.Request.UserAgent()
+2 -2
View File
@@ -14,6 +14,7 @@ const (
) )
func InitMiddleware(r *gin.Engine) { func InitMiddleware(r *gin.Engine) {
r.Use(DemoEvn())
// 数据库链接 // 数据库链接
r.Use(WithContextDb) r.Use(WithContextDb)
// 日志处理 // 日志处理
@@ -26,10 +27,9 @@ func InitMiddleware(r *gin.Engine) {
r.Use(Options) r.Use(Options)
// Secure is a middleware function that appends security // Secure is a middleware function that appends security
r.Use(Secure) r.Use(Secure)
//r.Use(DemoEvn())
// 链路追踪 // 链路追踪
//r.Use(middleware.Trace()) //r.Use(middleware.Trace())
sdk.Runtime.SetMiddleware(JwtTokenCheck, (*jwt.GinJWTMiddleware).MiddlewareFunc) sdk.Runtime.SetMiddleware(JwtTokenCheck, (*jwt.GinJWTMiddleware).MiddlewareFunc)
sdk.Runtime.SetMiddleware(RoleCheck, AuthCheckRole()) sdk.Runtime.SetMiddleware(RoleCheck, AuthCheckRole())
sdk.Runtime.SetMiddleware(PermissionCheck, actions.PermissionAction()) sdk.Runtime.SetMiddleware(PermissionCheck, actions.PermissionAction())
} }
+1 -5
View File
@@ -4,10 +4,8 @@ import (
"bufio" "bufio"
"bytes" "bytes"
"encoding/json" "encoding/json"
"fmt"
"go-admin/app/admin/service/dto" "go-admin/app/admin/service/dto"
"go-admin/common" "go-admin/common"
gaConfig "go-admin/config"
"io" "io"
"io/ioutil" "io/ioutil"
"net/http" "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"
"github.com/go-admin-team/go-admin-core/sdk/api" "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/config"
"github.com/go-admin-team/go-admin-core/sdk/pkg"
"github.com/go-admin-team/go-admin-core/sdk/pkg/jwtauth/user" "github.com/go-admin-team/go-admin-core/sdk/pkg/jwtauth/user"
"go-admin/common/global" "go-admin/common/global"
@@ -109,8 +106,7 @@ func SetDBOperLog(c *gin.Context, clientIP string, statusCode int, reqUri string
l["_fullPath"] = c.FullPath() l["_fullPath"] = c.FullPath()
l["operUrl"] = reqUri l["operUrl"] = reqUri
l["operIp"] = clientIP 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["operName"] = user.GetUserName(c)
l["requestMethod"] = reqMethod l["requestMethod"] = reqMethod
l["operParam"] = body l["operParam"] = body