实现注册功能
This commit is contained in:
parent
6be9ce2d10
commit
51a8654248
@ -82,7 +82,7 @@ const authStore = useAuthStore()
|
|||||||
|
|
||||||
const formRef = ref()
|
const formRef = ref()
|
||||||
const loading = ref(false)
|
const loading = ref(false)
|
||||||
const showSignupLink = ref(false)
|
const showSignupLink = ref(true)
|
||||||
|
|
||||||
const formData = reactive({
|
const formData = reactive({
|
||||||
username: '',
|
username: '',
|
||||||
|
|||||||
@ -212,35 +212,56 @@ const rules = computed(() => {
|
|||||||
return rules
|
return rules
|
||||||
})
|
})
|
||||||
|
|
||||||
|
const getReferrerIfAny = () => {
|
||||||
|
try {
|
||||||
|
return document.referrer || ''
|
||||||
|
} catch {
|
||||||
|
return ''
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const handleSignup = async () => {
|
const handleSignup = async () => {
|
||||||
try {
|
try {
|
||||||
await formRef.value?.validate()
|
await formRef.value?.validate()
|
||||||
loading.value = true
|
loading.value = true
|
||||||
|
|
||||||
message.error(t('注册功能已移除'))
|
const response = await fetch('/api/action/jcloud.api.account.signup_with_username', {
|
||||||
return
|
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 (result.success) {
|
if (!response.ok) {
|
||||||
message.success(t('Sign up successful'))
|
const errorData = await response.json().catch(() => ({}))
|
||||||
if (result.user) {
|
const errorMessage = errorData?.messages?.length
|
||||||
authStore.user = result.user
|
? errorData.messages.join('\n')
|
||||||
// 登录状态由 cookie 决定,不需要手动设置
|
: (errorData?.message || errorData?.exc || '注册失败,请检查您的信息')
|
||||||
localStorage.setItem('jingrow_user', JSON.stringify(result.user))
|
throw new Error(errorMessage)
|
||||||
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')
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const data = await response.json()
|
||||||
|
|
||||||
|
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 {
|
} else {
|
||||||
const errorMsg = result.error || t('Sign up failed')
|
window.location.href = '/'
|
||||||
console.error('注册失败:', errorMsg, result)
|
|
||||||
message.error(errorMsg)
|
|
||||||
}
|
}
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
console.error('注册异常:', error)
|
console.error('注册异常:', error)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user