mirror of
https://github.com/multipleof4/KalBot.git
synced 2026-03-16 21:41:02 +00:00
Feat: Login redirects to /dash
This commit is contained in:
151
app/page.js
151
app/page.js
@@ -3,105 +3,70 @@ import { useState, useRef } from 'react';
|
|||||||
import { useRouter } from 'next/navigation';
|
import { useRouter } from 'next/navigation';
|
||||||
|
|
||||||
export default function LoginPage() {
|
export default function LoginPage() {
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const [email, setEmail] = useState('');
|
const [email, setEmail] = useState('');
|
||||||
const [password, setPassword] = useState('');
|
const [password, setPassword] = useState('');
|
||||||
const [captcha, setCaptcha] = useState('');
|
const [captcha, setCaptcha] = useState('');
|
||||||
const [error, setError] = useState('');
|
const [error, setError] = useState('');
|
||||||
const [success, setSuccess] = useState('');
|
const [success, setSuccess] = useState('');
|
||||||
const captchaImgRef = useRef(null);
|
const captchaImgRef = useRef(null);
|
||||||
|
|
||||||
const refreshCaptcha = () => {
|
const refreshCaptcha = () => {
|
||||||
if (captchaImgRef.current) {
|
if (captchaImgRef.current) {
|
||||||
captchaImgRef.current.src = `/api/captcha?${new Date().getTime()}`;
|
captchaImgRef.current.src = `/api/captcha?${new Date().getTime()}`;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleLogin = async (e) => {
|
const handleLogin = async (e) => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
setError('');
|
setError('');
|
||||||
setSuccess('');
|
setSuccess('');
|
||||||
|
|
||||||
const res = await fetch('/api/login', {
|
const res = await fetch('/api/login', {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: { 'Content-Type': 'application/json' },
|
headers: { 'Content-Type': 'application/json' },
|
||||||
body: JSON.stringify({ email, password, captcha })
|
body: JSON.stringify({ email, password, captcha })
|
||||||
});
|
});
|
||||||
|
|
||||||
const data = await res.json();
|
const data = await res.json();
|
||||||
if (!res.ok) {
|
if (!res.ok) {
|
||||||
setError(data.error);
|
setError(data.error);
|
||||||
refreshCaptcha();
|
refreshCaptcha();
|
||||||
setCaptcha('');
|
setCaptcha('');
|
||||||
} else {
|
} else {
|
||||||
setSuccess(data.message);
|
setSuccess(data.message);
|
||||||
router.push('/paper');
|
router.push(data.redirect || '/dash');
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="min-h-screen flex items-center justify-center bg-gray-50 text-gray-900 font-sans">
|
<div className="min-h-screen flex items-center justify-center bg-gray-50 text-gray-900 font-sans">
|
||||||
<div className="bg-white p-8 rounded-lg shadow-xl w-full max-w-md border border-gray-100">
|
<div className="bg-white p-8 rounded-lg shadow-xl w-full max-w-md border border-gray-100">
|
||||||
<h1 className="text-2xl font-bold mb-6 text-center text-[#28CC95]">Kalbot Access</h1>
|
<h1 className="text-2xl font-bold mb-6 text-center text-[#28CC95]">Kalbot Access</h1>
|
||||||
|
|
||||||
{error && <div className="bg-red-50 border border-red-200 text-red-600 p-3 rounded mb-4 text-sm">{error}</div>}
|
{error && <div className="bg-red-50 border border-red-200 text-red-600 p-3 rounded mb-4 text-sm">{error}</div>}
|
||||||
{success && <div className="bg-green-50 border border-green-200 text-green-600 p-3 rounded mb-4 text-sm">{success}</div>}
|
{success && <div className="bg-green-50 border border-green-200 text-green-600 p-3 rounded mb-4 text-sm">{success}</div>}
|
||||||
|
|
||||||
<form onSubmit={handleLogin} className="space-y-4">
|
<form onSubmit={handleLogin} className="space-y-4">
|
||||||
<div>
|
<div>
|
||||||
<label className="block text-sm font-medium text-gray-700 mb-1">Email</label>
|
<label className="block text-sm font-medium text-gray-700 mb-1">Email</label>
|
||||||
<input
|
<input type="email" required className="w-full bg-white border border-gray-300 rounded px-3 py-2 focus:outline-none focus:border-[#28CC95] focus:ring-1 focus:ring-[#28CC95] transition-shadow" value={email} onChange={(e) => setEmail(e.target.value)} />
|
||||||
type="email"
|
</div>
|
||||||
required
|
<div>
|
||||||
className="w-full bg-white border border-gray-300 rounded px-3 py-2 focus:outline-none focus:border-[#28CC95] focus:ring-1 focus:ring-[#28CC95] transition-shadow"
|
<label className="block text-sm font-medium text-gray-700 mb-1">Password</label>
|
||||||
value={email}
|
<input type="password" required className="w-full bg-white border border-gray-300 rounded px-3 py-2 focus:outline-none focus:border-[#28CC95] focus:ring-1 focus:ring-[#28CC95] transition-shadow" value={password} onChange={(e) => setPassword(e.target.value)} />
|
||||||
onChange={(e) => setEmail(e.target.value)}
|
</div>
|
||||||
/>
|
<div>
|
||||||
</div>
|
<label className="block text-sm font-medium text-gray-700 mb-1">Captcha Verification</label>
|
||||||
<div>
|
<div className="flex items-center space-x-3 mb-2">
|
||||||
<label className="block text-sm font-medium text-gray-700 mb-1">Password</label>
|
<img ref={captchaImgRef} src="/api/captcha" alt="captcha" className="h-12 rounded cursor-pointer border border-gray-300" onClick={refreshCaptcha} title="Click to refresh" />
|
||||||
<input
|
<button type="button" onClick={refreshCaptcha} className="text-sm font-medium text-[#28CC95] hover:opacity-80 transition-opacity">Refresh</button>
|
||||||
type="password"
|
|
||||||
required
|
|
||||||
className="w-full bg-white border border-gray-300 rounded px-3 py-2 focus:outline-none focus:border-[#28CC95] focus:ring-1 focus:ring-[#28CC95] transition-shadow"
|
|
||||||
value={password}
|
|
||||||
onChange={(e) => setPassword(e.target.value)}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div>
|
|
||||||
<label className="block text-sm font-medium text-gray-700 mb-1">Captcha Verification</label>
|
|
||||||
<div className="flex items-center space-x-3 mb-2">
|
|
||||||
<img
|
|
||||||
ref={captchaImgRef}
|
|
||||||
src="/api/captcha"
|
|
||||||
alt="captcha"
|
|
||||||
className="h-12 rounded cursor-pointer border border-gray-300"
|
|
||||||
onClick={refreshCaptcha}
|
|
||||||
title="Click to refresh"
|
|
||||||
/>
|
|
||||||
<button type="button" onClick={refreshCaptcha} className="text-sm font-medium text-[#28CC95] hover:opacity-80 transition-opacity">
|
|
||||||
Refresh
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
<input
|
|
||||||
type="text"
|
|
||||||
required
|
|
||||||
placeholder="Enter the text above"
|
|
||||||
className="w-full bg-white border border-gray-300 rounded px-3 py-2 focus:outline-none focus:border-[#28CC95] focus:ring-1 focus:ring-[#28CC95] transition-shadow"
|
|
||||||
value={captcha}
|
|
||||||
onChange={(e) => setCaptcha(e.target.value)}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<button
|
|
||||||
type="submit"
|
|
||||||
className="w-full bg-[#28CC95] hover:brightness-95 text-white font-bold py-2 px-4 rounded transition-all mt-6 shadow-sm"
|
|
||||||
>
|
|
||||||
Login
|
|
||||||
</button>
|
|
||||||
</form>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
<input type="text" required placeholder="Enter the text above" className="w-full bg-white border border-gray-300 rounded px-3 py-2 focus:outline-none focus:border-[#28CC95] focus:ring-1 focus:ring-[#28CC95] transition-shadow" value={captcha} onChange={(e) => setCaptcha(e.target.value)} />
|
||||||
);
|
</div>
|
||||||
|
<button type="submit" className="w-full bg-[#28CC95] hover:brightness-95 text-white font-bold py-2 px-4 rounded transition-all mt-6 shadow-sm">Login</button>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user