mirror of
https://github.com/laoxong/nofx.git
synced 2026-06-04 09:58:22 +08:00
fix: Fixed redundant key input fields and corrected formatting on the frontend. (#566)
* Eliminate redundant key input fields in the front-end. * go / react Formatting.
This commit is contained in:
@@ -16,7 +16,7 @@ import (
|
||||
"strings"
|
||||
"syscall"
|
||||
|
||||
"github.com/joho/godotenv"
|
||||
"github.com/joho/godotenv"
|
||||
)
|
||||
|
||||
// LeverageConfig 杠杆配置
|
||||
@@ -225,7 +225,6 @@ func main() {
|
||||
log.Printf("✓ Admin mode enabled. All API endpoints require admin authentication.")
|
||||
}
|
||||
|
||||
|
||||
log.Printf("✓ 配置数据库初始化成功")
|
||||
fmt.Println()
|
||||
|
||||
|
||||
@@ -1936,28 +1936,6 @@ function ExchangeConfigModal({
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label
|
||||
className="block text-sm font-semibold mb-2"
|
||||
style={{ color: '#EAECEF' }}
|
||||
>
|
||||
{t('secretKey', language)}
|
||||
</label>
|
||||
<input
|
||||
type="password"
|
||||
value={secretKey}
|
||||
onChange={(e) => setSecretKey(e.target.value)}
|
||||
placeholder={t('enterSecretKey', language)}
|
||||
className="w-full px-3 py-2 rounded"
|
||||
style={{
|
||||
background: '#0B0E11',
|
||||
border: '1px solid #2B3139',
|
||||
color: '#EAECEF',
|
||||
}}
|
||||
required
|
||||
/>
|
||||
</div>
|
||||
|
||||
{selectedExchange.id === 'okx' && (
|
||||
<div>
|
||||
<label
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import React, { useEffect, useState } from 'react';
|
||||
import React, { useEffect, useState } from 'react'
|
||||
import { useAuth } from '../contexts/AuthContext'
|
||||
import { useLanguage } from '../contexts/LanguageContext'
|
||||
import { t } from '../i18n/translations'
|
||||
import HeaderBar from './landing/HeaderBar'
|
||||
import { getSystemConfig } from '../lib/config';
|
||||
import { getSystemConfig } from '../lib/config'
|
||||
|
||||
export function LoginPage() {
|
||||
const { language } = useLanguage()
|
||||
@@ -15,30 +15,29 @@ export function LoginPage() {
|
||||
const [userID, setUserID] = useState('')
|
||||
const [error, setError] = useState('')
|
||||
const [loading, setLoading] = useState(false)
|
||||
const [adminPassword, setAdminPassword] = useState('');
|
||||
const [adminMode, setAdminMode] = useState<boolean | null>(null);
|
||||
const [adminPassword, setAdminPassword] = useState('')
|
||||
const [adminMode, setAdminMode] = useState<boolean | null>(null)
|
||||
|
||||
useEffect(() => {
|
||||
getSystemConfig()
|
||||
.then((cfg) => {
|
||||
setAdminMode(!!cfg.admin_mode);
|
||||
setAdminMode(!!cfg.admin_mode)
|
||||
})
|
||||
.catch(() => {
|
||||
setAdminMode(false);
|
||||
});
|
||||
}, []);
|
||||
setAdminMode(false)
|
||||
})
|
||||
}, [])
|
||||
|
||||
const handleAdminLogin = async (e: React.FormEvent) => {
|
||||
e.preventDefault();
|
||||
setError('');
|
||||
setLoading(true);
|
||||
const result = await loginAdmin(adminPassword);
|
||||
e.preventDefault()
|
||||
setError('')
|
||||
setLoading(true)
|
||||
const result = await loginAdmin(adminPassword)
|
||||
if (!result.success) {
|
||||
setError(result.message || t('loginFailed', language));
|
||||
setError(result.message || t('loginFailed', language))
|
||||
}
|
||||
setLoading(false);
|
||||
};
|
||||
|
||||
setLoading(false)
|
||||
}
|
||||
|
||||
const handleLogin = async (e: React.FormEvent) => {
|
||||
e.preventDefault()
|
||||
@@ -127,39 +126,55 @@ export function LoginPage() {
|
||||
border: '1px solid var(--panel-border)',
|
||||
}}
|
||||
>
|
||||
{adminMode ? (
|
||||
<form onSubmit={handleAdminLogin} className="space-y-4">
|
||||
<div>
|
||||
<label className="block text-sm font-semibold mb-2" style={{ color: 'var(--brand-light-gray)' }}>
|
||||
管理员密码
|
||||
</label>
|
||||
<input
|
||||
type="password"
|
||||
value={adminPassword}
|
||||
onChange={(e) => setAdminPassword(e.target.value)}
|
||||
className="w-full px-3 py-2 rounded"
|
||||
style={{ background: 'var(--brand-black)', border: '1px solid var(--panel-border)', color: 'var(--brand-light-gray)' }}
|
||||
placeholder="请输入管理员密码"
|
||||
required
|
||||
/>
|
||||
</div>
|
||||
|
||||
{error && (
|
||||
<div className="text-sm px-3 py-2 rounded" style={{ background: 'var(--binance-red-bg)', color: 'var(--binance-red)' }}>
|
||||
{error}
|
||||
{adminMode ? (
|
||||
<form onSubmit={handleAdminLogin} className="space-y-4">
|
||||
<div>
|
||||
<label
|
||||
className="block text-sm font-semibold mb-2"
|
||||
style={{ color: 'var(--brand-light-gray)' }}
|
||||
>
|
||||
管理员密码
|
||||
</label>
|
||||
<input
|
||||
type="password"
|
||||
value={adminPassword}
|
||||
onChange={(e) => setAdminPassword(e.target.value)}
|
||||
className="w-full px-3 py-2 rounded"
|
||||
style={{
|
||||
background: 'var(--brand-black)',
|
||||
border: '1px solid var(--panel-border)',
|
||||
color: 'var(--brand-light-gray)',
|
||||
}}
|
||||
placeholder="请输入管理员密码"
|
||||
required
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
|
||||
<button
|
||||
type="submit"
|
||||
disabled={loading}
|
||||
className="w-full px-4 py-2 rounded text-sm font-semibold transition-all hover:scale-105 disabled:opacity-50"
|
||||
style={{ background: 'var(--brand-yellow)', color: 'var(--brand-black)' }}
|
||||
>
|
||||
{loading ? t('loading', language) : '登录'}
|
||||
</button>
|
||||
</form>
|
||||
) : step === 'login' ? (
|
||||
{error && (
|
||||
<div
|
||||
className="text-sm px-3 py-2 rounded"
|
||||
style={{
|
||||
background: 'var(--binance-red-bg)',
|
||||
color: 'var(--binance-red)',
|
||||
}}
|
||||
>
|
||||
{error}
|
||||
</div>
|
||||
)}
|
||||
|
||||
<button
|
||||
type="submit"
|
||||
disabled={loading}
|
||||
className="w-full px-4 py-2 rounded text-sm font-semibold transition-all hover:scale-105 disabled:opacity-50"
|
||||
style={{
|
||||
background: 'var(--brand-yellow)',
|
||||
color: 'var(--brand-black)',
|
||||
}}
|
||||
>
|
||||
{loading ? t('loading', language) : '登录'}
|
||||
</button>
|
||||
</form>
|
||||
) : step === 'login' ? (
|
||||
<form onSubmit={handleLogin} className="space-y-4">
|
||||
<div>
|
||||
<label
|
||||
|
||||
@@ -1,63 +1,66 @@
|
||||
import React, { useState } from 'react';
|
||||
import { useAuth } from '../contexts/AuthContext';
|
||||
import { useLanguage } from '../contexts/LanguageContext';
|
||||
import { t } from '../i18n/translations';
|
||||
import { Header } from './Header';
|
||||
import { ArrowLeft, KeyRound, Eye, EyeOff } from 'lucide-react';
|
||||
import React, { useState } from 'react'
|
||||
import { useAuth } from '../contexts/AuthContext'
|
||||
import { useLanguage } from '../contexts/LanguageContext'
|
||||
import { t } from '../i18n/translations'
|
||||
import { Header } from './Header'
|
||||
import { ArrowLeft, KeyRound, Eye, EyeOff } from 'lucide-react'
|
||||
|
||||
export function ResetPasswordPage() {
|
||||
const { language } = useLanguage();
|
||||
const { resetPassword } = useAuth();
|
||||
const [email, setEmail] = useState('');
|
||||
const [newPassword, setNewPassword] = useState('');
|
||||
const [confirmPassword, setConfirmPassword] = useState('');
|
||||
const [otpCode, setOtpCode] = useState('');
|
||||
const [error, setError] = useState('');
|
||||
const [success, setSuccess] = useState(false);
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [showPassword, setShowPassword] = useState(false);
|
||||
const [showConfirmPassword, setShowConfirmPassword] = useState(false);
|
||||
const { language } = useLanguage()
|
||||
const { resetPassword } = useAuth()
|
||||
const [email, setEmail] = useState('')
|
||||
const [newPassword, setNewPassword] = useState('')
|
||||
const [confirmPassword, setConfirmPassword] = useState('')
|
||||
const [otpCode, setOtpCode] = useState('')
|
||||
const [error, setError] = useState('')
|
||||
const [success, setSuccess] = useState(false)
|
||||
const [loading, setLoading] = useState(false)
|
||||
const [showPassword, setShowPassword] = useState(false)
|
||||
const [showConfirmPassword, setShowConfirmPassword] = useState(false)
|
||||
|
||||
const handleResetPassword = async (e: React.FormEvent) => {
|
||||
e.preventDefault();
|
||||
setError('');
|
||||
setSuccess(false);
|
||||
e.preventDefault()
|
||||
setError('')
|
||||
setSuccess(false)
|
||||
|
||||
// 验证两次密码是否一致
|
||||
if (newPassword !== confirmPassword) {
|
||||
setError(t('passwordMismatch', language));
|
||||
return;
|
||||
setError(t('passwordMismatch', language))
|
||||
return
|
||||
}
|
||||
|
||||
setLoading(true);
|
||||
setLoading(true)
|
||||
|
||||
const result = await resetPassword(email, newPassword, otpCode);
|
||||
const result = await resetPassword(email, newPassword, otpCode)
|
||||
|
||||
if (result.success) {
|
||||
setSuccess(true);
|
||||
setSuccess(true)
|
||||
// 3秒后跳转到登录页面
|
||||
setTimeout(() => {
|
||||
window.history.pushState({}, '', '/login');
|
||||
window.dispatchEvent(new PopStateEvent('popstate'));
|
||||
}, 3000);
|
||||
window.history.pushState({}, '', '/login')
|
||||
window.dispatchEvent(new PopStateEvent('popstate'))
|
||||
}, 3000)
|
||||
} else {
|
||||
setError(result.message || t('resetPasswordFailed', language));
|
||||
setError(result.message || t('resetPasswordFailed', language))
|
||||
}
|
||||
|
||||
setLoading(false);
|
||||
};
|
||||
setLoading(false)
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="min-h-screen" style={{ background: '#0B0E11' }}>
|
||||
<Header simple />
|
||||
|
||||
<div className="flex items-center justify-center" style={{ minHeight: 'calc(100vh - 80px)' }}>
|
||||
<div
|
||||
className="flex items-center justify-center"
|
||||
style={{ minHeight: 'calc(100vh - 80px)' }}
|
||||
>
|
||||
<div className="w-full max-w-md">
|
||||
{/* Back to Login */}
|
||||
<button
|
||||
onClick={() => {
|
||||
window.history.pushState({}, '', '/login');
|
||||
window.dispatchEvent(new PopStateEvent('popstate'));
|
||||
window.history.pushState({}, '', '/login')
|
||||
window.dispatchEvent(new PopStateEvent('popstate'))
|
||||
}}
|
||||
className="flex items-center gap-2 mb-6 text-sm hover:text-[#F0B90B] transition-colors"
|
||||
style={{ color: '#848E9C' }}
|
||||
@@ -68,7 +71,10 @@ export function ResetPasswordPage() {
|
||||
|
||||
{/* Logo */}
|
||||
<div className="text-center mb-8">
|
||||
<div className="w-16 h-16 mx-auto mb-4 flex items-center justify-center rounded-full" style={{ background: 'rgba(240, 185, 11, 0.1)' }}>
|
||||
<div
|
||||
className="w-16 h-16 mx-auto mb-4 flex items-center justify-center rounded-full"
|
||||
style={{ background: 'rgba(240, 185, 11, 0.1)' }}
|
||||
>
|
||||
<KeyRound className="w-8 h-8" style={{ color: '#F0B90B' }} />
|
||||
</div>
|
||||
<h1 className="text-2xl font-bold" style={{ color: '#EAECEF' }}>
|
||||
@@ -80,11 +86,17 @@ export function ResetPasswordPage() {
|
||||
</div>
|
||||
|
||||
{/* Reset Password Form */}
|
||||
<div className="rounded-lg p-6" style={{ background: '#1E2329', border: '1px solid #2B3139' }}>
|
||||
<div
|
||||
className="rounded-lg p-6"
|
||||
style={{ background: '#1E2329', border: '1px solid #2B3139' }}
|
||||
>
|
||||
{success ? (
|
||||
<div className="text-center py-8">
|
||||
<div className="text-5xl mb-4">✅</div>
|
||||
<p className="text-lg font-semibold mb-2" style={{ color: '#EAECEF' }}>
|
||||
<p
|
||||
className="text-lg font-semibold mb-2"
|
||||
style={{ color: '#EAECEF' }}
|
||||
>
|
||||
{t('resetPasswordSuccess', language)}
|
||||
</p>
|
||||
<p className="text-sm" style={{ color: '#848E9C' }}>
|
||||
@@ -94,7 +106,10 @@ export function ResetPasswordPage() {
|
||||
) : (
|
||||
<form onSubmit={handleResetPassword} className="space-y-4">
|
||||
<div>
|
||||
<label className="block text-sm font-semibold mb-2" style={{ color: '#EAECEF' }}>
|
||||
<label
|
||||
className="block text-sm font-semibold mb-2"
|
||||
style={{ color: '#EAECEF' }}
|
||||
>
|
||||
{t('email', language)}
|
||||
</label>
|
||||
<input
|
||||
@@ -102,14 +117,21 @@ export function ResetPasswordPage() {
|
||||
value={email}
|
||||
onChange={(e) => setEmail(e.target.value)}
|
||||
className="w-full px-3 py-2 rounded"
|
||||
style={{ background: '#0B0E11', border: '1px solid #2B3139', color: '#EAECEF' }}
|
||||
style={{
|
||||
background: '#0B0E11',
|
||||
border: '1px solid #2B3139',
|
||||
color: '#EAECEF',
|
||||
}}
|
||||
placeholder={t('emailPlaceholder', language)}
|
||||
required
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label className="block text-sm font-semibold mb-2" style={{ color: '#EAECEF' }}>
|
||||
<label
|
||||
className="block text-sm font-semibold mb-2"
|
||||
style={{ color: '#EAECEF' }}
|
||||
>
|
||||
{t('newPassword', language)}
|
||||
</label>
|
||||
<div className="relative">
|
||||
@@ -118,7 +140,11 @@ export function ResetPasswordPage() {
|
||||
value={newPassword}
|
||||
onChange={(e) => setNewPassword(e.target.value)}
|
||||
className="w-full px-3 py-2 pr-10 rounded"
|
||||
style={{ background: '#0B0E11', border: '1px solid #2B3139', color: '#EAECEF' }}
|
||||
style={{
|
||||
background: '#0B0E11',
|
||||
border: '1px solid #2B3139',
|
||||
color: '#EAECEF',
|
||||
}}
|
||||
placeholder={t('newPasswordPlaceholder', language)}
|
||||
required
|
||||
minLength={6}
|
||||
@@ -128,13 +154,20 @@ export function ResetPasswordPage() {
|
||||
onClick={() => setShowPassword(!showPassword)}
|
||||
className="absolute right-3 top-1/2 -translate-y-1/2 text-gray-400 hover:text-gray-300"
|
||||
>
|
||||
{showPassword ? <EyeOff className="w-5 h-5" /> : <Eye className="w-5 h-5" />}
|
||||
{showPassword ? (
|
||||
<EyeOff className="w-5 h-5" />
|
||||
) : (
|
||||
<Eye className="w-5 h-5" />
|
||||
)}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label className="block text-sm font-semibold mb-2" style={{ color: '#EAECEF' }}>
|
||||
<label
|
||||
className="block text-sm font-semibold mb-2"
|
||||
style={{ color: '#EAECEF' }}
|
||||
>
|
||||
{t('confirmPassword', language)}
|
||||
</label>
|
||||
<div className="relative">
|
||||
@@ -143,23 +176,36 @@ export function ResetPasswordPage() {
|
||||
value={confirmPassword}
|
||||
onChange={(e) => setConfirmPassword(e.target.value)}
|
||||
className="w-full px-3 py-2 pr-10 rounded"
|
||||
style={{ background: '#0B0E11', border: '1px solid #2B3139', color: '#EAECEF' }}
|
||||
style={{
|
||||
background: '#0B0E11',
|
||||
border: '1px solid #2B3139',
|
||||
color: '#EAECEF',
|
||||
}}
|
||||
placeholder={t('confirmPasswordPlaceholder', language)}
|
||||
required
|
||||
minLength={6}
|
||||
/>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => setShowConfirmPassword(!showConfirmPassword)}
|
||||
onClick={() =>
|
||||
setShowConfirmPassword(!showConfirmPassword)
|
||||
}
|
||||
className="absolute right-3 top-1/2 -translate-y-1/2 text-gray-400 hover:text-gray-300"
|
||||
>
|
||||
{showConfirmPassword ? <EyeOff className="w-5 h-5" /> : <Eye className="w-5 h-5" />}
|
||||
{showConfirmPassword ? (
|
||||
<EyeOff className="w-5 h-5" />
|
||||
) : (
|
||||
<Eye className="w-5 h-5" />
|
||||
)}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label className="block text-sm font-semibold mb-2" style={{ color: '#EAECEF' }}>
|
||||
<label
|
||||
className="block text-sm font-semibold mb-2"
|
||||
style={{ color: '#EAECEF' }}
|
||||
>
|
||||
{t('otpCode', language)}
|
||||
</label>
|
||||
<div className="text-center mb-3">
|
||||
@@ -171,9 +217,15 @@ export function ResetPasswordPage() {
|
||||
<input
|
||||
type="text"
|
||||
value={otpCode}
|
||||
onChange={(e) => setOtpCode(e.target.value.replace(/\D/g, '').slice(0, 6))}
|
||||
onChange={(e) =>
|
||||
setOtpCode(e.target.value.replace(/\D/g, '').slice(0, 6))
|
||||
}
|
||||
className="w-full px-3 py-2 rounded text-center text-2xl font-mono"
|
||||
style={{ background: '#0B0E11', border: '1px solid #2B3139', color: '#EAECEF' }}
|
||||
style={{
|
||||
background: '#0B0E11',
|
||||
border: '1px solid #2B3139',
|
||||
color: '#EAECEF',
|
||||
}}
|
||||
placeholder={t('otpPlaceholder', language)}
|
||||
maxLength={6}
|
||||
required
|
||||
@@ -181,7 +233,13 @@ export function ResetPasswordPage() {
|
||||
</div>
|
||||
|
||||
{error && (
|
||||
<div className="text-sm px-3 py-2 rounded" style={{ background: 'rgba(246, 70, 93, 0.1)', color: '#F6465D' }}>
|
||||
<div
|
||||
className="text-sm px-3 py-2 rounded"
|
||||
style={{
|
||||
background: 'rgba(246, 70, 93, 0.1)',
|
||||
color: '#F6465D',
|
||||
}}
|
||||
>
|
||||
{error}
|
||||
</div>
|
||||
)}
|
||||
@@ -192,7 +250,9 @@ export function ResetPasswordPage() {
|
||||
className="w-full px-4 py-2 rounded text-sm font-semibold transition-all hover:scale-105 disabled:opacity-50"
|
||||
style={{ background: '#F0B90B', color: '#000' }}
|
||||
>
|
||||
{loading ? t('loading', language) : t('resetPasswordButton', language)}
|
||||
{loading
|
||||
? t('loading', language)
|
||||
: t('resetPasswordButton', language)}
|
||||
</button>
|
||||
</form>
|
||||
)}
|
||||
@@ -200,5 +260,5 @@ export function ResetPasswordPage() {
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
)
|
||||
}
|
||||
|
||||
@@ -478,14 +478,16 @@ export default function HeaderBar({
|
||||
</a>
|
||||
{!isAdminMode && (
|
||||
<a
|
||||
href='/register'
|
||||
className='px-4 py-2 rounded font-semibold text-sm transition-colors hover:opacity-90'
|
||||
style={{ background: 'var(--brand-yellow)', color: 'var(--brand-black)' }}
|
||||
href="/register"
|
||||
className="px-4 py-2 rounded font-semibold text-sm transition-colors hover:opacity-90"
|
||||
style={{
|
||||
background: 'var(--brand-yellow)',
|
||||
color: 'var(--brand-black)',
|
||||
}}
|
||||
>
|
||||
{t('signUp', language)}
|
||||
{t('signUp', language)}
|
||||
</a>
|
||||
)}
|
||||
|
||||
</div>
|
||||
)
|
||||
)}
|
||||
|
||||
@@ -18,12 +18,10 @@ interface AuthContextType {
|
||||
userID?: string
|
||||
requiresOTP?: boolean
|
||||
}>
|
||||
loginAdmin: (
|
||||
password: string
|
||||
) => Promise<{
|
||||
success: boolean;
|
||||
message?: string
|
||||
}>;
|
||||
loginAdmin: (password: string) => Promise<{
|
||||
success: boolean
|
||||
message?: string
|
||||
}>
|
||||
register: (
|
||||
email: string,
|
||||
password: string,
|
||||
@@ -64,11 +62,11 @@ export function AuthProvider({ children }: { children: React.ReactNode }) {
|
||||
getSystemConfig()
|
||||
.then(() => {
|
||||
// 不再在管理员模式下模拟登录;统一检查本地存储
|
||||
const savedToken = localStorage.getItem('auth_token');
|
||||
const savedUser = localStorage.getItem('auth_user');
|
||||
const savedToken = localStorage.getItem('auth_token')
|
||||
const savedUser = localStorage.getItem('auth_user')
|
||||
if (savedToken && savedUser) {
|
||||
setToken(savedToken);
|
||||
setUser(JSON.parse(savedUser));
|
||||
setToken(savedToken)
|
||||
setUser(JSON.parse(savedUser))
|
||||
}
|
||||
|
||||
setIsLoading(false)
|
||||
@@ -118,31 +116,34 @@ export function AuthProvider({ children }: { children: React.ReactNode }) {
|
||||
return { success: false, message: '未知错误' }
|
||||
}
|
||||
|
||||
const loginAdmin = async (password: string) => {
|
||||
const loginAdmin = async (password: string) => {
|
||||
try {
|
||||
const response = await fetch('/api/admin-login', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ password }),
|
||||
});
|
||||
const data = await response.json();
|
||||
})
|
||||
const data = await response.json()
|
||||
if (response.ok) {
|
||||
const userInfo = { id: data.user_id || 'admin', email: data.email || 'admin@localhost' };
|
||||
setToken(data.token);
|
||||
setUser(userInfo);
|
||||
localStorage.setItem('auth_token', data.token);
|
||||
localStorage.setItem('auth_user', JSON.stringify(userInfo));
|
||||
const userInfo = {
|
||||
id: data.user_id || 'admin',
|
||||
email: data.email || 'admin@localhost',
|
||||
}
|
||||
setToken(data.token)
|
||||
setUser(userInfo)
|
||||
localStorage.setItem('auth_token', data.token)
|
||||
localStorage.setItem('auth_user', JSON.stringify(userInfo))
|
||||
// 跳转到仪表盘
|
||||
window.history.pushState({}, '', '/dashboard');
|
||||
window.dispatchEvent(new PopStateEvent('popstate'));
|
||||
return { success: true };
|
||||
window.history.pushState({}, '', '/dashboard')
|
||||
window.dispatchEvent(new PopStateEvent('popstate'))
|
||||
return { success: true }
|
||||
} else {
|
||||
return { success: false, message: data.error || '登录失败' };
|
||||
return { success: false, message: data.error || '登录失败' }
|
||||
}
|
||||
} catch (e) {
|
||||
return { success: false, message: '登录失败,请重试' };
|
||||
return { success: false, message: '登录失败,请重试' }
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
const register = async (
|
||||
email: string,
|
||||
@@ -282,12 +283,14 @@ export function AuthProvider({ children }: { children: React.ReactNode }) {
|
||||
}
|
||||
|
||||
const logout = () => {
|
||||
const savedToken = localStorage.getItem('auth_token');
|
||||
const savedToken = localStorage.getItem('auth_token')
|
||||
if (savedToken) {
|
||||
fetch('/api/logout', {
|
||||
method: 'POST',
|
||||
headers: { 'Authorization': `Bearer ${savedToken}` },
|
||||
}).catch(() => {/* ignore network errors on logout */});
|
||||
headers: { Authorization: `Bearer ${savedToken}` },
|
||||
}).catch(() => {
|
||||
/* ignore network errors on logout */
|
||||
})
|
||||
}
|
||||
setUser(null)
|
||||
setToken(null)
|
||||
@@ -301,7 +304,7 @@ export function AuthProvider({ children }: { children: React.ReactNode }) {
|
||||
user,
|
||||
token,
|
||||
login,
|
||||
loginAdmin,
|
||||
loginAdmin,
|
||||
register,
|
||||
verifyOTP,
|
||||
completeRegistration,
|
||||
|
||||
@@ -342,7 +342,8 @@ export const translations = {
|
||||
newPassword: 'New Password',
|
||||
newPasswordPlaceholder: 'Enter new password (at least 6 characters)',
|
||||
resetPasswordButton: 'Reset Password',
|
||||
resetPasswordSuccess: 'Password reset successful! Please login with your new password',
|
||||
resetPasswordSuccess:
|
||||
'Password reset successful! Please login with your new password',
|
||||
resetPasswordFailed: 'Password reset failed',
|
||||
backToLogin: 'Back to Login',
|
||||
scanQRCode: 'Scan QR Code',
|
||||
|
||||
@@ -14,7 +14,11 @@ import { useAuth } from '../contexts/AuthContext'
|
||||
import { useLanguage } from '../contexts/LanguageContext'
|
||||
import { t } from '../i18n/translations'
|
||||
|
||||
export function LandingPage({ isAdminMode = false }: { isAdminMode?: boolean }) {
|
||||
export function LandingPage({
|
||||
isAdminMode = false,
|
||||
}: {
|
||||
isAdminMode?: boolean
|
||||
}) {
|
||||
const [showLoginModal, setShowLoginModal] = useState(false)
|
||||
const { user, logout } = useAuth()
|
||||
const { language, setLanguage } = useLanguage()
|
||||
@@ -31,7 +35,7 @@ export function LandingPage({ isAdminMode = false }: { isAdminMode?: boolean })
|
||||
onLanguageChange={setLanguage}
|
||||
user={user}
|
||||
onLogout={logout}
|
||||
isAdminMode={isAdminMode}
|
||||
isAdminMode={isAdminMode}
|
||||
onPageChange={(page) => {
|
||||
console.log('LandingPage onPageChange called with:', page)
|
||||
if (page === 'competition') {
|
||||
|
||||
Reference in New Issue
Block a user