RegisterForm.jsx 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751
  1. /*
  2. Copyright (C) 2025 QuantumNous
  3. This program is free software: you can redistribute it and/or modify
  4. it under the terms of the GNU Affero General Public License as
  5. published by the Free Software Foundation, either version 3 of the
  6. License, or (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU Affero General Public License for more details.
  11. You should have received a copy of the GNU Affero General Public License
  12. along with this program. If not, see <https://www.gnu.org/licenses/>.
  13. For commercial licensing, please contact support@quantumnous.com
  14. */
  15. import React, { useContext, useEffect, useRef, useState } from 'react';
  16. import { Link, useNavigate } from 'react-router-dom';
  17. import {
  18. API,
  19. getLogo,
  20. showError,
  21. showInfo,
  22. showSuccess,
  23. updateAPI,
  24. getSystemName,
  25. setUserData,
  26. onDiscordOAuthClicked,
  27. } from '../../helpers';
  28. import Turnstile from 'react-turnstile';
  29. import { Button, Card, Checkbox, Divider, Form, Icon, Modal } from '@douyinfe/semi-ui';
  30. import Title from '@douyinfe/semi-ui/lib/es/typography/title';
  31. import Text from '@douyinfe/semi-ui/lib/es/typography/text';
  32. import {
  33. IconGithubLogo,
  34. IconMail,
  35. IconUser,
  36. IconLock,
  37. IconKey,
  38. } from '@douyinfe/semi-icons';
  39. import {
  40. onGitHubOAuthClicked,
  41. onLinuxDOOAuthClicked,
  42. onOIDCClicked,
  43. } from '../../helpers';
  44. import OIDCIcon from '../common/logo/OIDCIcon';
  45. import LinuxDoIcon from '../common/logo/LinuxDoIcon';
  46. import WeChatIcon from '../common/logo/WeChatIcon';
  47. import TelegramLoginButton from 'react-telegram-login/src';
  48. import { UserContext } from '../../context/User';
  49. import { useTranslation } from 'react-i18next';
  50. import { SiDiscord } from 'react-icons/si';
  51. const RegisterForm = () => {
  52. let navigate = useNavigate();
  53. const { t } = useTranslation();
  54. const githubButtonTextKeyByState = {
  55. idle: '使用 GitHub 继续',
  56. redirecting: '正在跳转 GitHub...',
  57. timeout: '请求超时,请刷新页面后重新发起 GitHub 登录',
  58. };
  59. const [inputs, setInputs] = useState({
  60. username: '',
  61. password: '',
  62. password2: '',
  63. email: '',
  64. verification_code: '',
  65. wechat_verification_code: '',
  66. });
  67. const { username, password, password2 } = inputs;
  68. const [userState, userDispatch] = useContext(UserContext);
  69. const [turnstileEnabled, setTurnstileEnabled] = useState(false);
  70. const [turnstileSiteKey, setTurnstileSiteKey] = useState('');
  71. const [turnstileToken, setTurnstileToken] = useState('');
  72. const [showWeChatLoginModal, setShowWeChatLoginModal] = useState(false);
  73. const [showEmailRegister, setShowEmailRegister] = useState(false);
  74. const [wechatLoading, setWechatLoading] = useState(false);
  75. const [githubLoading, setGithubLoading] = useState(false);
  76. const [discordLoading, setDiscordLoading] = useState(false);
  77. const [oidcLoading, setOidcLoading] = useState(false);
  78. const [linuxdoLoading, setLinuxdoLoading] = useState(false);
  79. const [emailRegisterLoading, setEmailRegisterLoading] = useState(false);
  80. const [registerLoading, setRegisterLoading] = useState(false);
  81. const [verificationCodeLoading, setVerificationCodeLoading] = useState(false);
  82. const [otherRegisterOptionsLoading, setOtherRegisterOptionsLoading] =
  83. useState(false);
  84. const [wechatCodeSubmitLoading, setWechatCodeSubmitLoading] = useState(false);
  85. const [disableButton, setDisableButton] = useState(false);
  86. const [countdown, setCountdown] = useState(30);
  87. const [agreedToTerms, setAgreedToTerms] = useState(false);
  88. const [hasUserAgreement, setHasUserAgreement] = useState(false);
  89. const [hasPrivacyPolicy, setHasPrivacyPolicy] = useState(false);
  90. const [githubButtonState, setGithubButtonState] = useState('idle');
  91. const [githubButtonDisabled, setGithubButtonDisabled] = useState(false);
  92. const githubTimeoutRef = useRef(null);
  93. const githubButtonText = t(githubButtonTextKeyByState[githubButtonState]);
  94. const logo = getLogo();
  95. const systemName = getSystemName();
  96. let affCode = new URLSearchParams(window.location.search).get('aff');
  97. if (affCode) {
  98. localStorage.setItem('aff', affCode);
  99. }
  100. const [status] = useState(() => {
  101. const savedStatus = localStorage.getItem('status');
  102. return savedStatus ? JSON.parse(savedStatus) : {};
  103. });
  104. const [showEmailVerification, setShowEmailVerification] = useState(() => {
  105. return status.email_verification ?? false;
  106. });
  107. useEffect(() => {
  108. setShowEmailVerification(status.email_verification);
  109. if (status.turnstile_check) {
  110. setTurnstileEnabled(true);
  111. setTurnstileSiteKey(status.turnstile_site_key);
  112. }
  113. // 从 status 获取用户协议和隐私政策的启用状态
  114. setHasUserAgreement(status.user_agreement_enabled || false);
  115. setHasPrivacyPolicy(status.privacy_policy_enabled || false);
  116. }, [status]);
  117. useEffect(() => {
  118. let countdownInterval = null;
  119. if (disableButton && countdown > 0) {
  120. countdownInterval = setInterval(() => {
  121. setCountdown(countdown - 1);
  122. }, 1000);
  123. } else if (countdown === 0) {
  124. setDisableButton(false);
  125. setCountdown(30);
  126. }
  127. return () => clearInterval(countdownInterval); // Clean up on unmount
  128. }, [disableButton, countdown]);
  129. useEffect(() => {
  130. return () => {
  131. if (githubTimeoutRef.current) {
  132. clearTimeout(githubTimeoutRef.current);
  133. }
  134. };
  135. }, []);
  136. const onWeChatLoginClicked = () => {
  137. setWechatLoading(true);
  138. setShowWeChatLoginModal(true);
  139. setWechatLoading(false);
  140. };
  141. const onSubmitWeChatVerificationCode = async () => {
  142. if (turnstileEnabled && turnstileToken === '') {
  143. showInfo('请稍后几秒重试,Turnstile 正在检查用户环境!');
  144. return;
  145. }
  146. setWechatCodeSubmitLoading(true);
  147. try {
  148. const res = await API.get(
  149. `/api/oauth/wechat?code=${inputs.wechat_verification_code}`,
  150. );
  151. const { success, message, data } = res.data;
  152. if (success) {
  153. userDispatch({ type: 'login', payload: data });
  154. localStorage.setItem('user', JSON.stringify(data));
  155. setUserData(data);
  156. updateAPI();
  157. navigate('/');
  158. showSuccess('登录成功!');
  159. setShowWeChatLoginModal(false);
  160. } else {
  161. showError(message);
  162. }
  163. } catch (error) {
  164. showError('登录失败,请重试');
  165. } finally {
  166. setWechatCodeSubmitLoading(false);
  167. }
  168. };
  169. function handleChange(name, value) {
  170. setInputs((inputs) => ({ ...inputs, [name]: value }));
  171. }
  172. async function handleSubmit(e) {
  173. if (password.length < 8) {
  174. showInfo('密码长度不得小于 8 位!');
  175. return;
  176. }
  177. if (password !== password2) {
  178. showInfo('两次输入的密码不一致');
  179. return;
  180. }
  181. if (username && password) {
  182. if (turnstileEnabled && turnstileToken === '') {
  183. showInfo('请稍后几秒重试,Turnstile 正在检查用户环境!');
  184. return;
  185. }
  186. setRegisterLoading(true);
  187. try {
  188. if (!affCode) {
  189. affCode = localStorage.getItem('aff');
  190. }
  191. inputs.aff_code = affCode;
  192. const res = await API.post(
  193. `/api/user/register?turnstile=${turnstileToken}`,
  194. inputs,
  195. );
  196. const { success, message } = res.data;
  197. if (success) {
  198. navigate('/login');
  199. showSuccess('注册成功!');
  200. } else {
  201. showError(message);
  202. }
  203. } catch (error) {
  204. showError('注册失败,请重试');
  205. } finally {
  206. setRegisterLoading(false);
  207. }
  208. }
  209. }
  210. const sendVerificationCode = async () => {
  211. if (inputs.email === '') return;
  212. if (turnstileEnabled && turnstileToken === '') {
  213. showInfo('请稍后几秒重试,Turnstile 正在检查用户环境!');
  214. return;
  215. }
  216. setVerificationCodeLoading(true);
  217. try {
  218. const res = await API.get(
  219. `/api/verification?email=${inputs.email}&turnstile=${turnstileToken}`,
  220. );
  221. const { success, message } = res.data;
  222. if (success) {
  223. showSuccess('验证码发送成功,请检查你的邮箱!');
  224. setDisableButton(true); // 发送成功后禁用按钮,开始倒计时
  225. } else {
  226. showError(message);
  227. }
  228. } catch (error) {
  229. showError('发送验证码失败,请重试');
  230. } finally {
  231. setVerificationCodeLoading(false);
  232. }
  233. };
  234. const handleGitHubClick = () => {
  235. if (githubButtonDisabled) {
  236. return;
  237. }
  238. setGithubLoading(true);
  239. setGithubButtonDisabled(true);
  240. setGithubButtonState('redirecting');
  241. if (githubTimeoutRef.current) {
  242. clearTimeout(githubTimeoutRef.current);
  243. }
  244. githubTimeoutRef.current = setTimeout(() => {
  245. setGithubLoading(false);
  246. setGithubButtonState('timeout');
  247. setGithubButtonDisabled(true);
  248. }, 20000);
  249. try {
  250. onGitHubOAuthClicked(status.github_client_id, { shouldLogout: true });
  251. } finally {
  252. setTimeout(() => setGithubLoading(false), 3000);
  253. }
  254. };
  255. const handleDiscordClick = () => {
  256. setDiscordLoading(true);
  257. try {
  258. onDiscordOAuthClicked(status.discord_client_id, { shouldLogout: true });
  259. } finally {
  260. setTimeout(() => setDiscordLoading(false), 3000);
  261. }
  262. };
  263. const handleOIDCClick = () => {
  264. setOidcLoading(true);
  265. try {
  266. onOIDCClicked(
  267. status.oidc_authorization_endpoint,
  268. status.oidc_client_id,
  269. false,
  270. { shouldLogout: true },
  271. );
  272. } finally {
  273. setTimeout(() => setOidcLoading(false), 3000);
  274. }
  275. };
  276. const handleLinuxDOClick = () => {
  277. setLinuxdoLoading(true);
  278. try {
  279. onLinuxDOOAuthClicked(status.linuxdo_client_id, { shouldLogout: true });
  280. } finally {
  281. setTimeout(() => setLinuxdoLoading(false), 3000);
  282. }
  283. };
  284. const handleEmailRegisterClick = () => {
  285. setEmailRegisterLoading(true);
  286. setShowEmailRegister(true);
  287. setEmailRegisterLoading(false);
  288. };
  289. const handleOtherRegisterOptionsClick = () => {
  290. setOtherRegisterOptionsLoading(true);
  291. setShowEmailRegister(false);
  292. setOtherRegisterOptionsLoading(false);
  293. };
  294. const onTelegramLoginClicked = async (response) => {
  295. const fields = [
  296. 'id',
  297. 'first_name',
  298. 'last_name',
  299. 'username',
  300. 'photo_url',
  301. 'auth_date',
  302. 'hash',
  303. 'lang',
  304. ];
  305. const params = {};
  306. fields.forEach((field) => {
  307. if (response[field]) {
  308. params[field] = response[field];
  309. }
  310. });
  311. try {
  312. const res = await API.get(`/api/oauth/telegram/login`, { params });
  313. const { success, message, data } = res.data;
  314. if (success) {
  315. userDispatch({ type: 'login', payload: data });
  316. localStorage.setItem('user', JSON.stringify(data));
  317. showSuccess('登录成功!');
  318. setUserData(data);
  319. updateAPI();
  320. navigate('/');
  321. } else {
  322. showError(message);
  323. }
  324. } catch (error) {
  325. showError('登录失败,请重试');
  326. }
  327. };
  328. const renderOAuthOptions = () => {
  329. return (
  330. <div className='flex flex-col items-center'>
  331. <div className='w-full max-w-md'>
  332. <div className='flex items-center justify-center mb-6 gap-2'>
  333. <img src={logo} alt='Logo' className='h-10 rounded-full' />
  334. <Title heading={3} className='!text-gray-800'>
  335. {systemName}
  336. </Title>
  337. </div>
  338. <Card className='border-0 !rounded-2xl overflow-hidden'>
  339. <div className='flex justify-center pt-6 pb-2'>
  340. <Title heading={3} className='text-gray-800 dark:text-gray-200'>
  341. {t('注 册')}
  342. </Title>
  343. </div>
  344. <div className='px-2 py-8'>
  345. <div className='space-y-3'>
  346. {status.wechat_login && (
  347. <Button
  348. theme='outline'
  349. className='w-full h-12 flex items-center justify-center !rounded-full border border-gray-200 hover:bg-gray-50 transition-colors'
  350. type='tertiary'
  351. icon={
  352. <Icon svg={<WeChatIcon />} style={{ color: '#07C160' }} />
  353. }
  354. onClick={onWeChatLoginClicked}
  355. loading={wechatLoading}
  356. >
  357. <span className='ml-3'>{t('使用 微信 继续')}</span>
  358. </Button>
  359. )}
  360. {status.github_oauth && (
  361. <Button
  362. theme='outline'
  363. className='w-full h-12 flex items-center justify-center !rounded-full border border-gray-200 hover:bg-gray-50 transition-colors'
  364. type='tertiary'
  365. icon={<IconGithubLogo size='large' />}
  366. onClick={handleGitHubClick}
  367. loading={githubLoading}
  368. disabled={githubButtonDisabled}
  369. >
  370. <span className='ml-3'>{githubButtonText}</span>
  371. </Button>
  372. )}
  373. {status.discord_oauth && (
  374. <Button
  375. theme='outline'
  376. className='w-full h-12 flex items-center justify-center !rounded-full border border-gray-200 hover:bg-gray-50 transition-colors'
  377. type='tertiary'
  378. icon={<SiDiscord style={{ color: '#5865F2', width: '20px', height: '20px' }} />}
  379. onClick={handleDiscordClick}
  380. loading={discordLoading}
  381. >
  382. <span className='ml-3'>{t('使用 Discord 继续')}</span>
  383. </Button>
  384. )}
  385. {status.oidc_enabled && (
  386. <Button
  387. theme='outline'
  388. className='w-full h-12 flex items-center justify-center !rounded-full border border-gray-200 hover:bg-gray-50 transition-colors'
  389. type='tertiary'
  390. icon={<OIDCIcon style={{ color: '#1877F2' }} />}
  391. onClick={handleOIDCClick}
  392. loading={oidcLoading}
  393. >
  394. <span className='ml-3'>{t('使用 OIDC 继续')}</span>
  395. </Button>
  396. )}
  397. {status.linuxdo_oauth && (
  398. <Button
  399. theme='outline'
  400. className='w-full h-12 flex items-center justify-center !rounded-full border border-gray-200 hover:bg-gray-50 transition-colors'
  401. type='tertiary'
  402. icon={
  403. <LinuxDoIcon
  404. style={{
  405. color: '#E95420',
  406. width: '20px',
  407. height: '20px',
  408. }}
  409. />
  410. }
  411. onClick={handleLinuxDOClick}
  412. loading={linuxdoLoading}
  413. >
  414. <span className='ml-3'>{t('使用 LinuxDO 继续')}</span>
  415. </Button>
  416. )}
  417. {status.telegram_oauth && (
  418. <div className='flex justify-center my-2'>
  419. <TelegramLoginButton
  420. dataOnauth={onTelegramLoginClicked}
  421. botName={status.telegram_bot_name}
  422. />
  423. </div>
  424. )}
  425. <Divider margin='12px' align='center'>
  426. {t('或')}
  427. </Divider>
  428. <Button
  429. theme='solid'
  430. type='primary'
  431. className='w-full h-12 flex items-center justify-center bg-black text-white !rounded-full hover:bg-gray-800 transition-colors'
  432. icon={<IconMail size='large' />}
  433. onClick={handleEmailRegisterClick}
  434. loading={emailRegisterLoading}
  435. >
  436. <span className='ml-3'>{t('使用 用户名 注册')}</span>
  437. </Button>
  438. </div>
  439. <div className='mt-6 text-center text-sm'>
  440. <Text>
  441. {t('已有账户?')}{' '}
  442. <Link
  443. to='/login'
  444. className='text-blue-600 hover:text-blue-800 font-medium'
  445. >
  446. {t('登录')}
  447. </Link>
  448. </Text>
  449. </div>
  450. </div>
  451. </Card>
  452. </div>
  453. </div>
  454. );
  455. };
  456. const renderEmailRegisterForm = () => {
  457. return (
  458. <div className='flex flex-col items-center'>
  459. <div className='w-full max-w-md'>
  460. <div className='flex items-center justify-center mb-6 gap-2'>
  461. <img src={logo} alt='Logo' className='h-10 rounded-full' />
  462. <Title heading={3} className='!text-gray-800'>
  463. {systemName}
  464. </Title>
  465. </div>
  466. <Card className='border-0 !rounded-2xl overflow-hidden'>
  467. <div className='flex justify-center pt-6 pb-2'>
  468. <Title heading={3} className='text-gray-800 dark:text-gray-200'>
  469. {t('注 册')}
  470. </Title>
  471. </div>
  472. <div className='px-2 py-8'>
  473. <Form className='space-y-3'>
  474. <Form.Input
  475. field='username'
  476. label={t('用户名')}
  477. placeholder={t('请输入用户名')}
  478. name='username'
  479. onChange={(value) => handleChange('username', value)}
  480. prefix={<IconUser />}
  481. />
  482. <Form.Input
  483. field='password'
  484. label={t('密码')}
  485. placeholder={t('输入密码,最短 8 位,最长 20 位')}
  486. name='password'
  487. mode='password'
  488. onChange={(value) => handleChange('password', value)}
  489. prefix={<IconLock />}
  490. />
  491. <Form.Input
  492. field='password2'
  493. label={t('确认密码')}
  494. placeholder={t('确认密码')}
  495. name='password2'
  496. mode='password'
  497. onChange={(value) => handleChange('password2', value)}
  498. prefix={<IconLock />}
  499. />
  500. {showEmailVerification && (
  501. <>
  502. <Form.Input
  503. field='email'
  504. label={t('邮箱')}
  505. placeholder={t('输入邮箱地址')}
  506. name='email'
  507. type='email'
  508. onChange={(value) => handleChange('email', value)}
  509. prefix={<IconMail />}
  510. suffix={
  511. <Button
  512. onClick={sendVerificationCode}
  513. loading={verificationCodeLoading}
  514. disabled={disableButton || verificationCodeLoading}
  515. >
  516. {disableButton
  517. ? `${t('重新发送')} (${countdown})`
  518. : t('获取验证码')}
  519. </Button>
  520. }
  521. />
  522. <Form.Input
  523. field='verification_code'
  524. label={t('验证码')}
  525. placeholder={t('输入验证码')}
  526. name='verification_code'
  527. onChange={(value) =>
  528. handleChange('verification_code', value)
  529. }
  530. prefix={<IconKey />}
  531. />
  532. </>
  533. )}
  534. {(hasUserAgreement || hasPrivacyPolicy) && (
  535. <div className='pt-4'>
  536. <Checkbox
  537. checked={agreedToTerms}
  538. onChange={(e) => setAgreedToTerms(e.target.checked)}
  539. >
  540. <Text size='small' className='text-gray-600'>
  541. {t('我已阅读并同意')}
  542. {hasUserAgreement && (
  543. <>
  544. <a
  545. href='/user-agreement'
  546. target='_blank'
  547. rel='noopener noreferrer'
  548. className='text-blue-600 hover:text-blue-800 mx-1'
  549. >
  550. {t('用户协议')}
  551. </a>
  552. </>
  553. )}
  554. {hasUserAgreement && hasPrivacyPolicy && t('和')}
  555. {hasPrivacyPolicy && (
  556. <>
  557. <a
  558. href='/privacy-policy'
  559. target='_blank'
  560. rel='noopener noreferrer'
  561. className='text-blue-600 hover:text-blue-800 mx-1'
  562. >
  563. {t('隐私政策')}
  564. </a>
  565. </>
  566. )}
  567. </Text>
  568. </Checkbox>
  569. </div>
  570. )}
  571. <div className='space-y-2 pt-2'>
  572. <Button
  573. theme='solid'
  574. className='w-full !rounded-full'
  575. type='primary'
  576. htmlType='submit'
  577. onClick={handleSubmit}
  578. loading={registerLoading}
  579. disabled={(hasUserAgreement || hasPrivacyPolicy) && !agreedToTerms}
  580. >
  581. {t('注册')}
  582. </Button>
  583. </div>
  584. </Form>
  585. {(status.github_oauth ||
  586. status.discord_oauth ||
  587. status.oidc_enabled ||
  588. status.wechat_login ||
  589. status.linuxdo_oauth ||
  590. status.telegram_oauth) && (
  591. <>
  592. <Divider margin='12px' align='center'>
  593. {t('或')}
  594. </Divider>
  595. <div className='mt-4 text-center'>
  596. <Button
  597. theme='outline'
  598. type='tertiary'
  599. className='w-full !rounded-full'
  600. onClick={handleOtherRegisterOptionsClick}
  601. loading={otherRegisterOptionsLoading}
  602. >
  603. {t('其他注册选项')}
  604. </Button>
  605. </div>
  606. </>
  607. )}
  608. <div className='mt-6 text-center text-sm'>
  609. <Text>
  610. {t('已有账户?')}{' '}
  611. <Link
  612. to='/login'
  613. className='text-blue-600 hover:text-blue-800 font-medium'
  614. >
  615. {t('登录')}
  616. </Link>
  617. </Text>
  618. </div>
  619. </div>
  620. </Card>
  621. </div>
  622. </div>
  623. );
  624. };
  625. const renderWeChatLoginModal = () => {
  626. return (
  627. <Modal
  628. title={t('微信扫码登录')}
  629. visible={showWeChatLoginModal}
  630. maskClosable={true}
  631. onOk={onSubmitWeChatVerificationCode}
  632. onCancel={() => setShowWeChatLoginModal(false)}
  633. okText={t('登录')}
  634. centered={true}
  635. okButtonProps={{
  636. loading: wechatCodeSubmitLoading,
  637. }}
  638. >
  639. <div className='flex flex-col items-center'>
  640. <img src={status.wechat_qrcode} alt='微信二维码' className='mb-4' />
  641. </div>
  642. <div className='text-center mb-4'>
  643. <p>
  644. {t('微信扫码关注公众号,输入「验证码」获取验证码(三分钟内有效)')}
  645. </p>
  646. </div>
  647. <Form>
  648. <Form.Input
  649. field='wechat_verification_code'
  650. placeholder={t('验证码')}
  651. label={t('验证码')}
  652. value={inputs.wechat_verification_code}
  653. onChange={(value) =>
  654. handleChange('wechat_verification_code', value)
  655. }
  656. />
  657. </Form>
  658. </Modal>
  659. );
  660. };
  661. return (
  662. <div className='relative overflow-hidden bg-gray-100 flex items-center justify-center py-12 px-4 sm:px-6 lg:px-8'>
  663. {/* 背景模糊晕染球 */}
  664. <div
  665. className='blur-ball blur-ball-indigo'
  666. style={{ top: '-80px', right: '-80px', transform: 'none' }}
  667. />
  668. <div
  669. className='blur-ball blur-ball-teal'
  670. style={{ top: '50%', left: '-120px' }}
  671. />
  672. <div className='w-full max-w-sm mt-[60px]'>
  673. {showEmailRegister ||
  674. !(
  675. status.github_oauth ||
  676. status.discord_oauth ||
  677. status.oidc_enabled ||
  678. status.wechat_login ||
  679. status.linuxdo_oauth ||
  680. status.telegram_oauth
  681. )
  682. ? renderEmailRegisterForm()
  683. : renderOAuthOptions()}
  684. {renderWeChatLoginModal()}
  685. {turnstileEnabled && (
  686. <div className='flex justify-center mt-6'>
  687. <Turnstile
  688. sitekey={turnstileSiteKey}
  689. onVerify={(token) => {
  690. setTurnstileToken(token);
  691. }}
  692. />
  693. </div>
  694. )}
  695. </div>
  696. </div>
  697. );
  698. };
  699. export default RegisterForm;