[优化] POW 系统接口方案

This commit is contained in:
ryan
2026-06-06 12:13:55 +08:00
parent 4be7c19798
commit 6bf5023af1
20 changed files with 896 additions and 36 deletions
+45
View File
@@ -0,0 +1,45 @@
package controller
import (
"net/http"
"github.com/gin-gonic/gin"
"github.com/rain-kl/openflare/openflare-server/controller/bind"
"github.com/rain-kl/openflare/openflare-server/service"
"github.com/rain-kl/openflare/openflare-server/utils/cap"
)
// GetCapChallenge generates a new CAPTCHA challenge
func GetCapChallenge(c *gin.Context) {
scope := c.Query("scope")
resp, err := service.CapManager.Generate(scope)
if err != nil {
c.JSON(http.StatusInternalServerError, gin.H{
"success": false,
"error": err.Error(),
})
return
}
c.JSON(http.StatusOK, resp)
}
// RedeemCapChallenge validates CAPTCHA solutions and yields a one-time redeem token
func RedeemCapChallenge(c *gin.Context) {
scope := c.Query("scope")
var req cap.RedeemRequest
if !bind.JSON(c, &req) {
return
}
resp, err := service.CapManager.Redeem(c.Request.Context(), req.Token, req.Solutions, scope)
if err != nil {
c.JSON(http.StatusInternalServerError, gin.H{
"success": false,
"error": err.Error(),
})
return
}
c.JSON(http.StatusOK, resp)
}
+1
View File
@@ -39,6 +39,7 @@ func GetStatus(c *gin.Context) {
"wechat_login": common.WeChatAuthEnabled,
"server_address": common.ServerAddress,
"password_register_enabled": common.PasswordRegisterEnabled,
"cap_login_enabled": common.CapLoginEnabled,
"auth_sources": authSources,
})
}