dev #3
@ -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: '',
|
||||
|
||||
@ -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)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user