mirror of
https://github.com/Rain-kl/OpenFlare.git
synced 2026-10-11 09:46:37 +08:00
migrate
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
// Copyright 2026 Arctel.net
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package legacy
|
||||
|
||||
import (
|
||||
ofauth "github.com/Rain-kl/Wavelet/internal/apps/openflare/auth"
|
||||
"github.com/Rain-kl/Wavelet/internal/apps/openflare/compat"
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
// GitHubOAuth handles GET /oauth/github for legacy GitHub login or bind.
|
||||
func GitHubOAuth(c *gin.Context) {
|
||||
user, err := ofauth.GitHubOAuth(c.Request.Context(), c, c.Query("code"))
|
||||
if err != nil {
|
||||
compat.Fail(c, err.Error())
|
||||
return
|
||||
}
|
||||
if user.ID == 0 {
|
||||
compat.OKMessage(c, "bind")
|
||||
return
|
||||
}
|
||||
compat.OK(c, user)
|
||||
}
|
||||
|
||||
// WeChatOAuth handles GET /oauth/wechat for legacy WeChat login.
|
||||
func WeChatOAuth(c *gin.Context) {
|
||||
user, err := ofauth.WeChatOAuth(c.Request.Context(), c, c.Query("code"))
|
||||
if err != nil {
|
||||
compat.Fail(c, err.Error())
|
||||
return
|
||||
}
|
||||
compat.OK(c, user)
|
||||
}
|
||||
|
||||
// WeChatBind handles GET /oauth/wechat/bind for legacy WeChat account binding.
|
||||
func WeChatBind(c *gin.Context) {
|
||||
if err := ofauth.WeChatBind(c.Request.Context(), callerUserID(c), c.Query("code")); err != nil {
|
||||
compat.Fail(c, err.Error())
|
||||
return
|
||||
}
|
||||
compat.OKMessage(c, "")
|
||||
}
|
||||
|
||||
// EmailBind handles GET /oauth/email/bind for legacy email binding.
|
||||
func EmailBind(c *gin.Context) {
|
||||
if err := ofauth.EmailBind(c.Request.Context(), callerUserID(c), c.Query("email"), c.Query("code")); err != nil {
|
||||
compat.Fail(c, err.Error())
|
||||
return
|
||||
}
|
||||
compat.OKMessage(c, "")
|
||||
}
|
||||
@@ -9,11 +9,6 @@ import (
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
// bridgeOpenFlareToken maps OpenFlare-Token to X-Access-Token for compat auth middleware.
|
||||
func bridgeOpenFlareToken() gin.HandlerFunc {
|
||||
return compat.BridgeOpenFlareToken()
|
||||
}
|
||||
|
||||
// legacyCapAuth verifies PoW CAPTCHA for legacy login using OpenFlare response format.
|
||||
func legacyCapAuth(scope string) gin.HandlerFunc {
|
||||
mgr := cap.GetDefaultManager()
|
||||
|
||||
@@ -4,10 +4,14 @@
|
||||
// Package legacy registers OpenFlare /api/* compatibility routes for the old frontend.
|
||||
package legacy
|
||||
|
||||
import "github.com/gin-gonic/gin"
|
||||
import (
|
||||
"github.com/Rain-kl/Wavelet/internal/apps/openflare/compat"
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
// RegisterRoutes mounts all OpenFlare legacy API routes under the /api group.
|
||||
func RegisterRoutes(apiGroup *gin.RouterGroup) {
|
||||
apiGroup.Use(compat.BridgeOpenFlareToken())
|
||||
registerAuthRoutes(apiGroup)
|
||||
registerOptionRoutes(apiGroup)
|
||||
registerOriginRoutes(apiGroup)
|
||||
|
||||
@@ -16,12 +16,16 @@ func registerAuthRoutes(apiGroup *gin.RouterGroup) {
|
||||
|
||||
oauthGroup := apiGroup.Group("/oauth")
|
||||
{
|
||||
oauthGroup.GET("/github", GitHubOAuth)
|
||||
oauthGroup.GET("/wechat", WeChatOAuth)
|
||||
oauthGroup.GET("/wechat/bind", compat.BridgeOpenFlareToken(), compat.UserAuth(), WeChatBind)
|
||||
oauthGroup.GET("/email/bind", compat.BridgeOpenFlareToken(), compat.UserAuth(), EmailBind)
|
||||
oauthGroup.GET("/:source/authorize", OAuthAuthorize)
|
||||
oauthGroup.GET("/:source/callback", OAuthCallback)
|
||||
oauthGroup.POST("/link-existing", LinkExistingOAuthAccount)
|
||||
|
||||
externalAccounts := oauthGroup.Group("/external-accounts")
|
||||
externalAccounts.Use(bridgeOpenFlareToken(), compat.UserAuth())
|
||||
externalAccounts.Use(compat.UserAuth())
|
||||
{
|
||||
externalAccounts.GET("/", ListExternalAccounts)
|
||||
externalAccounts.POST("/:id/delete", DeleteExternalAccount)
|
||||
@@ -41,7 +45,7 @@ func registerAuthRoutes(apiGroup *gin.RouterGroup) {
|
||||
userGroup.GET("/logout", Logout)
|
||||
|
||||
selfGroup := userGroup.Group("/")
|
||||
selfGroup.Use(bridgeOpenFlareToken(), compat.UserAuth())
|
||||
selfGroup.Use(compat.UserAuth())
|
||||
{
|
||||
selfGroup.GET("/self", GetSelf)
|
||||
selfGroup.POST("/self/update", UpdateSelf)
|
||||
@@ -50,7 +54,7 @@ func registerAuthRoutes(apiGroup *gin.RouterGroup) {
|
||||
}
|
||||
|
||||
adminGroup := userGroup.Group("/")
|
||||
adminGroup.Use(bridgeOpenFlareToken(), compat.AdminAuth())
|
||||
adminGroup.Use(compat.AdminAuth())
|
||||
{
|
||||
adminGroup.GET("/", GetAllUsers)
|
||||
adminGroup.GET("/search", SearchUsers)
|
||||
@@ -63,7 +67,7 @@ func registerAuthRoutes(apiGroup *gin.RouterGroup) {
|
||||
}
|
||||
|
||||
authSourceGroup := apiGroup.Group("/auth-sources")
|
||||
authSourceGroup.Use(bridgeOpenFlareToken(), compat.RootAuth())
|
||||
authSourceGroup.Use(compat.RootAuth())
|
||||
{
|
||||
authSourceGroup.GET("/", ListAuthSources)
|
||||
authSourceGroup.POST("/", CreateAuthSource)
|
||||
|
||||
Reference in New Issue
Block a user