- 删除注册、登录、找回密码、游客登录接口及密码、token 相关代码 - 鉴权中间件不再校验 token,按 X-User-Agent 中的 devID 识别用户,首次访问自动创建,Redis 缓存 10 分钟 - 渠道码改从请求头 channel 读取;修改资料不再支持改密码 - 同步更新 swagger 文档 Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
46 lines
1.2 KiB
Go
46 lines
1.2 KiB
Go
package auth
|
|
|
|
import (
|
|
"net/http"
|
|
"strings"
|
|
"videoweb/app/middleware/reptilerecord"
|
|
"videoweb/app/service/authser"
|
|
"videoweb/pub/common"
|
|
"videoweb/pub/common/enum/consts"
|
|
"videoweb/pub/common/ipaddr"
|
|
"videoweb/pub/common/log"
|
|
"videoweb/pub/common/srvdef"
|
|
"videoweb/pub/pubdef"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
// gin 用户识别中间件:不再校验 token,按 X-User-Agent 中的 devID 识别用户,
|
|
// 该设备首次访问时自动创建用户。没有 devID 的请求按匿名处理,
|
|
// 需要用户身份的接口自行返回"请先登录"。
|
|
func Auth(ctx *gin.Context) {
|
|
if reptilerecord.IsBot(ctx) {
|
|
ctx.Set(consts.CtxUserID, pubdef.CrawlerUserId)
|
|
return
|
|
}
|
|
|
|
ua, err := common.GetUA(ctx)
|
|
if err != nil || strings.TrimSpace(ua.DevID) == "" {
|
|
return
|
|
}
|
|
|
|
userId, serr := authser.ResolveDeviceUser(ctx, ua, ipaddr.ResolveClientIP(ctx), ctx.GetHeader("channel"))
|
|
if serr != nil {
|
|
if serr.Code == srvdef.AccountErrAccessForbid {
|
|
ctx.AbortWithStatusJSON(http.StatusOK, gin.H{
|
|
"code": serr.Code,
|
|
"msg": serr.Code.Msg(),
|
|
})
|
|
return
|
|
}
|
|
log.Error("Auth:ResolveDeviceUser", log.Any("devID", ua.DevID), log.Any("path", ctx.Request.URL.Path), log.E(serr))
|
|
return
|
|
}
|
|
ctx.Set(consts.CtxUserID, userId)
|
|
}
|