feat(auth): 添加用户认证中间件并重构Linux.do登录流程

- 新增UserAuth中间件用于验证用户登录状态和权限
- 移除Linux.do登录中的redirectUri和minimumTrustLevel配置项
- 修改Linux.do登录流程以支持动态构建回调URL
- 将API v1接口组迁移至需要用户认证的路由
- 在远程AI服务调用中添加用户令牌认证
- 修复被封禁用户的认证检查逻辑
- 更新登录重定向函数以处理请求来源
- 添加RequestOrigin函数解析转发的主机和协议头
This commit is contained in:
HouYunFei
2026-05-25 12:05:02 +08:00
parent b2cae2471d
commit fe3294ed60
13 changed files with 72 additions and 67 deletions
+11
View File
@@ -21,6 +21,17 @@ func AdminAuth(c *gin.Context) {
c.Next()
}
func UserAuth(c *gin.Context) {
user, ok := authUser(c)
if !ok || user.Role == model.UserRoleGuest {
handler.Fail(c.Writer, "未登录或权限不足")
c.Abort()
return
}
c.Request = c.Request.WithContext(service.WithUser(c.Request.Context(), user))
c.Next()
}
func OptionalAuth(c *gin.Context) {
if user, ok := authUser(c); ok {
c.Request = c.Request.WithContext(service.WithUser(c.Request.Context(), user))