From 3cec6077d335262f3165ded11e0ce4937acea6f4 Mon Sep 17 00:00:00 2001 From: TsMask <340112800@qq.com> Date: Fri, 12 Jan 2024 11:54:25 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E7=A7=BB=E9=99=A4muxt=E9=AA=8C=E8=AF=81?= =?UTF-8?q?=E7=A0=81=E8=B7=AF=E7=94=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- features/security/account.go | 101 ----------------------------------- lib/routes/routes.go | 12 ----- 2 files changed, 113 deletions(-) diff --git a/features/security/account.go b/features/security/account.go index 0e593d8..699c280 100644 --- a/features/security/account.go +++ b/features/security/account.go @@ -3,7 +3,6 @@ package security import ( "encoding/json" "fmt" - "image/color" "io" "net/http" "strconv" @@ -25,7 +24,6 @@ import ( "ems.agt/restagent/config" srcConfig "ems.agt/src/framework/config" "ems.agt/src/framework/redis" - "github.com/mojocn/base64Captcha" ) var ( @@ -310,102 +308,3 @@ func LoginOMC(w http.ResponseWriter, r *http.Request) { } ctx.JSON(w, 200, result.Err(nil)) } - -// 获取验证码 -// -// GET /captchaImage -func CaptchaImage(w http.ResponseWriter, r *http.Request) { - configService := sysConfigService.NewServiceSysConfig - - // 从数据库配置获取验证码开关 true开启,false关闭 - captchaEnabledStr := configService.SelectConfigValueByKey("sys.account.captchaEnabled") - captchaEnabled, err := strconv.ParseBool(captchaEnabledStr) - if err != nil { - captchaEnabled = false - } - if !captchaEnabled { - ctx.JSON(w, 200, result.Ok(map[string]any{ - "captchaEnabled": captchaEnabled, - })) - return - } - - // 生成唯一标识 - verifyKey := "" - data := map[string]any{ - "captchaEnabled": captchaEnabled, - "uuid": "", - "img": "data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7", - } - - // char 字符验证 - driverCaptcha := &base64Captcha.DriverString{ - //Height png height in pixel. - Height: 40, - // Width Captcha png width in pixel. - Width: 120, - //NoiseCount text noise count. - NoiseCount: 4, - //Length random string length. - Length: 4, - //Source is a unicode which is the rand string from. - Source: "023456789abcdefghjkmnprstuvwxyz", - //ShowLineOptions := OptionShowHollowLine | OptionShowSlimeLine | OptionShowSineLine . - ShowLineOptions: base64Captcha.OptionShowHollowLine, - //BgColor captcha image background color (optional) - BgColor: &color.RGBA{ - R: 250, - G: 250, - B: 250, - A: 255, // 不透明 - }, - } - // 验证码生成 - id, question, answer := driverCaptcha.GenerateIdQuestionAnswer() - // 验证码表达式解析输出 - item, err := driverCaptcha.DrawCaptcha(question) - if err != nil { - log.Infof("Generate Id Question Answer %s : %v", question, err) - } else { - data["uuid"] = id - data["img"] = item.EncodeB64string() - verifyKey = cachekey.CAPTCHA_CODE_KEY + id - cache.SetLocalTTL(verifyKey, answer, 120*time.Second) - } - - // 本地开发下返回验证码结果,方便接口调试 - // text, ok := cache.GetLocalTTL(verifyKey) - // if ok { - // data["text"] = text.(string) - // } - - ctx.JSON(w, 200, result.Ok(data)) -} - -// 登录用户信息 -func UserInfo(w http.ResponseWriter, r *http.Request) { - loginUser, err := ctx.LoginUser(r) - if err != nil { - ctx.JSON(w, 200, result.OkData(err.Error())) - } - // 角色权限集合,管理员拥有所有权限 - userId := fmt.Sprint(loginUser.UserID) - isAdmin := srcConfig.IsAdmin(userId) - roles, perms := service.NewServiceAccount.RoleAndMenuPerms(userId, isAdmin) - - ctx.JSON(w, 200, result.OkData(map[string]any{ - "user": loginUser.User, - "roles": roles, - "permissions": perms, - })) -} - -// 登录用户路由信息 -func Routers(w http.ResponseWriter, r *http.Request) { - userID := ctx.LoginUserToUserID(r) - - // 前端路由,管理员拥有所有 - isAdmin := srcConfig.IsAdmin(userID) - buildMenus := service.NewServiceAccount.RouteMenus(userID, isAdmin) - ctx.JSON(w, 200, result.OkData(buildMenus)) -} diff --git a/lib/routes/routes.go b/lib/routes/routes.go index ae10e59..fd5e9fb 100644 --- a/lib/routes/routes.go +++ b/lib/routes/routes.go @@ -330,18 +330,6 @@ func init() { Register("POST", security.UriLogin, security.LoginOMC, nil) Register("POST", security.CustomUriLogin, security.LoginOMC, nil) - // 获取验证码 - Register("GET", security.UriCaptchaImage, security.CaptchaImage, nil) - Register("GET", security.CustomUriCaptchaImage, security.CaptchaImage, nil) - - // 登录用户信息 - Register("GET", security.UriUserInfo, security.UserInfo, midware.Authorize(nil)) - Register("GET", security.CustomUriUserInfo, security.UserInfo, midware.Authorize(nil)) - - // 登录用户路由信息 - Register("GET", security.UriRouters, security.Routers, midware.Authorize(nil)) - Register("GET", security.CustomUriRouters, security.Routers, midware.Authorize(nil)) - // 参数配置信息接口添加到路由 for _, v := range sysconfig.Routers() { Register(v.Method, v.Pattern, v.Handler, v.Middleware)