修复验证码为空时不应出现的框

当没有设置私钥时自动生成
This commit is contained in:
xmdhs 2023-10-11 21:02:16 +08:00
parent cad8e6e317
commit 47493b99fd
No known key found for this signature in database
GPG Key ID: E809D6D43DEFCC95
3 changed files with 16 additions and 2 deletions

View File

@ -50,7 +50,7 @@ textureBaseUrl: ""
webBaseUrl: "" webBaseUrl: ""
# 皮肤站名字,用于在多个地方展示 # 皮肤站名字,用于在多个地方展示
serverName: "" serverName: "没有设置名字"
captcha: captcha:
# 验证码类型,目前只支持 cloudflare turnstile # 验证码类型,目前只支持 cloudflare turnstile

View File

@ -2,6 +2,8 @@ package main
import ( import (
"context" "context"
"crypto/rand"
"crypto/rsa"
"errors" "errors"
"flag" "flag"
"fmt" "fmt"
@ -12,6 +14,7 @@ import (
"github.com/samber/lo" "github.com/samber/lo"
"github.com/xmdhs/authlib-skin/config" "github.com/xmdhs/authlib-skin/config"
"github.com/xmdhs/authlib-skin/server" "github.com/xmdhs/authlib-skin/server"
"github.com/xmdhs/authlib-skin/utils/sign"
) )
var configPath string var configPath string
@ -29,7 +32,7 @@ func main() {
b, err := os.ReadFile(configPath) b, err := os.ReadFile(configPath)
if err != nil { if err != nil {
if errors.Is(err, os.ErrNotExist) { if errors.Is(err, os.ErrNotExist) {
lo.Must0(os.WriteFile("config.yaml", configTempLate, 0600)) lo.Must0(os.WriteFile(configPath, configTempLate, 0600))
fmt.Println("未找到配置文件,已写入模板配置文件") fmt.Println("未找到配置文件,已写入模板配置文件")
return return
} }
@ -37,6 +40,13 @@ func main() {
} }
config := lo.Must(config.YamlDeCode(b)) config := lo.Must(config.YamlDeCode(b))
if config.RsaPriKey == "" {
rsa2048 := lo.Must(rsa.GenerateKey(rand.Reader, 4096))
as := sign.NewAuthlibSignWithKey(rsa2048)
config.RsaPriKey = lo.Must(as.GetPriKey())
lo.Must0(os.WriteFile(configPath, []byte(config.RsaPriKey), 0600))
}
s, cancel := lo.Must2(server.InitializeRoute(ctx, config)) s, cancel := lo.Must2(server.InitializeRoute(ctx, config))
defer cancel() defer cancel()
panic(s.ListenAndServe()) panic(s.ListenAndServe())

View File

@ -48,6 +48,10 @@ const CaptchaWidget = forwardRef<refType, prop>(({ onSuccess }, ref) => {
return <Skeleton variant="rectangular" width={300} height={65} /> return <Skeleton variant="rectangular" width={300} height={65} />
} }
if (data?.captcha.type == "") {
return <></>
}
return ( return (
<> <>
<Turnstile siteKey={data?.captcha?.siteKey ?? ""} key={key} onSuccess={onSuccess} ref={Turnstileref} scriptOptions={{ async: true }} /> <Turnstile siteKey={data?.captcha?.siteKey ?? ""} key={key} onSuccess={onSuccess} ref={Turnstileref} scriptOptions={{ async: true }} />