Skip to content

Commit 8b2e322

Browse files
1. 优化代码
2. 支持体验更好的拖动验证吗
1 parent 3a5b693 commit 8b2e322

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

87 files changed

+8136
-10402
lines changed

admin/src/api/user.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ export interface LoginData {
1010
username: string;
1111
password: string;
1212
captchaId: string;
13-
captchaUrl: string;
1413
captchaCode: string;
1514
}
1615

@@ -35,7 +34,6 @@ export function login(data: LoginData) {
3534
formData.append('username', data.username);
3635
formData.append('password', data.password);
3736
formData.append('captchaId', data.captchaId);
38-
formData.append('captchaUrl', data.captchaUrl);
3937
formData.append('captchaCode', data.captchaCode);
4038
return axios.postForm<LoginRes>('/api/login/signin', formData);
4139
}

admin/src/components/ImageUpload.vue

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,4 +93,10 @@
9393
};
9494
</script>
9595

96-
<style lang="scss" scoped></style>
96+
<style lang="scss" scoped>
97+
.custom-upload-avatar {
98+
img {
99+
object-fit: cover;
100+
}
101+
}
102+
</style>

admin/src/views/login/components/login-form.vue

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
</a-form-item>
4444

4545
<a-form-item
46-
v-if="form.captchaUrl"
46+
v-if="captchaBase64"
4747
field="captchaCode"
4848
:rules="[
4949
{ required: true, message: $t('login.form.captchaCode.errMsg') },
@@ -61,7 +61,10 @@
6161
<icon-copy />
6262
</template>
6363
<template #append>
64-
<img :src="form.captchaUrl" @click="refreshCaptcha" />
64+
<img
65+
:src="`data:image/png;base64,${captchaBase64}`"
66+
@click="refreshCaptcha"
67+
/>
6568
</template>
6669
</a-input>
6770
</a-form-item>
@@ -93,27 +96,22 @@
9396
username: '',
9497
password: '',
9598
captchaId: '',
96-
captchaUrl: '',
9799
captchaCode: '',
98100
});
99101
102+
const captchaBase64 = ref('');
103+
100104
interface User {
101105
captchaId: string;
102-
captchaUrl: string;
106+
captchaBase64: string;
103107
}
104108
105109
const refreshCaptcha = async () => {
106-
const { captchaId, captchaUrl } = await axios.get<any, User>(
107-
'/api/captcha/request',
108-
{
109-
params: {
110-
captchaId: form.captchaId,
111-
},
112-
}
113-
);
114-
form.captchaId = captchaId;
115-
form.captchaUrl = captchaUrl;
110+
const ret = await axios.get<any, User>('/api/captcha/request');
111+
form.captchaId = ret.captchaId;
116112
form.captchaCode = '';
113+
114+
captchaBase64.value = ret.captchaBase64;
117115
};
118116
119117
refreshCaptcha();
@@ -184,6 +182,7 @@
184182
.captcha-code {
185183
img {
186184
height: 30px;
185+
cursor: pointer;
187186
}
188187
}
189188
</style>

admin/src/views/pages/settings/components/CommonSettings.vue

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
<a-form-item label="网站LOGO">
88
<image-upload v-model="config.siteLogo" />
9-
<div></div>
109
</a-form-item>
1110

1211
<a-form-item label="网站描述">

bbs-go.code-workspace

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@
2424
"admin/src/components/message-box/locale",
2525
"admin/src/views/login/locale",
2626
"admin/src/views/dashboard/workplace/locale"
27+
],
28+
"cSpell.words": [
29+
"favorited",
30+
"Weixin"
2731
]
2832
}
2933
}

server/bbs-go.example.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,4 +62,4 @@ SmSEO:
6262

6363
# search
6464
Search:
65-
IndexPath: # 索引路径
65+
IndexPath: # 索引路径

server/go.mod

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
module bbs-go
22

3-
go 1.23
4-
5-
toolchain go1.23.0
3+
go 1.24.0
64

