🐛 resolve interface validation issues
This commit is contained in:
@@ -8,6 +8,7 @@ import (
|
||||
"schisandra-cloud-album/common/result"
|
||||
"schisandra-cloud-album/global"
|
||||
"schisandra-cloud-album/utils"
|
||||
"time"
|
||||
)
|
||||
|
||||
// GenerateClientId 生成客户端ID
|
||||
@@ -29,10 +30,9 @@ func (ClientAPI) GenerateClientId(c *gin.Context) {
|
||||
result.OkWithData(clientId, c)
|
||||
return
|
||||
}
|
||||
|
||||
// 生成新的客户端ID
|
||||
v1 := uuid.NewV1()
|
||||
err := redis.Set(constant.UserLoginClientRedisKey+ip, v1.String(), 0).Err()
|
||||
err := redis.Set(constant.UserLoginClientRedisKey+ip, v1.String(), time.Hour*24*30).Err()
|
||||
if err != nil {
|
||||
global.LOG.Error(err)
|
||||
return
|
||||
|
@@ -125,9 +125,8 @@ func (OAuthAPI) GetTempQrCode(c *gin.Context) {
|
||||
result.FailWithMessage(ginI18n.MustGetMessage(c, "ParamsError"), c)
|
||||
return
|
||||
}
|
||||
|
||||
ip := utils.GetClientIP(c) // 使用工具函数获取客户端IP
|
||||
key := constant.UserLoginQrcodeRedisKey + ip + ":" + clientId
|
||||
key := constant.UserLoginQrcodeRedisKey + ip
|
||||
|
||||
// 从Redis获取二维码数据
|
||||
qrcode := redis.Get(key).Val()
|
||||
|
@@ -69,7 +69,7 @@ func (PermissionAPI) AssignPermissionsToRole(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
// GetUserPermissions 获取服用权限
|
||||
// GetUserPermissions 获取用户角色权限
|
||||
func (PermissionAPI) GetUserPermissions(c *gin.Context) {
|
||||
userId := c.Query("user_id")
|
||||
if userId == "" {
|
||||
@@ -78,6 +78,7 @@ func (PermissionAPI) GetUserPermissions(c *gin.Context) {
|
||||
}
|
||||
data, err := global.Casbin.GetImplicitRolesForUser(userId)
|
||||
if err != nil {
|
||||
result.FailWithMessage(ginI18n.MustGetMessage(c, "GetUserFailed"), c)
|
||||
return
|
||||
}
|
||||
result.OkWithData(data, c)
|
||||
|
@@ -498,3 +498,35 @@ func getUserLoginDevice(user model.ScaAuthUser, c *gin.Context) bool {
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
// Logout 退出登录
|
||||
// @Summary 退出登录
|
||||
// @Tags 用户模块
|
||||
// @Success 200 {string} json
|
||||
// @Router /api/auth/user/logout [post]
|
||||
func (UserAPI) Logout(c *gin.Context) {
|
||||
userId := c.Query("user_id")
|
||||
if userId == "" {
|
||||
global.LOG.Errorln("userId is empty")
|
||||
result.FailWithMessage(ginI18n.MustGetMessage(c, "ParamsError"), c)
|
||||
return
|
||||
}
|
||||
|
||||
tokenKey := constant.UserLoginTokenRedisKey + userId
|
||||
del := redis.Del(tokenKey)
|
||||
|
||||
if del.Err() != nil {
|
||||
global.LOG.Errorln(del.Err())
|
||||
result.FailWithMessage(ginI18n.MustGetMessage(c, "LogoutFailed"), c)
|
||||
return
|
||||
}
|
||||
ip := utils.GetClientIP(c)
|
||||
key := constant.UserLoginClientRedisKey + ip
|
||||
del = redis.Del(key)
|
||||
if del.Err() != nil {
|
||||
global.LOG.Errorln(del.Err())
|
||||
result.FailWithMessage(ginI18n.MustGetMessage(c, "LogoutFailed"), c)
|
||||
return
|
||||
}
|
||||
result.OkWithMessage(ginI18n.MustGetMessage(c, "LogoutSuccess"), c)
|
||||
}
|
||||
|
Reference in New Issue
Block a user