mirror of
https://gitee.com/dromara/mayfly-go
synced 2026-02-21 11:45:36 +08:00
feat: 新增系统全局配置&修改账号密码
This commit is contained in:
@@ -23,6 +23,7 @@ type Account struct {
|
||||
ResourceApp application.Resource
|
||||
RoleApp application.Role
|
||||
MsgApp application.Msg
|
||||
ConfigApp application.Config
|
||||
}
|
||||
|
||||
/** 登录者个人相关操作 **/
|
||||
@@ -32,8 +33,11 @@ func (a *Account) Login(rc *ctx.ReqCtx) {
|
||||
loginForm := &form.LoginForm{}
|
||||
ginx.BindJsonAndValid(rc.GinCtx, loginForm)
|
||||
|
||||
// 校验验证码
|
||||
biz.IsTrue(captcha.Verify(loginForm.Cid, loginForm.Captcha), "验证码错误")
|
||||
// 判断是否有开启登录验证码校验
|
||||
if a.ConfigApp.GetConfig(entity.ConfigKeyUseLoginCaptcha).BoolValue(true) {
|
||||
// 校验验证码
|
||||
biz.IsTrue(captcha.Verify(loginForm.Cid, loginForm.Captcha), "验证码错误")
|
||||
}
|
||||
|
||||
originPwd, err := utils.DefaultRsaDecrypt(loginForm.Password, true)
|
||||
biz.ErrIsNilAppendErr(err, "解密密码错误: %s")
|
||||
@@ -145,17 +149,6 @@ func (a *Account) saveLogin(account *entity.Account, ip string) {
|
||||
loginMsg.Creator = account.Username
|
||||
loginMsg.CreatorId = account.Id
|
||||
a.MsgApp.Create(loginMsg)
|
||||
|
||||
// bodyMap, err := httpclient.NewRequest(fmt.Sprintf("http://ip-api.com/json/%s?lang=zh-CN", ip)).Get().BodyToMap()
|
||||
// if err != nil {
|
||||
// global.Log.Errorf("获取客户端ip地址信息失败:%s", err.Error())
|
||||
// return
|
||||
// }
|
||||
// if bodyMap["status"].(string) == "fail" {
|
||||
// return
|
||||
// }
|
||||
// msg := fmt.Sprintf("%s于%s-%s登录", account.Username, bodyMap["regionName"], bodyMap["city"])
|
||||
// global.Log.Info(msg)
|
||||
}
|
||||
|
||||
// 获取个人账号信息
|
||||
@@ -203,8 +196,8 @@ func (a *Account) Accounts(rc *ctx.ReqCtx) {
|
||||
rc.ResData = a.AccountApp.GetPageList(condition, ginx.GetPageParam(rc.GinCtx), new([]vo.AccountManageVO))
|
||||
}
|
||||
|
||||
// @router /accounts [get]
|
||||
func (a *Account) CreateAccount(rc *ctx.ReqCtx) {
|
||||
// @router /accounts
|
||||
func (a *Account) SaveAccount(rc *ctx.ReqCtx) {
|
||||
form := &form.AccountCreateForm{}
|
||||
ginx.BindJsonAndValid(rc.GinCtx, form)
|
||||
rc.ReqParam = form
|
||||
@@ -212,7 +205,16 @@ func (a *Account) CreateAccount(rc *ctx.ReqCtx) {
|
||||
account := &entity.Account{}
|
||||
utils.Copy(account, form)
|
||||
account.SetBaseInfo(rc.LoginAccount)
|
||||
a.AccountApp.Create(account)
|
||||
|
||||
if account.Id == 0 {
|
||||
a.AccountApp.Create(account)
|
||||
} else {
|
||||
if account.Password != "" {
|
||||
biz.IsTrue(CheckPasswordLever(account.Password), "密码强度必须8位以上且包含字⺟⼤⼩写+数字+特殊符号")
|
||||
account.Password = utils.PwdHash(account.Password)
|
||||
}
|
||||
a.AccountApp.Update(account)
|
||||
}
|
||||
}
|
||||
|
||||
func (a *Account) ChangeStatus(rc *ctx.ReqCtx) {
|
||||
|
||||
39
server/internal/sys/api/config.go
Normal file
39
server/internal/sys/api/config.go
Normal file
@@ -0,0 +1,39 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"mayfly-go/internal/sys/api/form"
|
||||
"mayfly-go/internal/sys/application"
|
||||
"mayfly-go/internal/sys/domain/entity"
|
||||
"mayfly-go/pkg/biz"
|
||||
"mayfly-go/pkg/ctx"
|
||||
"mayfly-go/pkg/ginx"
|
||||
"mayfly-go/pkg/utils"
|
||||
)
|
||||
|
||||
type Config struct {
|
||||
ConfigApp application.Config
|
||||
}
|
||||
|
||||
func (c *Config) Configs(rc *ctx.ReqCtx) {
|
||||
g := rc.GinCtx
|
||||
condition := &entity.Config{Key: g.Query("key")}
|
||||
rc.ResData = c.ConfigApp.GetPageList(condition, ginx.GetPageParam(g), new([]entity.Config))
|
||||
}
|
||||
|
||||
func (c *Config) GetConfigValueByKey(rc *ctx.ReqCtx) {
|
||||
key := rc.GinCtx.Query("key")
|
||||
biz.NotEmpty(key, "key不能为空")
|
||||
rc.ResData = c.ConfigApp.GetConfig(key).Value
|
||||
}
|
||||
|
||||
func (c *Config) SaveConfig(rc *ctx.ReqCtx) {
|
||||
g := rc.GinCtx
|
||||
form := &form.ConfigForm{}
|
||||
ginx.BindJsonAndValid(g, form)
|
||||
rc.ReqParam = form
|
||||
|
||||
config := new(entity.Config)
|
||||
utils.Copy(config, form)
|
||||
config.SetBaseInfo(rc.LoginAccount)
|
||||
c.ConfigApp.Save(config)
|
||||
}
|
||||
@@ -1,7 +1,9 @@
|
||||
package form
|
||||
|
||||
type AccountCreateForm struct {
|
||||
Id uint64
|
||||
Username *string `json:"username" binding:"required,min=4,max=16"`
|
||||
Password *string `json:"password"`
|
||||
}
|
||||
|
||||
type AccountUpdateForm struct {
|
||||
|
||||
9
server/internal/sys/api/form/config.go
Normal file
9
server/internal/sys/api/form/config.go
Normal file
@@ -0,0 +1,9 @@
|
||||
package form
|
||||
|
||||
type ConfigForm struct {
|
||||
Id int
|
||||
Name string `binding:"required"`
|
||||
Key string `binding:"required"`
|
||||
Value string
|
||||
Remark string `json:"remark"`
|
||||
}
|
||||
@@ -4,6 +4,6 @@ package form
|
||||
type LoginForm struct {
|
||||
Username string `json:"username" binding:"required"`
|
||||
Password string `binding:"required"`
|
||||
Captcha string `binding:"required"`
|
||||
Cid string `binding:"required"`
|
||||
Captcha string
|
||||
Cid string
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user