75
require (
86
github.com/88250/lute v1.7.6
@@ -22,14 +20,16 @@ require (
2220
github.com/lionsoul2014/ip2region/binding/golang v0.0.0-20240510055607-89e20ab7b6c6
2321
github.com/microcosm-cc/bluemonday v1.0.27
2422
github.com/mitchellh/mapstructure v1.5.0
25-
github.com/mlogclub/simple v1.2.27
23+
github.com/mlogclub/simple v1.2.30
2624
github.com/panjf2000/ants/v2 v2.10.0
2725
github.com/pkg/errors v0.9.1
2826
github.com/robfig/cron/v3 v3.0.1
2927
github.com/sirupsen/logrus v1.9.3
3028
github.com/spf13/cast v1.7.0
3129
github.com/spf13/viper v1.19.0
3230
github.com/tidwall/gjson v1.17.3
31+
github.com/wenlng/go-captcha-assets v1.0.5
32+
github.com/wenlng/go-captcha/v2 v2.0.3
3333
gopkg.in/natefinch/lumberjack.v2 v2.2.1
3434
gorm.io/driver/mysql v1.5.7
3535
gorm.io/gorm v1.25.12
@@ -70,10 +70,15 @@ require (
7070
github.com/fatih/structs v1.1.0 // indirect
7171
github.com/flosch/pongo2/v4 v4.0.2 // indirect
7272
github.com/fsnotify/fsnotify v1.7.0 // indirect
73+
github.com/gabriel-vasile/mimetype v1.4.6 // indirect
74+
github.com/go-playground/locales v0.14.1 // indirect
75+
github.com/go-playground/universal-translator v0.18.1 // indirect
76+
github.com/go-playground/validator/v10 v10.22.1 // indirect
7377
github.com/go-sql-driver/mysql v1.7.0 // indirect
7478
github.com/gobwas/httphead v0.1.0 // indirect
7579
github.com/gobwas/pool v0.2.1 // indirect
7680
github.com/gobwas/ws v1.3.2 // indirect
81+
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0 // indirect
7782
github.com/golang/geo v0.0.0-20230421003525-6adc56603217 // indirect
7883
github.com/golang/protobuf v1.5.4 // indirect
7984
github.com/golang/snappy v0.0.4 // indirect
@@ -98,6 +103,7 @@ require (
98103
github.com/kataras/sitemap v0.0.6 // indirect
99104
github.com/kataras/tunnel v0.0.4 // indirect
100105
github.com/klauspost/compress v1.17.7 // indirect
106+
github.com/leodido/go-urn v1.4.0 // indirect
101107
github.com/magiconair/properties v1.8.7 // indirect
102108
github.com/mailgun/raymond/v2 v2.0.48 // indirect
103109
github.com/mailru/easyjson v0.7.7 // indirect
@@ -130,10 +136,11 @@ require (
130136
go.uber.org/multierr v1.11.0 // indirect
131137
golang.org/x/crypto v0.31.0 // indirect
132138
golang.org/x/exp v0.0.0-20240404231335-c0f41cb1a7a0 // indirect
139+
golang.org/x/image v0.25.0 // indirect
133140
golang.org/x/net v0.33.0 // indirect
134-
golang.org/x/sync v0.10.0 // indirect
141+
golang.org/x/sync v0.12.0 // indirect
135142
golang.org/x/sys v0.28.0 // indirect
136-
golang.org/x/text v0.21.0 // indirect
143+
golang.org/x/text v0.23.0 // indirect
137144
golang.org/x/time v0.6.0 // indirect
138145
golang.org/x/xerrors v0.0.0-20231012003039-104605ab7028 // indirect
139146
google.golang.org/protobuf v1.34.2 // indirect

server/go.sum

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -111,10 +111,20 @@ github.com/frankban/quicktest v1.14.6 h1:7Xjx+VpznH+oBnejlPUj8oUpdxnVs4f8XU8WnHk
111111
github.com/frankban/quicktest v1.14.6/go.mod h1:4ptaffx2x8+WTWXmUCuVU6aPUX1/Mz7zb5vbUoiM6w0=
112112
github.com/fsnotify/fsnotify v1.7.0 h1:8JEhPFa5W2WU7YfeZzPNqzMP6Lwt7L2715Ggo0nosvA=
113113
github.com/fsnotify/fsnotify v1.7.0/go.mod h1:40Bi/Hjc2AVfZrqy+aj+yEI+/bRxZnMJyTJwOpGvigM=
114+
github.com/gabriel-vasile/mimetype v1.4.6 h1:3+PzJTKLkvgjeTbts6msPJt4DixhT4YtFNf1gtGe3zc=
115+
github.com/gabriel-vasile/mimetype v1.4.6/go.mod h1:JX1qVKqZd40hUPpAfiNTe0Sne7hdfKSbOqqmkq8GCXc=
114116
github.com/go-logr/logr v1.4.2 h1:6pFjapn8bFcIbiKo3XT4j/BhANplGihG6tvd+8rYgrY=
115117
github.com/go-logr/logr v1.4.2/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY=
116118
github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag=
117119
github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE=
120+
github.com/go-playground/assert/v2 v2.2.0 h1:JvknZsQTYeFEAhQwI4qEt9cyV5ONwRHC+lYKSsYSR8s=
121+
github.com/go-playground/assert/v2 v2.2.0/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4=
122+
github.com/go-playground/locales v0.14.1 h1:EWaQ/wswjilfKLTECiXz7Rh+3BjFhfDFKv/oXslEjJA=
123+
github.com/go-playground/locales v0.14.1/go.mod h1:hxrqLVvrK65+Rwrd5Fc6F2O76J/NuW9t0sjnWqG1slY=
124+
github.com/go-playground/universal-translator v0.18.1 h1:Bcnm0ZwsGyWbCzImXv+pAJnYK9S473LQFuzCbDbfSFY=
125+
github.com/go-playground/universal-translator v0.18.1/go.mod h1:xekY+UJKNuX9WP91TpwSH2VMlDf28Uj24BCp08ZFTUY=
126+
github.com/go-playground/validator/v10 v10.22.1 h1:40JcKH+bBNGFczGuoBYgX4I6m/i27HYW8P9FDk5PbgA=
127+
github.com/go-playground/validator/v10 v10.22.1/go.mod h1:dbuPbCMFw/DrkbEynArYaCwl3amGuJotoKCe95atGMM=
118128
github.com/go-resty/resty/v2 v2.15.0 h1:clPQLZ2x9h4yGY81IzpMPnty+xoGyFaDg0XMkCsHf90=
119129
github.com/go-resty/resty/v2 v2.15.0/go.mod h1:0fHAoK7JoBy/Ch36N8VFeMsK7xQOHhvWaC3iOktwmIU=
120130
github.com/go-sql-driver/mysql v1.7.0 h1:ueSltNNllEqE3qcWBTD0iQd3IpL/6U+mJxLkazJ7YPc=
@@ -135,6 +145,8 @@ github.com/golang-jwt/jwt/v4 v4.5.1 h1:JdqV9zKUdtaa9gdPlywC3aeoEsR681PlKC+4F5gQg
135145
github.com/golang-jwt/jwt/v4 v4.5.1/go.mod h1:m21LjoU+eqJr34lmDMbreY2eSTRJ1cv77w39/MY0Ch0=
136146
github.com/golang-migrate/migrate/v4 v4.18.2 h1:2VSCMz7x7mjyTXx3m2zPokOY82LTRgxK1yQYKo6wWQ8=
137147
github.com/golang-migrate/migrate/v4 v4.18.2/go.mod h1:2CM6tJvn2kqPXwnXO/d3rAQYiyoIm180VsO8PRX6Rpk=
148+
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0 h1:DACJavvAHhabrF08vX0COfcOBJRhZ8lUbR+ZWIs0Y5g=
149+
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0/go.mod h1:E/TSTwGwJL78qG/PmXZO1EjYhfJinVAhrmmHX6Z8B9k=
138150
github.com/golang/geo v0.0.0-20230421003525-6adc56603217 h1:HKlyj6in2JV6wVkmQ4XmG/EIm+SCYlPZ+V4GWit7Z+I=
139151
github.com/golang/geo v0.0.0-20230421003525-6adc56603217/go.mod h1:8wI0hitZ3a1IxZfeH3/5I97CI8i5cLGsYe7xNhQGs9U=
140152
github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek=
@@ -207,6 +219,8 @@ github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
207219
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
208220
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
209221
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
222+
github.com/leodido/go-urn v1.4.0 h1:WT9HwE9SGECu3lg4d/dIA+jxlljEa1/ffXKmRjqdmIQ=
223+
github.com/leodido/go-urn v1.4.0/go.mod h1:bvxc+MVxLKB4z00jd1z+Dvzr47oO32F/QSNjSBOlFxI=
210224
github.com/lib/pq v1.10.9 h1:YXG7RB+JIjhP29X+OtkiDnYaXQwpS4JEWq7dtCCRUEw=
211225
github.com/lib/pq v1.10.9/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o=
212226
github.com/lionsoul2014/ip2region/binding/golang v0.0.0-20240510055607-89e20ab7b6c6 h1:YeIGErDiB/fhmNsJy0cfjoT8XnRNT9hb19xZ4MvWQDU=
@@ -229,8 +243,8 @@ github.com/mitchellh/go-wordwrap v1.0.1 h1:TLuKupo69TCn6TQSyGxwI1EblZZEsQ0vMlAFQ
229243
github.com/mitchellh/go-wordwrap v1.0.1/go.mod h1:R62XHJLzvMFRBbcrT7m7WgmE1eOyTSsCt+hzestvNj0=
230244
github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY=
231245
github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
232-
github.com/mlogclub/simple v1.2.27 h1:0eWKPyWE/HjhabUX6kFlC2Bp1CHjT3NkZvs+dymnl+I=
233-
github.com/mlogclub/simple v1.2.27/go.mod h1:qbq9YjSTXqO8uwyLBf2gHqx6OAzAiPk/x+1CAgY/8/w=
246+
github.com/mlogclub/simple v1.2.30 h1:RdylnAOLyCDO99I98otym6tPXScE7o9BDXlTVtiTCMM=
247+
github.com/mlogclub/simple v1.2.30/go.mod h1:LUoFfG22bQTjWrpGqni59annKDgj69I0NUxz5AsdotY=
234248
github.com/moby/docker-image-spec v1.3.1 h1:jMKff3w6PgbfSa69GfNg+zN/XLhfXJGnEx3Nl2EsFP0=
235249
github.com/moby/docker-image-spec v1.3.1/go.mod h1:eKmb5VW8vQEh/BAr2yvVNvuiJuY6UIocYsFu/DxxRpo=
236250
github.com/moby/term v0.5.0 h1:xt8Q1nalod/v7BqbG21f8mQPqH+xAaC9C3N3wfWbVP0=
@@ -328,6 +342,10 @@ github.com/vmihailenco/msgpack/v5 v5.4.1 h1:cQriyiUvjTwOHg8QZaPihLWeRAAVoCpE00IU
328342
github.com/vmihailenco/msgpack/v5 v5.4.1/go.mod h1:GaZTsDaehaPpQVyxrf5mtQlH+pc21PIudVV/E3rRQok=
329343
github.com/vmihailenco/tagparser/v2 v2.0.0 h1:y09buUbR+b5aycVFQs/g70pqKVZNBmxwAhO7/IwNM9g=
330344
github.com/vmihailenco/tagparser/v2 v2.0.0/go.mod h1:Wri+At7QHww0WTrCBeu4J6bNtoV6mEfg5OIWRZA9qds=
345+
github.com/wenlng/go-captcha-assets v1.0.5 h1:TL+31Qe/kJwcuYyU+jHedjSTZnMu1XKgktKL++lH9Js=
346+
github.com/wenlng/go-captcha-assets v1.0.5/go.mod h1:zinRACsdYcL/S6pHgI9Iv7FKTU41d00+43pNX+b9+MM=
347+
github.com/wenlng/go-captcha/v2 v2.0.3 h1:QTZ39/gVDisPSgvL9O2X2HbTuj5P/z8QsdGB/aayg9c=
348+
github.com/wenlng/go-captcha/v2 v2.0.3/go.mod h1:5hac1em3uXoyC5ipZ0xFv9umNM/waQvYAQdr0cx/h34=
331349
github.com/xeipuuv/gojsonpointer v0.0.0-20180127040702-4e3ac2762d5f h1:J9EGpcZtP0E/raorCMxlFGSTBrsSlaDGf3jU/qvAE2c=
332350
github.com/xeipuuv/gojsonpointer v0.0.0-20180127040702-4e3ac2762d5f/go.mod h1:N2zxlSyiKSe5eX1tZViRH5QA0qijqEDrYZiPEAiq3wU=
333351
github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415 h1:EzJWgHovont7NscjpAxXsDA8S8BMYve8Y5+7cuRE7R0=
@@ -365,6 +383,9 @@ golang.org/x/crypto v0.31.0 h1:ihbySMvVjLAeSH1IbfcRTkD/iNscyz8rGzjF/E5hV6U=
365383
golang.org/x/crypto v0.31.0/go.mod h1:kDsLvtWBEx7MV9tJOj9bnXsPbxwJQ6csT/x4KIN4Ssk=
366384
golang.org/x/exp v0.0.0-20240404231335-c0f41cb1a7a0 h1:985EYyeCOxTpcgOTJpflJUwOeEz0CQOdPt73OzpE9F8=
367385
golang.org/x/exp v0.0.0-20240404231335-c0f41cb1a7a0/go.mod h1:/lliqkxwWAhPjf5oSOIJup2XcqJaw8RGS6k3TGEc7GI=
386+
golang.org/x/image v0.16.0/go.mod h1:ugSZItdV4nOxyqp56HmXwH0Ry0nBCpjnZdpDaIHdoPs=
387+
golang.org/x/image v0.25.0 h1:Y6uW6rH1y5y/LK1J8BPWZtr6yZ7hrsy6hFrXjgsc2fQ=
388+
golang.org/x/image v0.25.0/go.mod h1:tCAmOEGthTtkalusGp1g3xa2gke8J6c2N565dTyl9Rs=
368389
golang.org/x/mod v0.5.1/go.mod h1:5OXOZSfqPIIbmVBIIKWRFfZjPR0E5r58TLhUjH0a2Ro=
369390
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
370391
golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
@@ -383,8 +404,8 @@ golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJ
383404
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
384405
golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
385406
golang.org/x/sync v0.3.0/go.mod h1:FU7BRWz2tNW+3quACPkgCx/L+uEAv1htQ0V83Z9Rj+Y=
386-
golang.org/x/sync v0.10.0 h1:3NQrjDixjgGwUOCaF8w2+VYHv0Ve/vGYSbdkTa98gmQ=
387-
golang.org/x/sync v0.10.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
407+
golang.org/x/sync v0.12.0 h1:MHc5BpPuC30uJk597Ri8TV3CNZcTLu6B6z4lJy+g6Jw=
408+
golang.org/x/sync v0.12.0/go.mod h1:1dzgHSNfp02xaA81J2MS99Qcpr2w7fw1gpm99rleRqA=
388409
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
389410
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
390411
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
@@ -410,8 +431,9 @@ golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
410431
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
411432
golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
412433
golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8=
413-
golang.org/x/text v0.21.0 h1:zyQAAkrwaneQ066sspRyJaG9VNi/YJ1NfzcGB3hZ/qo=
414-
golang.org/x/text v0.21.0/go.mod h1:4IBbMaMmOPCJ8SecivzSH54+73PCFmPWxNTLm+vZkEQ=
434+
golang.org/x/text v0.15.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
435+
golang.org/x/text v0.23.0 h1:D71I7dUrlY+VX0gQShAThNGHFxZ13dGLBHQLVl1mJlY=
436+
golang.org/x/text v0.23.0/go.mod h1:/BLNzu4aZCJ1+kcD0DNRotWKage4q2rGVAg4o22unh4=
415437
golang.org/x/time v0.6.0 h1:eTDhh4ZXt5Qf0augr54TN6suAUudPcawVZeIAPU7D4U=
416438
golang.org/x/time v0.6.0/go.mod h1:3BpzKBy/shNhVucY/MWOyx10tF3SFh9QdLuxbVysPQM=
417439
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
Lines changed: 16 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
package api
22

33
import (
4-
"bbs-go/internal/pkg/bbsurls"
5-
"log/slog"
4+
newCaptcha "bbs-go/internal/pkg/captcha"
5+
"bytes"
6+
"encoding/base64"
67

78
"github.com/dchest/captcha"
89
"github.com/kataras/iris/v12"
9-
"github.com/mlogclub/simple/common/strs"
1010
"github.com/mlogclub/simple/web"
1111
)
1212

@@ -15,44 +15,28 @@ type CaptchaController struct {
1515
}
1616

1717
func (c *CaptchaController) GetRequest() *web.JsonResult {
18-
captchaId := c.Ctx.FormValue("captchaId")
19-
if strs.IsNotBlank(captchaId) { // reload
20-
if !captcha.Reload(captchaId) {
21-
// reload 失败,重新加载验证码
22-
captchaId = captcha.NewLen(4)
23-
}
24-
} else {
25-
captchaId = captcha.NewLen(4)
18+
captchaId := captcha.NewLen(4)
19+
var buf bytes.Buffer
20+
if err := captcha.WriteImage(&buf, captchaId, captcha.StdWidth, captcha.StdHeight); err != nil {
21+
return web.JsonError(err)
2622
}
27-
captchaUrl := bbsurls.AbsUrl("/api/captcha/show?captchaId=" + captchaId + "&r=" + strs.UUID())
2823
return web.NewEmptyRspBuilder().
2924
Put("captchaId", captchaId).
30-
Put("captchaUrl", captchaUrl).
25+
Put("captchaBase64", base64.StdEncoding.EncodeToString(buf.Bytes())).
3126
JsonResult()
3227
}
3328

34-
func (c *CaptchaController) GetShow() {
35-
captchaId := c.Ctx.URLParam("captchaId")
36-
37-
if captchaId == "" {
38-
c.Ctx.StatusCode(404)
39-
return
40-
}
41-
42-
if !captcha.Reload(captchaId) {
43-
c.Ctx.StatusCode(404)
44-
return
45-
}
46-
47-
c.Ctx.Header("Content-Type", "image/png")
48-
if err := captcha.WriteImage(c.Ctx.ResponseWriter(), captchaId, captcha.StdWidth, captcha.StdHeight); err != nil {
49-
slog.Error(err.Error(), slog.Any("err", err))
50-
}
51-
}
52-
5329
func (c *CaptchaController) GetVerify() *web.JsonResult {
5430
captchaId := c.Ctx.URLParam("captchaId")
5531
captchaCode := c.Ctx.URLParam("captchaCode")
5632
success := captcha.VerifyString(captchaId, captchaCode)
5733
return web.NewEmptyRspBuilder().Put("success", success).JsonResult()
5834
}
35+
36+
func (c *CaptchaController) GetRequest_angle() *web.JsonResult {
37+
data, err := newCaptcha.Generate()
38+
if err != nil {
39+
return web.JsonError(err)
40+
}
41+
return web.JsonData(data)
42+
}

0 commit comments

Comments
 (0)