Skip to content

Commit

Permalink
Merge pull request #8 from moevm/koroleva/auth
Browse files Browse the repository at this point in the history
Add server validation in auth page
  • Loading branch information
polinaKoroleva05 authored Nov 7, 2024
2 parents be0371e + 5ff4782 commit 6cf5da6
Show file tree
Hide file tree
Showing 9 changed files with 544 additions and 88 deletions.
429 changes: 418 additions & 11 deletions client/package-lock.json

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@
"@types/node": "^16.18.114",
"@types/react": "^18.3.11",
"@types/react-dom": "^18.3.1",
"axios": "^1.7.7",
"bootstrap": "^5.3.3",
"chart.js": "^4.4.6",
"mobx-react": "^9.1.1",
"react": "^18.3.1",
"react-chartjs-2": "^5.2.0",
"bootstrap": "^5.3.3",
"react-bootstrap": "^2.10.5",
"react-chartjs-2": "^5.2.0",
"react-dom": "^18.3.1",
"react-router-dom": "^6.27.0",
"react-scripts": "5.0.1",
Expand Down
1 change: 0 additions & 1 deletion client/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ function App() {
<BrowserRouter>
<header>
<Link to="/personalAccount">ЛК</Link>
<Link to="/allUsers">Страница пользователей</Link>
</header>
<Routes>
<Route path="/" element={<AuthPage />}></Route>
Expand Down
2 changes: 2 additions & 0 deletions client/src/components/CellsTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export default function CellsTable(props: { isForRent: boolean, isForAdmin: bool
{/* {showPayment && <Payment cell={cellForRent} handleClick={CloseRent} isOpen={showPayment} />} */}
<Table striped bordered hover>
<thead>
<tr>
<th scope="col">
Номер
</th>
Expand All @@ -57,6 +58,7 @@ export default function CellsTable(props: { isForRent: boolean, isForAdmin: bool
Склад
</th>
{props.isForAdmin && <th scope="col"> Тех.обслуживание </th>}
</tr>
</thead>
<tbody>
{listCells}
Expand Down
66 changes: 50 additions & 16 deletions client/src/pages/AuthPage.tsx
Original file line number Diff line number Diff line change
@@ -1,24 +1,58 @@
import React, { useState } from "react";
import { Button, Form } from "react-bootstrap"
import axios, { AxiosError } from "axios";
import { SIGN_IN_URL } from "../serviceFiles/constants";
import { useNavigate } from "react-router-dom";

export default function AuthPage() {
const [formData, setFormData] = useState({email: '', password: ''});
let navigate = useNavigate();

function handleEmailChange(e: React.ChangeEvent<HTMLInputElement>){
setFormData(prevData => ({...prevData, "email": e.target.value}))
}
function handlePasswordChange(e: React.ChangeEvent<HTMLInputElement>){
setFormData(prevData => ({...prevData, "password": e.target.value}))
}
async function handleEntry(e: React.ChangeEvent<HTMLFormElement>) {
console.log(formData);
e.preventDefault();
try {
const response = await axios.post(SIGN_IN_URL, formData);
console.log('Вход в систему выполнен успешно!', response.data);
const userName = `${response.data.name} ${response.data.surname}`;
sessionStorage.setItem("name", userName);
sessionStorage.setItem("position", response.data.position);
navigate("/personalAccount");
} catch (error) {
if(axios.isAxiosError(error)){
const errorCode = error.message;
const errorDetail = error.response?.data.detail || error.response?.data.message;
const errorAlert = `${errorCode}. ${errorDetail}`
alert(errorAlert);
console.error('Ошибка при входе в систему.', error);
navigate("/personalAccount");
}
}
}
return (<div>
<h2>Вход</h2>
<Form>
<Form.Group className="mb-3" controlId="formBasicEmail">
<Form.Label>Логин</Form.Label>
<Form.Control type="email" placeholder="Логин" />
</Form.Group>
<Form onSubmit={handleEntry}>
<Form.Group className="mb-3" controlId="formBasicEmail">
<Form.Label>Логин</Form.Label>
<Form.Control type="email" placeholder="Почта" onChange={handleEmailChange}/>
</Form.Group>
<Form.Group className="mb-3" controlId="formBasicPassword">
<Form.Label>Пароль</Form.Label>
<Form.Control type="password" placeholder="Пароль" onChange={handlePasswordChange}/>
</Form.Group>

<Form.Group className="mb-3" controlId="formBasicPassword">
<Form.Label>Пароль</Form.Label>
<Form.Control type="password" placeholder="Пароль" />
</Form.Group>
<Form.Group className="mb-3" controlId="formBasicCheckbox">
<Form.Check type="checkbox" label="Запомнить меня" />
</Form.Group>
<Button variant="primary" type="submit">
Вход
</Button>
</Form>
<Form.Group className="mb-3" controlId="formBasicCheckbox">
<Form.Check type="checkbox" label="Запомнить меня" />
</Form.Group>
<Button variant="primary" type="submit">
Вход
</Button>
</Form>
</div>)
}
29 changes: 16 additions & 13 deletions client/src/pages/PersonalAccountPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,31 @@ import { BrowserRouter, Routes, Route, Link } from "react-router-dom";
import MyCellsPage from './manyEntity/MyCellsPage';
import BookCellPage from './manyEntity/RentCellPage';
import HelpPage from './HelpPage';
import { ListGroup } from 'react-bootstrap';


export default function PersonalAccount() {
return (<div>
PersonalPage
<ul className="list-group">
<li className="list-group-item">
{/* сам линк сделать элементом списка, а не вложенным */}
<ListGroup>
<ListGroup.Item>
<Link to="/myCells">Мои ячейки</Link>
</li>
<li className="list-group-item">
</ListGroup.Item>
<ListGroup.Item>
<Link to="/rentCell">Арендовать ячейку</Link>
</li>
<li className="list-group-item">
</ListGroup.Item>
<ListGroup.Item>
<Link to="/help">Поддержка</Link>
</li>
<li className="list-group-item">
</ListGroup.Item>
<ListGroup.Item>
<Link to="/allCells">Все ячейки</Link>
</li>
<li className="list-group-item">
</ListGroup.Item>
<ListGroup.Item>
<Link to="/allEvents">Все события</Link>
</li>
</ul>
</ListGroup.Item>
<ListGroup.Item>
<Link to="/allUsers">Страница пользователей</Link>
</ListGroup.Item>
</ListGroup>
</div>)
}
31 changes: 4 additions & 27 deletions client/src/pages/manyEntity/AllEventsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,37 +3,12 @@ import { useNavigate } from "react-router-dom";
import { Event } from "../../serviceFiles/types";
import Table from "react-bootstrap/Table";
import { Tab } from "react-bootstrap";
import { eventsInit } from "../../serviceFiles/constants";

export default function AllEventsPage() {
let navigate = useNavigate();

const [events, setEvent] = useState([
{
eventId: 1,
cellId: 1,
userId: 1,
action: "open",
dateAndTime: "2024-10-13 12:46:01",
description: ""

}, {
eventId: 2,
cellId: 2,
userId: 1,
action: "close",
dateAndTime: "2024-11-13 13:50:01",
description: ""

},
{
eventId: 3,
cellId: 2,
userId: 1,
action: "breaking",
dateAndTime: "2024-11-16 01:50:01",
description: "Сломана дверца"

}]);
const [events, setEvent] = useState(eventsInit);
function handleUserClick(event: Event) {
navigate("/event", { state: event })
}
Expand Down Expand Up @@ -62,6 +37,7 @@ export default function AllEventsPage() {
return (<>
<Table striped bordered hover>
<thead>
<tr>
<th>
eventId
</th>
Expand All @@ -80,6 +56,7 @@ export default function AllEventsPage() {
<th>
description
</th>
</tr>
</thead>
<tbody>
{listUsers}
Expand Down
21 changes: 4 additions & 17 deletions client/src/pages/manyEntity/AllUsersPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,12 @@ import { useState } from "react";
import { useNavigate } from "react-router-dom";
import { User } from "../../serviceFiles/types";
import { Table } from "react-bootstrap";
import { usersInit } from "../../serviceFiles/constants";

export default function AllUsersPage() {
let navigate = useNavigate();

const [users, setUsers] = useState([{
id: 1,
NameSurnamePatronymic: "Крупская Ольга Дмитриевна",
role: "Client",
login: "LOGIN_1",
date: "2024-01-13",
rentedCells: [201, 321, 710],
indebtedness: 0.00
}, {
id: 2,
NameSurnamePatronymic: "Королева Полина Андреевна",
role: "User",
login: "LOGIN_2",
date: "2023-04-10",
rentedCells: [202, 901],
indebtedness: 10.00
}]);
const [users, setUsers] = useState(usersInit);
function handleUserClick(user: User){
navigate("/user", {state: user})
}
Expand Down Expand Up @@ -60,6 +45,7 @@ export default function AllUsersPage() {
return (<>
<Table striped bordered hover>
<thead>
<tr>
<th>
id
</th>
Expand Down Expand Up @@ -87,6 +73,7 @@ export default function AllUsersPage() {
<th>
Задолженность
</th>
</tr>
</thead>
<tbody>
{listUsers}
Expand Down
48 changes: 47 additions & 1 deletion client/src/serviceFiles/constants.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,50 @@
export let cellsInit = [
{ cellId: 5, isFree: true, needService: true, endOfRent: "2025-02-02", size: 0.1, warehouse: "Комендантский проспект" },
{ cellId: 9, isFree: true, needService: false, endOfRent: "2025-01-02", size: 0.3, warehouse: "Большевиков" },
{ cellId: 4, isFree: true, needService: true, endOfRent: "2026-02-01", size: 0.6, warehouse: "Электросила" }]
{ cellId: 4, isFree: true, needService: true, endOfRent: "2026-02-01", size: 0.6, warehouse: "Электросила" }]

export let eventsInit = [{
eventId: 1,
cellId: 1,
userId: 1,
action: "open",
dateAndTime: "2024-10-13 12:46:01",
description: ""

}, {
eventId: 2,
cellId: 2,
userId: 1,
action: "close",
dateAndTime: "2024-11-13 13:50:01",
description: ""

},
{
eventId: 3,
cellId: 2,
userId: 1,
action: "breaking",
dateAndTime: "2024-11-16 01:50:01",
description: "Сломана дверца"

}]

export let usersInit = [{
id: 1,
NameSurnamePatronymic: "Крупская Ольга Дмитриевна",
role: "Client",
login: "LOGIN_1",
date: "2024-01-13",
rentedCells: [201, 321, 710],
indebtedness: 0.00
}, {
id: 2,
NameSurnamePatronymic: "Королева Полина Андреевна",
role: "User",
login: "LOGIN_2",
date: "2023-04-10",
rentedCells: [202, 901],
indebtedness: 10.00
}]
export const SIGN_IN_URL = "src/serviceFiles/data.ts"

0 comments on commit 6cf5da6

Please sign in to comment.