регистрация
This commit is contained in:
parent
81f072131f
commit
658ae323ba
@ -5,6 +5,12 @@
|
||||
"login": "dyctator",
|
||||
"password": "12345",
|
||||
"role": "user"
|
||||
},
|
||||
{
|
||||
"login": "user",
|
||||
"password": "123",
|
||||
"role": "user",
|
||||
"id": 1
|
||||
}
|
||||
],
|
||||
"directions": [
|
||||
|
@ -4,16 +4,19 @@ import EntrysDataApiService from '../service/EntrysDataApiService';
|
||||
const useEntrysData = (login, password) => {
|
||||
const [entrys, setEntrys] = useState([]);
|
||||
|
||||
const getLogin = async () => {
|
||||
const expand = `?login=${login}`;
|
||||
const data = await EntrysDataApiService.getAll();
|
||||
const getEntrysData = async () => {
|
||||
let expand = `?login=${login}&password=${password}`;
|
||||
if (password === '') {
|
||||
expand = `?login=${login}`;
|
||||
}
|
||||
const data = await EntrysDataApiService.getAll(expand);
|
||||
setEntrys(data ?? []);
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
getEntrysData();
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, []);
|
||||
}, [login, password]);
|
||||
|
||||
return {
|
||||
entrys,
|
||||
|
@ -2,11 +2,9 @@ import { useState } from 'react';
|
||||
import EntrysDataApiService from '../service/EntrysDataApiService';
|
||||
import useEntysDataItem from './DataItemHook';
|
||||
|
||||
const useLinesItemForm = (id, linesChangeHandle) => {
|
||||
const useEntrysItemForm = (id) => {
|
||||
const { item, setItem } = useEntysDataItem(id);
|
||||
|
||||
const [modified, setModified] = useState(false);
|
||||
|
||||
const [validated, setValidated] = useState(false);
|
||||
|
||||
const resetValidity = () => {
|
||||
@ -16,7 +14,7 @@ const useLinesItemForm = (id, linesChangeHandle) => {
|
||||
const getLineObject = (formData) => {
|
||||
const Login = formData.login.toString();
|
||||
const Password = formData.password.toString();
|
||||
const Role = formData.role.toString();
|
||||
const Role = 'user';
|
||||
return {
|
||||
login: Login,
|
||||
password: Password,
|
||||
@ -44,8 +42,6 @@ const useLinesItemForm = (id, linesChangeHandle) => {
|
||||
} else {
|
||||
await EntrysDataApiService.update(id, body);
|
||||
}
|
||||
if (linesChangeHandle) linesChangeHandle();
|
||||
setModified(true);
|
||||
return true;
|
||||
}
|
||||
setValidated(true);
|
||||
@ -55,11 +51,10 @@ const useLinesItemForm = (id, linesChangeHandle) => {
|
||||
return {
|
||||
item,
|
||||
validated,
|
||||
handleSubmit,
|
||||
handleChange,
|
||||
UseHandleSubmit: handleSubmit,
|
||||
UseHandleChange: handleChange,
|
||||
resetValidity,
|
||||
isModified: modified,
|
||||
};
|
||||
};
|
||||
|
||||
export default useLinesItemForm;
|
||||
export default useEntrysItemForm;
|
||||
|
@ -6,11 +6,11 @@ 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 { entrys } = useEntrysData(login, password);
|
||||
|
||||
const handleSubmit = (event) => {
|
||||
const form = event.currentTarget;
|
||||
@ -18,19 +18,14 @@ const Entry = () => {
|
||||
event.stopPropagation();
|
||||
if (form.checkValidity() !== false) {
|
||||
if (isLoginValid(login)) {
|
||||
entrys.map((item) => {
|
||||
if (login === item.login) {
|
||||
if (password === item.password) {
|
||||
toast.success('Вы вошли в аккаунт');
|
||||
return [];
|
||||
}
|
||||
}
|
||||
toast.error('Данный пользователь не найден, либо был введён неверный пароль');
|
||||
return [];
|
||||
});
|
||||
if (entrys.length === 0) {
|
||||
toast.error('Аккаунт не найден');
|
||||
} else {
|
||||
setValidated(true);
|
||||
toast.success('Был произведён вход');
|
||||
}
|
||||
} else {
|
||||
toast.error('Логин должен быть введён латинскими символами');
|
||||
return;
|
||||
}
|
||||
}
|
||||
setValidated(true);
|
||||
|
@ -4,13 +4,16 @@ import toast from 'react-hot-toast';
|
||||
import { Button, Form } from 'react-bootstrap';
|
||||
import Input from '../../input/Input.jsx';
|
||||
import useEntrysData from '../hooks/EntrysDataHook';
|
||||
import useEntrysItemForm from '../hooks/EntrysDataItemHook';
|
||||
|
||||
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 { entrys } = useEntrysData(login, '');
|
||||
|
||||
const { UseHandleSubmit, UseHandleChange } = useEntrysItemForm();
|
||||
|
||||
const handleSubmit = (event) => {
|
||||
const form = event.currentTarget;
|
||||
@ -22,6 +25,7 @@ const Entry = () => {
|
||||
if (isLoginExists) {
|
||||
toast.error('Такой аккаунт уже создан');
|
||||
} else {
|
||||
UseHandleSubmit(event);
|
||||
toast.success('Ваш аккаунт успешно создан');
|
||||
}
|
||||
} else {
|
||||
@ -32,6 +36,16 @@ const Entry = () => {
|
||||
setValidated(true);
|
||||
};
|
||||
|
||||
const handleChangeLogin = (event) => {
|
||||
setLogin(event.target.value);
|
||||
UseHandleChange(event);
|
||||
};
|
||||
|
||||
const handleChangePassword = (event) => {
|
||||
setPassword(event.target.value);
|
||||
UseHandleChange(event);
|
||||
};
|
||||
|
||||
return (
|
||||
<main className="container-fluid text-center">
|
||||
<span className="mainSt">
|
||||
@ -43,10 +57,10 @@ const Entry = () => {
|
||||
</span>
|
||||
<Form className="col-md-4 m-0 w-auto" onSubmit={ handleSubmit } noValidate validated={validated}>
|
||||
<label className="form-label"><b>Логин</b></label>
|
||||
<Input name="login" value = { login } onChange={(e) => setLogin(e.target.value)}
|
||||
<Input name="login" value = { login } onChange={ handleChangeLogin }
|
||||
placeholder="dyctator" type="text" required />
|
||||
<label className="form-label"><b>Пароль</b></label>
|
||||
<Input name="password" value = { password } onChange={(e) => setPassword(e.target.value)}
|
||||
<Input name="password" value = { password } onChange={ handleChangePassword }
|
||||
type="password" required />
|
||||
<Button as={Link} to='/page4' className = "btn btn-info">Назад</Button>
|
||||
<Button className="btn btn-primary w-auto" type="submit" >Создать</Button>
|
||||
|
Loading…
Reference in New Issue
Block a user