generated from moevm/nsql-clean-tempate
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from moevm/koroleva/auth
Add server validation in auth page
- Loading branch information
Showing
9 changed files
with
544 additions
and
88 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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>) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |