From 24d107cc9dc958c63bd08fda1f53f98fad8771e7 Mon Sep 17 00:00:00 2001 From: ParkSuMin Date: Thu, 27 Feb 2025 11:21:06 -0300 Subject: [PATCH] FIIIIIXX --- frontend/style/app/login/page.tsx | 48 +++++++++++++++++ frontend/style/app/register/page.tsx | 78 ++++++++++++++++++++++++++++ 2 files changed, 126 insertions(+) create mode 100644 frontend/style/app/login/page.tsx create mode 100644 frontend/style/app/register/page.tsx diff --git a/frontend/style/app/login/page.tsx b/frontend/style/app/login/page.tsx new file mode 100644 index 00000000..d0f6d098 --- /dev/null +++ b/frontend/style/app/login/page.tsx @@ -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 ( +
+

Войти

+
+
+ + setEmail(e.target.value)} required /> +
+
+ + setPassword(e.target.value)} + required + /> +
+ +
+
+ ) +} + diff --git a/frontend/style/app/register/page.tsx b/frontend/style/app/register/page.tsx new file mode 100644 index 00000000..4c1bb4d8 --- /dev/null +++ b/frontend/style/app/register/page.tsx @@ -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 ( +
+

Регистрация

+
+
+ + setEmail(e.target.value)} + className="border rounded w-full p-2 mb-4" + /> +
+
+ + setPassword(e.target.value)} + className="border rounded w-full p-2 mb-4" + /> +
+
+ + setConfirmPassword(e.target.value)} + className="border rounded w-full p-2 mb-4" + /> +
+ + {message &&

{message}

} +
+
+ ); +} \ No newline at end of file