FIIIIIXX
This commit is contained in:
48
frontend/style/app/login/page.tsx
Normal file
48
frontend/style/app/login/page.tsx
Normal file
@@ -0,0 +1,48 @@
|
||||
"use client"
|
||||
|
||||
import { useState } from "react"
|
||||
import { useRouter } from "next/navigation"
|
||||
import { Button } from "@/components/ui/button"
|
||||
import { Input } from "@/components/ui/input"
|
||||
import { Label } from "@/components/ui/label"
|
||||
import { useAuth } from "@/contexts/auth-context"
|
||||
|
||||
export default function LoginPage() {
|
||||
const [email, setEmail] = useState("")
|
||||
const [password, setPassword] = useState("")
|
||||
const router = useRouter()
|
||||
const { login } = useAuth()
|
||||
|
||||
const handleSubmit = (e: React.FormEvent) => {
|
||||
e.preventDefault()
|
||||
// In a real application, you would validate credentials here
|
||||
login()
|
||||
router.push("/")
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="container mx-auto px-4 py-8">
|
||||
<h1 className="text-2xl font-bold mb-6">Войти</h1>
|
||||
<form onSubmit={handleSubmit} className="space-y-4 max-w-md mx-auto">
|
||||
<div>
|
||||
<Label htmlFor="email">Email</Label>
|
||||
<Input type="email" id="email" value={email} onChange={(e) => setEmail(e.target.value)} required />
|
||||
</div>
|
||||
<div>
|
||||
<Label htmlFor="password">Пароль</Label>
|
||||
<Input
|
||||
type="password"
|
||||
id="password"
|
||||
value={password}
|
||||
onChange={(e) => setPassword(e.target.value)}
|
||||
required
|
||||
/>
|
||||
</div>
|
||||
<Button type="submit" className="w-full">
|
||||
Войти
|
||||
</Button>
|
||||
</form>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
78
frontend/style/app/register/page.tsx
Normal file
78
frontend/style/app/register/page.tsx
Normal file
@@ -0,0 +1,78 @@
|
||||
"use client";
|
||||
|
||||
import { useState } from "react";
|
||||
|
||||
export default function RegisterPage() {
|
||||
const [email, setEmail] = useState("");
|
||||
const [password, setPassword] = useState("");
|
||||
const [confirmPassword, setConfirmPassword] = useState("");
|
||||
const [message, setMessage] = useState("");
|
||||
|
||||
const handleSubmit = async (e: React.FormEvent) => {
|
||||
e.preventDefault();
|
||||
|
||||
if (password !== confirmPassword) {
|
||||
setMessage("Пароли не совпадают");
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const response = await fetch("http://localhost:8080/api/register", {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
body: JSON.stringify({ email, password }),
|
||||
});
|
||||
|
||||
if (response.ok) {
|
||||
setMessage("Регистрация прошла успешно!");
|
||||
} else {
|
||||
const errorText = await response.text();
|
||||
setMessage(`Ошибка при регистрации: ${errorText}`);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("Ошибка сети:", error);
|
||||
setMessage("Ошибка сети");
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="container mx-auto px-4 py-8">
|
||||
<h1 className="text-2xl font-bold mb-6">Регистрация</h1>
|
||||
<form onSubmit={handleSubmit}>
|
||||
<div>
|
||||
<label>Email:</label>
|
||||
<input
|
||||
type="email"
|
||||
value={email}
|
||||
onChange={(e) => setEmail(e.target.value)}
|
||||
className="border rounded w-full p-2 mb-4"
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<label>Пароль:</label>
|
||||
<input
|
||||
type="password"
|
||||
value={password}
|
||||
onChange={(e) => setPassword(e.target.value)}
|
||||
className="border rounded w-full p-2 mb-4"
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<label>Подтвердите пароль:</label>
|
||||
<input
|
||||
type="password"
|
||||
value={confirmPassword}
|
||||
onChange={(e) => setConfirmPassword(e.target.value)}
|
||||
className="border rounded w-full p-2 mb-4"
|
||||
/>
|
||||
</div>
|
||||
<button type="submit" className="bg-black text-white py-2 px-4 rounded">
|
||||
Зарегистрироваться
|
||||
</button>
|
||||
{message && <p className="mt-4 text-red-500">{message}</p>}
|
||||
</form>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user