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:
@@ -12,12 +12,12 @@ import (
|
||||
)
|
||||
|
||||
// LoginUser 登录用户信息
|
||||
func LoginUser(c *gin.Context) (token.TokenInfo, error) {
|
||||
func LoginUser(c *gin.Context) (token.UserInfo, error) {
|
||||
value, exists := c.Get(constants.CTX_LOGIN_USER)
|
||||
if exists && value != nil {
|
||||
return value.(token.TokenInfo), nil
|
||||
return value.(token.UserInfo), nil
|
||||
}
|
||||
return token.TokenInfo{}, fmt.Errorf("invalid login user information")
|
||||
return token.UserInfo{}, fmt.Errorf("invalid login user information")
|
||||
}
|
||||
|
||||
// LoginUserToUserID 登录用户信息-用户ID
|
||||
@@ -58,14 +58,14 @@ func LoginUserByContainRoles(c *gin.Context, target string) bool {
|
||||
|
||||
// LoginUserByContainPerms 登录用户信息-包含权限标识
|
||||
func LoginUserByContainPerms(c *gin.Context, target string) bool {
|
||||
loginUser, err := LoginUser(c)
|
||||
info, err := LoginUser(c)
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
if config.IsSystemUser(loginUser.UserId) {
|
||||
if config.IsSystemUser(info.UserId) {
|
||||
return true
|
||||
}
|
||||
perms := loginUser.Permissions
|
||||
perms := info.Permissions
|
||||
for _, str := range perms {
|
||||
if str == target {
|
||||
return true
|
||||
|
||||
@@ -73,11 +73,11 @@ func Authorization(c *gin.Context) string {
|
||||
return ""
|
||||
}
|
||||
// 拆分 Authorization 请求头,提取 JWT 令牌部分
|
||||
arr := strings.SplitN(authHeader, constants.HEADER_PREFIX, 2)
|
||||
if len(arr) < 2 {
|
||||
return ""
|
||||
tokenStr := strings.Replace(authHeader, constants.HEADER_PREFIX, "", 1)
|
||||
if len(tokenStr) > 64 {
|
||||
return strings.TrimSpace(tokenStr) // 去除可能存在的空格
|
||||
}
|
||||
return arr[1]
|
||||
return ""
|
||||
}
|
||||
|
||||
// AcceptLanguage 解析客户端接收语言 zh:中文 en: 英文
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
package reqctx
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
|
||||
"be.ems/src/framework/ip2region"
|
||||
"be.ems/src/framework/utils/crypto"
|
||||
"be.ems/src/framework/utils/ua"
|
||||
)
|
||||
|
||||
@@ -33,3 +36,9 @@ func UaOsBrowser(c *gin.Context) (string, string) {
|
||||
}
|
||||
return os, browser
|
||||
}
|
||||
|
||||
// DeviceFingerprint 设备指纹信息
|
||||
func DeviceFingerprint(c *gin.Context, v any) string {
|
||||
str := fmt.Sprintf("%v:%s", v, c.Request.UserAgent())
|
||||
return crypto.SHA256ToBase64(str)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user