Skip to content

Commit

Permalink
修复验证码为空时不应出现的框
Browse files Browse the repository at this point in the history
当没有设置私钥时自动生成
  • Loading branch information
xmdhs committed Oct 11, 2023
1 parent cad8e6e commit 47493b9
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
2 changes: 1 addition & 1 deletion cmd/authlibskin/config.yaml.template
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ textureBaseUrl: ""
webBaseUrl: ""

# 皮肤站名字,用于在多个地方展示
serverName: ""
serverName: "没有设置名字"

captcha:
# 验证码类型,目前只支持 cloudflare turnstile
Expand Down
12 changes: 11 additions & 1 deletion cmd/authlibskin/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package main

import (
"context"
"crypto/rand"
"crypto/rsa"
"errors"
"flag"
"fmt"
Expand All @@ -12,6 +14,7 @@ import (
"github.com/samber/lo"
"github.com/xmdhs/authlib-skin/config"
"github.com/xmdhs/authlib-skin/server"
"github.com/xmdhs/authlib-skin/utils/sign"
)

var configPath string
Expand All @@ -29,14 +32,21 @@ func main() {
b, err := os.ReadFile(configPath)
if err != nil {
if errors.Is(err, os.ErrNotExist) {
lo.Must0(os.WriteFile("config.yaml", configTempLate, 0600))
lo.Must0(os.WriteFile(configPath, configTempLate, 0600))
fmt.Println("未找到配置文件,已写入模板配置文件")
return
}
panic(err)
}
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))
defer cancel()
panic(s.ListenAndServe())
Expand Down
4 changes: 4 additions & 0 deletions frontend/src/components/CaptchaWidget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ const CaptchaWidget = forwardRef<refType, prop>(({ onSuccess }, ref) => {
return <Skeleton variant="rectangular" width={300} height={65} />
}

if (data?.captcha.type == "") {
return <></>
}

return (
<>
<Turnstile siteKey={data?.captcha?.siteKey ?? ""} key={key} onSuccess={onSuccess} ref={Turnstileref} scriptOptions={{ async: true }} />
Expand Down

0 comments on commit 47493b9

Please sign in to comment.