mirror of
https://gitee.com/dromara/mayfly-go
synced 2026-04-10 22:35:19 +08:00
feat: 新增系统操作日志&其他优化
This commit is contained in:
@@ -10,6 +10,7 @@ import (
|
||||
"mayfly-go/pkg/captcha"
|
||||
"mayfly-go/pkg/ctx"
|
||||
"mayfly-go/pkg/ginx"
|
||||
"mayfly-go/pkg/model"
|
||||
"mayfly-go/pkg/utils"
|
||||
"strconv"
|
||||
"strings"
|
||||
@@ -29,7 +30,6 @@ type Account struct {
|
||||
func (a *Account) Login(rc *ctx.ReqCtx) {
|
||||
loginForm := &form.LoginForm{}
|
||||
ginx.BindJsonAndValid(rc.GinCtx, loginForm)
|
||||
rc.ReqParam = loginForm.Username
|
||||
|
||||
// 校验验证码
|
||||
biz.IsTrue(captcha.Verify(loginForm.Cid, loginForm.Captcha), "验证码错误")
|
||||
@@ -54,8 +54,13 @@ func (a *Account) Login(rc *ctx.ReqCtx) {
|
||||
// 保存该账号的权限codes
|
||||
ctx.SavePermissionCodes(account.Id, permissions)
|
||||
|
||||
clientIp := rc.GinCtx.ClientIP()
|
||||
// 保存登录消息
|
||||
go a.saveLogin(account, rc.GinCtx.ClientIP())
|
||||
go a.saveLogin(account, clientIp)
|
||||
|
||||
rc.ReqParam = fmt.Sprintln("登录ip: ", clientIp)
|
||||
// 赋值loginAccount 主要用于记录操作日志,因为操作日志保存请求上下文没有该信息不保存日志
|
||||
rc.LoginAccount = &model.LoginAccount{Id: account.Id, Username: account.Username}
|
||||
|
||||
rc.ResData = map[string]interface{}{
|
||||
"token": ctx.CreateToken(account.Id, account.Username),
|
||||
|
||||
@@ -29,6 +29,7 @@ func (r *Role) SaveRole(rc *ctx.ReqCtx) {
|
||||
g := rc.GinCtx
|
||||
form := &form.RoleForm{}
|
||||
ginx.BindJsonAndValid(g, form)
|
||||
rc.ReqParam = form
|
||||
|
||||
role := new(entity.Role)
|
||||
utils.Copy(role, form)
|
||||
|
||||
21
server/internal/sys/api/syslog.go
Normal file
21
server/internal/sys/api/syslog.go
Normal file
@@ -0,0 +1,21 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"mayfly-go/internal/sys/application"
|
||||
"mayfly-go/internal/sys/domain/entity"
|
||||
"mayfly-go/pkg/ctx"
|
||||
"mayfly-go/pkg/ginx"
|
||||
)
|
||||
|
||||
type Syslog struct {
|
||||
SyslogApp application.Syslog
|
||||
}
|
||||
|
||||
func (r *Syslog) Syslogs(rc *ctx.ReqCtx) {
|
||||
g := rc.GinCtx
|
||||
condition := &entity.Syslog{
|
||||
Type: int8(ginx.QueryInt(g, "type", 0)),
|
||||
CreatorId: uint64(ginx.QueryInt(g, "creatorId", 0)),
|
||||
}
|
||||
rc.ResData = r.SyslogApp.GetPageList(condition, ginx.GetPageParam(g), new([]entity.Syslog), "create_time DESC")
|
||||
}
|
||||
Reference in New Issue
Block a user