feat: 登录注册接入 Cloudflare Turnstile 人机验证 — 前端widget+提交token, 后端siteverify校验(secret存.env), 网络故障fail-open
This commit is contained in:
1 parent
54fba4d97a
commit
23426588d0
3 files changed
+111
-7
No files matched your search
@@ -49,11 +49,11 @@ export function useUserAuth() {
|
||||
const isLoggedIn = computed(() => state.value !== null);
|
||||
const username = computed(() => state.value?.username ?? '');
|
||||
|
||||
async function login(u: string, p: string) {
|
||||
async function login(u: string, p: string, cfToken = '') {
|
||||
const { status, body } = await apiFetch('/user/login', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ username: u, password: p }),
|
||||
body: JSON.stringify({ username: u, password: p, cf_token: cfToken }),
|
||||
});
|
||||
if (status !== 200) {
|
||||
throw new Error(body.message || '登录失败');
|
||||
@@ -63,11 +63,11 @@ export function useUserAuth() {
|
||||
return body.data.username;
|
||||
}
|
||||
|
||||
async function register(u: string, p: string) {
|
||||
async function register(u: string, p: string, cfToken = '') {
|
||||
const { status, body } = await apiFetch('/user/register', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ username: u, password: p }),
|
||||
body: JSON.stringify({ username: u, password: p, cf_token: cfToken }),
|
||||
});
|
||||
if (status !== 200) {
|
||||
throw new Error(body.message || '注册失败');
|
||||
|
||||
Reference in new issue
Block a user