From 51a86542485cadf74136b2380d70e54845f31888 Mon Sep 17 00:00:00 2001 From: jingrow Date: Sat, 27 Dec 2025 22:37:36 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=9E=E7=8E=B0=E6=B3=A8=E5=86=8C=E5=8A=9F?= =?UTF-8?q?=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/src/views/auth/Login.vue | 2 +- frontend/src/views/auth/Signup.vue | 65 ++++++++++++++++++++---------- 2 files changed, 44 insertions(+), 23 deletions(-) diff --git a/frontend/src/views/auth/Login.vue b/frontend/src/views/auth/Login.vue index 8856c1c..2adac8b 100644 --- a/frontend/src/views/auth/Login.vue +++ b/frontend/src/views/auth/Login.vue @@ -82,7 +82,7 @@ const authStore = useAuthStore() const formRef = ref() const loading = ref(false) -const showSignupLink = ref(false) +const showSignupLink = ref(true) const formData = reactive({ username: '', diff --git a/frontend/src/views/auth/Signup.vue b/frontend/src/views/auth/Signup.vue index 5178638..8744471 100644 --- a/frontend/src/views/auth/Signup.vue +++ b/frontend/src/views/auth/Signup.vue @@ -212,35 +212,56 @@ const rules = computed(() => { return rules }) +const getReferrerIfAny = () => { + try { + return document.referrer || '' + } catch { + return '' + } +} + const handleSignup = async () => { try { await formRef.value?.validate() loading.value = true - message.error(t('注册功能已移除')) - return + const response = await fetch('/api/action/jcloud.api.account.signup_with_username', { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + 'Accept': 'application/json' + }, + credentials: 'include', + body: JSON.stringify({ + username: formData.username, + password: formData.password, + email: formData.email || null, + phone_number: isEnglish.value ? (formData.phoneNumber || null) : formData.phoneNumber || null, + referrer: getReferrerIfAny(), + product: router.currentRoute.value.query.product || null + }) + }) + + if (!response.ok) { + const errorData = await response.json().catch(() => ({})) + const errorMessage = errorData?.messages?.length + ? errorData.messages.join('\n') + : (errorData?.message || errorData?.exc || '注册失败,请检查您的信息') + throw new Error(errorMessage) + } + + const data = await response.json() - if (result.success) { - message.success(t('Sign up successful')) - if (result.user) { - authStore.user = result.user - // 登录状态由 cookie 决定,不需要手动设置 - localStorage.setItem('jingrow_user', JSON.stringify(result.user)) - localStorage.setItem('jingrow_authenticated', 'true') - router.push('/') - } else { - const loginResult = await authStore.login(formData.username, formData.password) - if (loginResult.success) { - router.push('/') - } else { - message.warning(loginResult.error || t('注册成功,但自动登录失败,请手动登录')) - router.push('/login') - } - } + if (data && data.success === false) { + throw new Error(data.message || '注册失败,请检查您的信息') + } + + localStorage.setItem('login_email', formData.username || formData.email) + + if (data && data.dashboard_route) { + window.location.href = data.dashboard_route } else { - const errorMsg = result.error || t('Sign up failed') - console.error('注册失败:', errorMsg, result) - message.error(errorMsg) + window.location.href = '/' } } catch (error: any) { console.error('注册异常:', error)