feat: Implement Oauth2 login log service and repository

- Added Oauth2LogLoginService for managing user authorization logs.
- Implemented methods for inserting logs, cleaning logs, and exporting log data.
- Created a new file for Oauth2 login log service.

refactor: Remove unused open_api module

- Deleted the open_api.go file as it was not utilized in the project.

fix: Update error codes in SysProfileController

- Changed error codes for binding errors and user authentication errors to more descriptive values.

fix: Update cache handling in SysConfig and SysDictType services

- Modified Redis set operations to include expiration time for cached values.

refactor: Update middleware authorization checks

- Replaced PreAuthorize middleware with AuthorizeUser across multiple routes in system and tool modules for consistency.

chore: Clean up trace and ws modules

- Updated middleware authorization in trace and ws modules to use AuthorizeUser.
This commit is contained in:
TsMask
2025-04-27 11:07:34 +08:00
parent b29a36e7b5
commit 56991a0b49
72 changed files with 2334 additions and 873 deletions

View File

@@ -1,8 +1,6 @@
package controller
import (
"strings"
"be.ems/src/framework/constants"
"be.ems/src/framework/i18n"
"be.ems/src/framework/reqctx"
@@ -52,7 +50,7 @@ func (s *BootloaderController) Start(c *gin.Context) {
}
// 登录用户信息
loginUser := token.TokenInfo{
info := token.UserInfo{
UserId: sysUser.UserId,
DeptId: sysUser.DeptId,
User: sysUser,
@@ -60,23 +58,24 @@ func (s *BootloaderController) Start(c *gin.Context) {
}
// 当前请求信息
ipaddr, location := reqctx.IPAddrLocation(c)
os, browser := reqctx.UaOsBrowser(c)
deviceFingerprint := reqctx.DeviceFingerprint(c, info.UserId)
// 生成令牌,创建系统访问记录
tokenStr := token.Create(&loginUser, [4]string{ipaddr, location, os, browser})
if tokenStr == "" {
c.JSON(200, resp.Err(nil))
// 生成访问令牌
accessToken, expiresIn := token.UserTokenCreate(info.UserId, deviceFingerprint, "access")
if accessToken == "" || expiresIn == 0 {
c.JSON(200, resp.ErrMsg("token generation failed"))
return
} else {
s.accountService.UpdateLoginDateAndIP(loginUser)
}
// 创建系统访问记录
s.accountService.UpdateLoginDateAndIP(info)
c.JSON(200, resp.OkData(map[string]any{
"accessToken": tokenStr,
"tokenType": strings.TrimRight(constants.HEADER_PREFIX, " "),
"expiresIn": (loginUser.ExpireTime - loginUser.LoginTime) / 1000,
"userId": loginUser.UserId,
"tokenType": constants.HEADER_PREFIX,
"accessToken": accessToken,
"expiresIn": expiresIn,
"refreshToken": "",
"refreshExpiresIn": 0,
"userId": info.UserId,
}))
}
@@ -102,7 +101,7 @@ func (s *BootloaderController) Done(c *gin.Context) {
}
// 清除授权信息
token.Remove(reqctx.Authorization(c))
token.UserInfoRemove(reqctx.Authorization(c))
c.JSON(200, resp.Ok(nil))
}
@@ -127,7 +126,7 @@ func (s *BootloaderController) Reset(c *gin.Context) {
}
// 清除授权信息
token.Remove(reqctx.Authorization(c))
token.UserInfoRemove(reqctx.Authorization(c))
c.JSON(200, resp.Ok(nil))
}