1
0

fix: 移除muxt验证码路由

This commit is contained in:
TsMask
2024-01-12 11:54:25 +08:00
parent 2118daa165
commit 3cec6077d3
2 changed files with 0 additions and 113 deletions

View File

@@ -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))
}

View File

@@ -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)