(e)
| 216 | } |
| 217 | |
| 218 | async function handleSubmit(e) { |
| 219 | if (password.length < 8) { |
| 220 | showInfo('密码长度不得小于 8 位!'); |
| 221 | return; |
| 222 | } |
| 223 | if (password !== password2) { |
| 224 | showInfo('两次输入的密码不一致'); |
| 225 | return; |
| 226 | } |
| 227 | if (username && password) { |
| 228 | if (turnstileEnabled && turnstileToken === '') { |
| 229 | showInfo('请稍后几秒重试,Turnstile 正在检查用户环境!'); |
| 230 | return; |
| 231 | } |
| 232 | setRegisterLoading(true); |
| 233 | try { |
| 234 | if (!affCode) { |
| 235 | affCode = localStorage.getItem('aff'); |
| 236 | } |
| 237 | inputs.aff_code = affCode; |
| 238 | const res = await API.post( |
| 239 | `/api/user/register?turnstile=${turnstileToken}`, |
| 240 | inputs, |
| 241 | ); |
| 242 | const { success, message } = res.data; |
| 243 | if (success) { |
| 244 | navigate('/login'); |
| 245 | showSuccess('注册成功!'); |
| 246 | } else { |
| 247 | showError(message); |
| 248 | } |
| 249 | } catch (error) { |
| 250 | showError('注册失败,请重试'); |
| 251 | } finally { |
| 252 | setRegisterLoading(false); |
| 253 | } |
| 254 | } |
| 255 | } |
| 256 | |
| 257 | const sendVerificationCode = async () => { |
| 258 | if (inputs.email === '') return; |
nothing calls this directly
no test coverage detected