/* Copyright (C) 2025 QuantumNous This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. You should have received a copy of the GNU Affero General Public License along with this program. If not, see . For commercial licensing, please contact support@quantumnous.com */ import React, { useState } from 'react'; import { Button, Popover, Typography, Modal } from '@douyinfe/semi-ui'; import { IconMail, IconShield, IconGithubLogo } from '@douyinfe/semi-icons'; import { Link2, ExternalLink, Check, X } from 'lucide-react'; import { TelegramBrandIcon, WechatBrandIcon, LinuxBrandIcon, DiscordBrandIcon, } from '../../../common/icons/BrandIcons'; import TelegramLoginButton from 'react-telegram-login'; import { onGitHubOAuthClicked, onOIDCClicked, onLinuxDOOAuthClicked, onDiscordOAuthClicked, } from '../../../../helpers'; // 绑定卡片配置 const BINDING_CARDS = [ { key: 'email', icon: IconMail, gradient: 'from-blue-500 to-cyan-500', panelClass: 'bg-gradient-to-br from-blue-50/78 to-cyan-50/70 dark:from-blue-500/[0.09] dark:to-cyan-400/[0.07]', }, { key: 'wechat', icon: WechatBrandIcon, gradient: 'from-green-500 to-emerald-500', panelClass: 'bg-gradient-to-br from-green-50/78 to-emerald-50/70 dark:from-green-500/[0.09] dark:to-emerald-400/[0.07]', isBrandIcon: true, }, { key: 'github', icon: IconGithubLogo, gradient: 'from-gray-700 to-gray-900', panelClass: 'bg-gradient-to-br from-gray-50/88 to-slate-50/75 dark:from-slate-500/[0.10] dark:to-slate-700/[0.10]', }, { key: 'discord', icon: DiscordBrandIcon, gradient: 'from-brand-from to-brand-to', panelClass: 'bg-gradient-to-br from-brand-from/10 to-brand-to/10 dark:from-brand-from/[0.14] dark:to-brand-to/[0.12]', isBrandIcon: true, }, { key: 'oidc', icon: IconShield, gradient: 'from-orange-500 to-red-500', panelClass: 'bg-gradient-to-br from-orange-50/78 to-red-50/70 dark:from-orange-500/[0.10] dark:to-red-500/[0.08]', }, { key: 'telegram', icon: TelegramBrandIcon, gradient: 'from-sky-500 to-blue-500', panelClass: 'bg-gradient-to-br from-sky-50/78 to-blue-50/70 dark:from-sky-500/[0.10] dark:to-blue-500/[0.08]', isBrandIcon: true, }, { key: 'linuxdo', icon: LinuxBrandIcon, gradient: 'from-yellow-500 to-orange-500', panelClass: 'bg-gradient-to-br from-yellow-50/78 to-orange-50/70 dark:from-yellow-500/[0.10] dark:to-orange-500/[0.08]', isBrandIcon: true, }, ]; const AccountBindingSection = ({ t, userState, status, setShowEmailBindModal, setShowWeChatBindModal, }) => { const [showTelegramBindModal, setShowTelegramBindModal] = useState(false); const isBound = (accountId) => Boolean(accountId); const renderAccountInfo = (accountId, label) => { if (!accountId || accountId === '') { return {t('未绑定')}; } const popContent = (
{accountId} {label &&
{label}
}
); return ( {accountId} ); }; const getBindingData = (key) => { switch (key) { case 'email': return { name: t('邮箱'), value: userState.user?.email, label: t('邮箱地址'), enabled: true, onBind: () => setShowEmailBindModal(true), }; case 'wechat': return { name: t('微信'), value: userState.user?.wechat_id, label: t('微信账号'), enabled: status.wechat_login, onBind: () => setShowWeChatBindModal(true), }; case 'github': return { name: 'GitHub', value: userState.user?.github_id, label: 'GitHub ID', enabled: status.github_oauth, onBind: () => onGitHubOAuthClicked(status.github_client_id), disableWhenBound: true, }; case 'discord': return { name: 'Discord', value: userState.user?.discord_id, label: 'Discord ID', enabled: status.discord_oauth, onBind: () => onDiscordOAuthClicked(status.discord_client_id), disableWhenBound: true, }; case 'oidc': return { name: 'OIDC', value: userState.user?.oidc_id, label: 'OIDC ID', enabled: status.oidc_enabled, onBind: () => onOIDCClicked( status.oidc_authorization_endpoint, status.oidc_client_id, ), disableWhenBound: true, }; case 'telegram': return { name: 'Telegram', value: userState.user?.telegram_id, label: 'Telegram ID', enabled: status.telegram_oauth, onBind: () => setShowTelegramBindModal(true), disableWhenBound: true, }; case 'linuxdo': return { name: 'LinuxDO', value: userState.user?.linux_do_id, label: 'LinuxDO ID', enabled: status.linuxdo_oauth, onBind: () => onLinuxDOOAuthClicked(status.linuxdo_client_id), disableWhenBound: true, }; default: return null; } }; return (
{/* 页面标题 */}

{t('账号绑定')}

{t('管理邮箱和第三方登录方式')}

{/* 绑定卡片网格 */}
{BINDING_CARDS.map((card) => { const data = getBindingData(card.key); if (!data) return null; // 未启用的绑定方式不显示卡片 if (!data.enabled) return null; const Icon = card.icon; const bound = isBound(data.value); const disabled = data.disableWhenBound && bound; return (
{/* 状态指示器 */}
{bound ? (
{t('已绑定')}
) : (
{t('未绑定')}
)}
{/* 图标和名称 */}
{card.isBrandIcon ? ( ) : ( )}

{data.name}

{bound ? renderAccountInfo(data.value, data.label) : null}
{/* 操作按钮 */}
); })}
{/* Telegram 绑定弹窗 */} setShowTelegramBindModal(false)} footer={null} >
{t('点击下方按钮通过 Telegram 完成绑定')}
); }; export default AccountBindingSection;