You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
44 lines
1.3 KiB
44 lines
1.3 KiB
package routes |
|
|
|
import ( |
|
"gofaster/internal/auth/controller" |
|
"gofaster/internal/auth/service" |
|
"gofaster/internal/auth/repository" |
|
"gofaster/internal/shared/middleware" |
|
"gofaster/internal/shared/jwt" |
|
|
|
"github.com/gin-gonic/gin" |
|
"gorm.io/gorm" |
|
) |
|
|
|
// RegisterAuthRoutes 注册认证相关路由 |
|
func RegisterAuthRoutes(r *gin.RouterGroup, db *gorm.DB, jwtConfig middleware.JWTConfig) { |
|
// 创建仓储层实例 |
|
userRepo := repository.NewUserRepository(db) |
|
captchaRepo := repository.NewCaptchaRepository(db) |
|
|
|
// 创建JWT管理器 |
|
jwtManager := jwt.NewJWTManager(jwtConfig.SecretKey, jwtConfig.Issuer) |
|
|
|
// 创建服务层实例 |
|
authService := service.NewAuthService(userRepo, captchaRepo, jwtManager) |
|
|
|
// 创建控制器实例 |
|
authController := controller.NewAuthController(authService) |
|
|
|
// 认证路由组 |
|
auth := r.Group("/auth") |
|
{ |
|
// 公开接口(无需认证) |
|
auth.POST("/login", authController.Login) // 用户登录 |
|
auth.GET("/captcha", authController.GenerateCaptcha) // 生成验证码 |
|
|
|
// 需要认证的接口 |
|
auth.Use(middleware.JWTAuth(jwtConfig)) |
|
{ |
|
auth.POST("/logout", authController.Logout) // 用户登出 |
|
auth.POST("/refresh", authController.RefreshToken) // 刷新令牌 |
|
auth.GET("/userinfo", authController.GetUserInfo) // 获取用户信息 |
|
} |
|
} |
|
}
|
|
|