From df5809232b5fe638a829dc65058c307106f6a002 Mon Sep 17 00:00:00 2001 From: Andrei Duvakin Date: Fri, 7 Feb 2025 19:55:19 +0500 Subject: [PATCH] =?UTF-8?q?=D1=81=D0=B4=D0=B5=D0=BB=D0=B0=D0=BB=20=D0=B7?= =?UTF-8?q?=D0=B0=D0=B3=D0=BE=D1=82=D0=BE=D0=B2=D0=BA=D1=83=20=D0=BF=D0=BE?= =?UTF-8?q?=D0=B4=20=D0=BD=D0=B0=D0=B2=D0=B8=D0=B3=D0=B0=D1=86=D0=B8=D1=8E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/app/domain/entities/auth.py | 6 +-- api/app/domain/entities/register.py | 12 ++--- api/app/domain/entities/user.py | 13 +++-- web-app/package-lock.json | 7 +-- web-app/package.json | 1 + web-app/public/favicons/browserconfig.xml | 17 +++--- web-app/src/AppRouter.jsx | 5 +- web-app/src/layouts/MainLayout.jsx | 66 +++++++++++++++++++++++ web-app/src/pages/LoginPage.jsx | 14 ++++- 9 files changed, 110 insertions(+), 31 deletions(-) create mode 100644 web-app/src/layouts/MainLayout.jsx diff --git a/api/app/domain/entities/auth.py b/api/app/domain/entities/auth.py index a36b80a..003b78e 100644 --- a/api/app/domain/entities/auth.py +++ b/api/app/domain/entities/auth.py @@ -1,7 +1,7 @@ -from pydantic import BaseModel, Field +from pydantic import BaseModel class AuthEntity(BaseModel): - login: str = Field(..., example='user@example.com') - password: str = Field(..., min_length=5, example='strongpassword') + login: str + password: str diff --git a/api/app/domain/entities/register.py b/api/app/domain/entities/register.py index f6a479d..ad923f3 100644 --- a/api/app/domain/entities/register.py +++ b/api/app/domain/entities/register.py @@ -4,9 +4,9 @@ from pydantic import BaseModel, Field class RegisterEntity(BaseModel): - first_name: str = Field(..., example='Ivan') - last_name: str = Field(..., example='Ivanov') - patronymic: Optional[str] = Field(None, example='Ivanov') - role_id: int = Field(..., example=1) - login: str = Field(..., example='user@example.com') - password: str = Field(..., min_length=5, example='strongpassword') + first_name: str + last_name: str + patronymic: Optional[str] + role_id: int + login: str + password: str diff --git a/api/app/domain/entities/user.py b/api/app/domain/entities/user.py index ba2347b..159c0e8 100644 --- a/api/app/domain/entities/user.py +++ b/api/app/domain/entities/user.py @@ -4,11 +4,10 @@ from pydantic import BaseModel, Field class UserEntity(BaseModel): - id: int = Field(..., example=1) - first_name: str = Field(..., example='Ivan') - last_name: str = Field(..., example='Ivanov') - patronymic: Optional[str] = Field(None, example='Ivanov') - login: str = Field(..., example='ivanov74') - - role_id: int = Field(..., example=1) + id: int + first_name: str + last_name: str + patronymic: Optional[str] + login: str + role_id: int diff --git a/web-app/package-lock.json b/web-app/package-lock.json index 0680458..b325a53 100644 --- a/web-app/package-lock.json +++ b/web-app/package-lock.json @@ -8,6 +8,7 @@ "name": "web-app", "version": "0.0.0", "dependencies": { + "@ant-design/icons": "^5.6.1", "@react-buddy/ide-toolbox": "^2.4.0", "@react-buddy/palette-antd": "^5.3.0", "antd": "^5.23.1", @@ -86,9 +87,9 @@ } }, "node_modules/@ant-design/icons": { - "version": "5.5.2", - "resolved": "https://registry.npmjs.org/@ant-design/icons/-/icons-5.5.2.tgz", - "integrity": "sha512-xc53rjVBl9v2BqFxUjZGti/RfdDeA8/6KYglmInM2PNqSXc/WfuGDTifJI/ZsokJK0aeKvOIbXc9y2g8ILAhEA==", + "version": "5.6.1", + "resolved": "https://registry.npmjs.org/@ant-design/icons/-/icons-5.6.1.tgz", + "integrity": "sha512-0/xS39c91WjPAZOWsvi1//zjx6kAp4kxWwctR6kuU6p133w8RU0D2dSCvZC19uQyharg/sAvYxGYWl01BbZZfg==", "license": "MIT", "dependencies": { "@ant-design/colors": "^7.0.0", diff --git a/web-app/package.json b/web-app/package.json index c1149c1..5e8226e 100644 --- a/web-app/package.json +++ b/web-app/package.json @@ -10,6 +10,7 @@ "preview": "vite preview" }, "dependencies": { + "@ant-design/icons": "^5.6.1", "@react-buddy/ide-toolbox": "^2.4.0", "@react-buddy/palette-antd": "^5.3.0", "antd": "^5.23.1", diff --git a/web-app/public/favicons/browserconfig.xml b/web-app/public/favicons/browserconfig.xml index e1ae694..450ac0c 100644 --- a/web-app/public/favicons/browserconfig.xml +++ b/web-app/public/favicons/browserconfig.xml @@ -1,12 +1,11 @@ - - - - - - - #ffffff - - + + + + + + #ffffff + + diff --git a/web-app/src/AppRouter.jsx b/web-app/src/AppRouter.jsx index 6d85598..75d0b5c 100644 --- a/web-app/src/AppRouter.jsx +++ b/web-app/src/AppRouter.jsx @@ -1,6 +1,7 @@ import {Routes, Route} from "react-router-dom"; import PrivateRoute from "./components/PrivateRoute.jsx"; import LoginPage from "./pages/LoginPage.jsx"; +import MainLayout from "./layouts/MainLayout.jsx"; const AppRouter = () => ( @@ -8,7 +9,9 @@ const AppRouter = () => ( }/> }> - 1234

}/> + }> + 1234

}/> +
) diff --git a/web-app/src/layouts/MainLayout.jsx b/web-app/src/layouts/MainLayout.jsx new file mode 100644 index 0000000..2db9c9c --- /dev/null +++ b/web-app/src/layouts/MainLayout.jsx @@ -0,0 +1,66 @@ +import {useState} from "react"; +import {Layout, Menu} from "antd"; +import {Outlet, useLocation, useNavigate} from "react-router-dom"; +import { + DesktopOutlined, + FileOutlined, + PieChartOutlined, + TeamOutlined, + UserOutlined, +} from "@ant-design/icons"; + +const {Content, Footer, Sider} = Layout; + +const getItem = (label, key, icon, children) => ({ + key, + icon, + children, + label, +}); + +const items = [ + getItem("Главная", "/", ), + getItem("Настройки", "/settings", ), + getItem("Пользователи", "sub1", , [ + getItem("Том", "/users/tom"), + getItem("Билл", "/users/bill"), + getItem("Алекс", "/users/alex"), + ]), + getItem("Команда", "sub2", , [ + getItem("Команда 1", "/team/1"), + getItem("Команда 2", "/team/2"), + ]), + getItem("Файлы", "/files", ), +]; + +const MainLayout = () => { + const [collapsed, setCollapsed] = useState(false); + const navigate = useNavigate(); + const location = useLocation(); + + return ( + + + navigate(key)} + /> + + + + +
+ +
+
+ + +
+ + ); +}; + +export default MainLayout; diff --git a/web-app/src/pages/LoginPage.jsx b/web-app/src/pages/LoginPage.jsx index 0b60e27..652372b 100644 --- a/web-app/src/pages/LoginPage.jsx +++ b/web-app/src/pages/LoginPage.jsx @@ -1,20 +1,30 @@ import {Form, Input, Button, Row, Col, Typography} from 'antd'; -import {useState} from 'react'; +import {useEffect, useState} from 'react'; import {useAuth} from "../AuthContext.jsx"; +import {useNavigate} from "react-router-dom"; const {Title} = Typography; const LoginPage = () => { - const {login} = useAuth(); + const {user, login} = useAuth(); const [loading, setLoading] = useState(false); const [error, setError] = useState(null); + const navigate = useNavigate(); + + useEffect(() => { + if (user) { + navigate("/"); + } + }, [user, navigate]); + const onFinish = async (values) => { setLoading(true); setError(null); try { await login(values); + navigate("/"); } catch (error) { setError(`Ошибка при входе: ${error.message}`); } finally {