From c036badf7a9ef612128c0bd479dbf55824c0e338 Mon Sep 17 00:00:00 2001 From: DyCTaTOR <125912249+DyCTaTOR@users.noreply.github.com> Date: Mon, 25 Dec 2023 13:32:42 +0400 Subject: [PATCH] =?UTF-8?q?=D0=9B=D0=BE=D0=B3=D0=B8=D0=BD=D0=9F=D0=B0?= =?UTF-8?q?=D1=80=D0=BE=D0=BB=D0=B8.=20=D0=9F=D1=80=D0=BE=D0=B4=D0=BE?= =?UTF-8?q?=D0=BB=D0=B6=D0=B5=D0=BD=D0=B8=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Lab5/data.json | 7 +++++ .../Directions/direct/Directions.jsx | 8 ++--- .../components/logins/hooks/EntrysDataHook.js | 30 ++++++------------ Lab5/src/components/logins/login/Entry.jsx | 31 ++++++++++++++++--- Lab5/src/index.css | 5 +++ Lab5/src/main.jsx | 5 +++ Lab5/src/pages/RegistrPage.jsx | 9 ++++++ 7 files changed, 66 insertions(+), 29 deletions(-) create mode 100644 Lab5/src/pages/RegistrPage.jsx diff --git a/Lab5/data.json b/Lab5/data.json index 6124570..5f3aadf 100644 --- a/Lab5/data.json +++ b/Lab5/data.json @@ -1,4 +1,11 @@ { + "entrysData": [ + { + "id": 0, + "login": "dyctator", + "password": "12345" + } + ], "directions": [ { "id": 0, diff --git a/Lab5/src/components/Directions/direct/Directions.jsx b/Lab5/src/components/Directions/direct/Directions.jsx index 6143454..74b0a0a 100644 --- a/Lab5/src/components/Directions/direct/Directions.jsx +++ b/Lab5/src/components/Directions/direct/Directions.jsx @@ -24,10 +24,10 @@ const Directions = () => { || item.things.toLowerCase().includes(searchValue.toLowerCase()) || item.code.toLowerCase().includes(searchValue.toLowerCase())) { return ; - } - return null; - }) - } + } + return null; + }) + } diff --git a/Lab5/src/components/logins/hooks/EntrysDataHook.js b/Lab5/src/components/logins/hooks/EntrysDataHook.js index 62b534e..5367865 100644 --- a/Lab5/src/components/logins/hooks/EntrysDataHook.js +++ b/Lab5/src/components/logins/hooks/EntrysDataHook.js @@ -1,34 +1,22 @@ import { useEffect, useState } from 'react'; import EntrysDataApiService from '../service/EntrysDataApiService'; -const useEntysDataItem = (id) => { - const emptyItem = { - id: '', - date: '', - name: '', - description: '', - image: '', - }; - const [item, setItem] = useState({ ...emptyItem }); +const useEntrysData = () => { + const [entrys, setEntrys] = useState([]); - const getItem = async (itemId = undefined) => { - if (itemId && itemId > 0) { - const data = await EntrysDataApiService.get(itemId); - setItem(data); - } else { - setItem({ ...emptyItem }); - } + const getEntrysData = async () => { + const data = await EntrysDataApiService.getAll(); + setEntrys(data ?? []); }; useEffect(() => { - getItem(id); + getEntrysData(); // eslint-disable-next-line react-hooks/exhaustive-deps - }, [id]); + }, []); return { - item, - setItem, + entrys, }; }; -export default useEntysDataItem; +export default useEntrysData; diff --git a/Lab5/src/components/logins/login/Entry.jsx b/Lab5/src/components/logins/login/Entry.jsx index a1aadec..9a31cd4 100644 --- a/Lab5/src/components/logins/login/Entry.jsx +++ b/Lab5/src/components/logins/login/Entry.jsx @@ -1,36 +1,59 @@ import { useState } from 'react'; +import { Link } from 'react-router-dom'; import toast from 'react-hot-toast'; -import { Button, Form, Label } from 'react-bootstrap'; +import { Button, Form } from 'react-bootstrap'; import Input from '../../input/Input.jsx'; +import useEntrysData from '../hooks/EntrysDataHook'; const Entry = () => { + const { entrys } = useEntrysData(); const [validated, setValidated] = useState(false); const [login, setLogin] = useState(''); const [password, setPassword] = useState(''); + const isLoginValid = (value) => /^[a-zA-Z]+$/.test(value); const handleSubmit = (event) => { const form = event.currentTarget; event.preventDefault(); event.stopPropagation(); if (form.checkValidity() !== false) { - toast.success('Валидация прошла успешно'); + if (isLoginValid(login)) { + entrys.map((item) => { + if (login === item.login) { + if (password === item.password) { + toast.success('Вы вошли в аккаунт'); + return []; + } + } + toast.error('Данный пользователь не найден, либо был введён неверный пароль'); + return []; + }); + } else { + toast.error('Логин должен быть введён латинскими символами'); + return; + } } setValidated(true); }; + return (
Личный кабинет
+ + +
- + setLogin(e.target.value)} placeholder="dyctator" type="text" required /> - + setPassword(e.target.value)} type="password" required /> +
diff --git a/Lab5/src/index.css b/Lab5/src/index.css index 538beb0..9fc06a7 100644 --- a/Lab5/src/index.css +++ b/Lab5/src/index.css @@ -37,6 +37,11 @@ h3 { color: #060647; font-size: 50px; } +.EntrysSt{ + font-weight: bold; + color: #060647; + font-size: 30px; +} .rectPage2{ color: #FFFFFF; diff --git a/Lab5/src/main.jsx b/Lab5/src/main.jsx index 2c55b15..e5c0281 100644 --- a/Lab5/src/main.jsx +++ b/Lab5/src/main.jsx @@ -10,6 +10,7 @@ import Page2 from './pages/Page2.jsx'; import Page3 from './pages/Page3.jsx'; import Page4 from './pages/Page4.jsx'; import Page5 from './pages/Page5.jsx'; +import RegistrPage from './pages/RegistrPage.jsx'; const routes = [ { @@ -38,6 +39,10 @@ const routes = [ element: , title: 'Контакты', }, + { + path: '/registrPage', + element: , + }, ]; const router = createBrowserRouter([ diff --git a/Lab5/src/pages/RegistrPage.jsx b/Lab5/src/pages/RegistrPage.jsx new file mode 100644 index 0000000..f7a792d --- /dev/null +++ b/Lab5/src/pages/RegistrPage.jsx @@ -0,0 +1,9 @@ +const RegistrPage = () => { + return ( +
+ +
+ ); +}; + +export default RegistrPage;