mirror of
https://github.com/Rain-kl/OpenFlare.git
synced 2026-10-02 14:56:38 +08:00
[优化] POW 系统接口方案
This commit is contained in:
@@ -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)
|
||||
}
|
||||
@@ -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,
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user