feat: 新增第三方登录认证和管理

This commit is contained in:
TsMask
2025-08-12 09:52:10 +08:00
parent d3f7c75ab4
commit c79786e1a1
50 changed files with 1678 additions and 157 deletions

View File

@@ -46,25 +46,31 @@ func LogOperate(options collectlogs.Options) func(http.Handler) http.Handler {
lastDotIndex := strings.LastIndex(funcName, "/")
funcName = funcName[lastDotIndex+1:]
// 用户名
username := ctx.LoginUserToUserName(r)
// 获取登录用户信息
loginUser, err := ctx.LoginUser(r)
if err != nil {
http.Error(w, "unauthorized", http.StatusUnauthorized)
return
}
// 解析ip地址
ip := strings.Split(r.RemoteAddr, ":")[0]
ipaddr := ip2region.ClientIP(ip)
location := ip2region.RealAddressByIp(ipaddr)
// 操作日志记录
operLog := model.SysLogOperate{
Title: options.Title,
BusinessType: options.BusinessType,
OperatorType: collectlogs.OPERATOR_TYPE_MANAGE,
OperatorType: loginUser.User.UserType,
Method: funcName,
OperURL: r.RequestURI,
RequestMethod: r.Method,
OperIP: ipaddr,
OperLocation: location,
OperName: username,
DeptName: "",
OperName: loginUser.User.UserName,
DeptName: loginUser.User.Dept.DeptName,
TenantName: loginUser.User.Tenant.TenantName,
TenantID: loginUser.User.Tenant.TenantID,
}
// 是否需要保存request参数和值
@@ -120,8 +126,15 @@ func LogOperate(options collectlogs.Options) func(http.Handler) http.Handler {
contentDisposition := w.Header().Get("Content-Disposition")
contentType := w.Header().Get("Content-Type")
content := contentType + contentDisposition
msg := fmt.Sprintf(`{"status":"%s","size":"%s","content-type":"%s"}`, status, size, content)
operLog.OperMsg = msg
msgByte, err := json.Marshal(map[string]any{
"status": status,
"size": size,
"content-type": content,
})
if err != nil {
operLog.OperMsg = ""
}
operLog.OperMsg = string(msgByte)
}
// 日志记录时间