|
@@ -1,231 +1,24 @@
|
|
-import React, {
|
|
|
|
- // createContext,
|
|
|
|
- forwardRef,
|
|
|
|
- // useContext,
|
|
|
|
- useState
|
|
|
|
-} from 'react';
|
|
|
|
-import { store } from '../redux';
|
|
|
|
|
|
+import * as React from 'react';
|
|
import {
|
|
import {
|
|
useHistory,
|
|
useHistory,
|
|
useLocation
|
|
useLocation
|
|
} from "react-router-dom";
|
|
} from "react-router-dom";
|
|
-import { actionFullLogin, actionFullRegistration } from "../redux/action";
|
|
|
|
|
|
+
|
|
|
|
+import LoginForm from './login_form';
|
|
|
|
|
|
import {
|
|
import {
|
|
- Dialog,
|
|
|
|
- DialogActions,
|
|
|
|
- DialogContent,
|
|
|
|
- DialogContentText,
|
|
|
|
- DialogTitle,
|
|
|
|
Paper,
|
|
Paper,
|
|
Box,
|
|
Box,
|
|
- Typography,
|
|
|
|
- Button,
|
|
|
|
- Stack,
|
|
|
|
- OutlinedInput,
|
|
|
|
- IconButton,
|
|
|
|
- InputLabel,
|
|
|
|
- InputAdornment,
|
|
|
|
- FormControl,
|
|
|
|
- TextField,
|
|
|
|
- Slide
|
|
|
|
|
|
+ Typography
|
|
} from "@mui/material";
|
|
} from "@mui/material";
|
|
|
|
|
|
-import {
|
|
|
|
- Visibility,
|
|
|
|
- VisibilityOff
|
|
|
|
-} from '@mui/icons-material';
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-// анимация появление модального окна
|
|
|
|
-const Transition = forwardRef(function Transition(props, ref) {
|
|
|
|
- return <Slide direction="up" ref={ref} {...props} />;
|
|
|
|
-})
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-// поля ввода и кнопки
|
|
|
|
-function LoginForm() {
|
|
|
|
- const location = useLocation().pathname === '/';
|
|
|
|
- const history = useHistory();
|
|
|
|
-
|
|
|
|
- // отслеживаем введение данных в полях логин/пароль
|
|
|
|
- const [data, setData] = useState({ login: '', pass: '', confirmPass: '' })
|
|
|
|
- console.log('data: ', data)
|
|
|
|
-
|
|
|
|
- // модальное окно открытие/закрытие
|
|
|
|
- const [open, setOpen] = useState(false);
|
|
|
|
- const openModalAlertWindow = () => {
|
|
|
|
- setOpen(true);
|
|
|
|
- }
|
|
|
|
- const closeModalAlertWindow = () => {
|
|
|
|
- setOpen(false);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- // регулярка для проверки нового пароля
|
|
|
|
- const pattern = /(?=.*[0-9])(?=.*[!@#$%^&*])(?=.*[a-z])(?=.*[A-Z])/g
|
|
|
|
- // указываем минимальную длинну для нового пароля
|
|
|
|
- const passLength = 8;
|
|
|
|
-
|
|
|
|
- let isValidate, isCorrect;
|
|
|
|
-
|
|
|
|
- ((data.pass.length < passLength) || !(pattern.test(data.pass))) && (isValidate = true);
|
|
|
|
- (data.pass != data.confirmPass) && (isCorrect = true);
|
|
|
|
-
|
|
|
|
- const validation = (data.login == '') || (data.pass == '')
|
|
|
|
-
|
|
|
|
-
|
|
|
|
- // включаем,выклюаем отображение пароля
|
|
|
|
- const [showPassword, setShowPassword] = useState(false);
|
|
|
|
- const handleClickShowPassword = () => setShowPassword((show) => !show);
|
|
|
|
- const handleMouseDownPassword = (event) => {
|
|
|
|
- event.preventDefault();
|
|
|
|
- };
|
|
|
|
-
|
|
|
|
- // включаем,выклюаем отображение подтверждения пароля
|
|
|
|
- const [showPasswordConfirm, setShowPasswordConfirm] = useState(false);
|
|
|
|
- const handleClickShowPasswordConfirm = () => setShowPasswordConfirm((show) => !show);
|
|
|
|
- const handleMouseDownPasswordConfirm = (event) => {
|
|
|
|
- event.preventDefault();
|
|
|
|
- };
|
|
|
|
-
|
|
|
|
|
|
|
|
- // Thunk регистрация
|
|
|
|
- async function fullRegistration() {
|
|
|
|
- const token = await store.dispatch(actionFullRegistration(data.login, data.confirmPass))
|
|
|
|
|
|
|
|
- if (token !== null) {
|
|
|
|
- history.push('/')
|
|
|
|
- } else {
|
|
|
|
- openModalAlertWindow()
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- // Thunk логинизация
|
|
|
|
- async function fullLogin() {
|
|
|
|
- const token = await store.dispatch(actionFullLogin(data.login, data.pass))
|
|
|
|
-
|
|
|
|
- if (token == null) {
|
|
|
|
- openModalAlertWindow()
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
-
|
|
|
|
- return (
|
|
|
|
- <Box sx={{ width: '100%' }}>
|
|
|
|
- <form>
|
|
|
|
- <Stack spacing={2}>
|
|
|
|
- <TextField
|
|
|
|
- fullWidth
|
|
|
|
- variant='outlined'
|
|
|
|
- id='login'
|
|
|
|
- label='Логин'
|
|
|
|
- size='normal'
|
|
|
|
- value={data.login}
|
|
|
|
- onChange={e => setData({ ...data, login: e.target.value })}
|
|
|
|
- />
|
|
|
|
-
|
|
|
|
- <FormControl variant="outlined">
|
|
|
|
- <InputLabel htmlFor="outlined-adornment-password">Пароль</InputLabel>
|
|
|
|
- <OutlinedInput
|
|
|
|
- error={isValidate}
|
|
|
|
- fullWidth
|
|
|
|
- id="password"
|
|
|
|
- label="Пароль"
|
|
|
|
- size="normal"
|
|
|
|
- type={showPassword ? 'text' : 'password'}
|
|
|
|
- value={data.pass}
|
|
|
|
- onChange={e => setData({ ...data, pass: e.target.value })}
|
|
|
|
-
|
|
|
|
- endAdornment={
|
|
|
|
- <InputAdornment position="end">
|
|
|
|
- <IconButton
|
|
|
|
- aria-label="visibility"
|
|
|
|
- onClick={handleClickShowPassword}
|
|
|
|
- onMouseDown={handleMouseDownPassword}
|
|
|
|
- edge="end"
|
|
|
|
- >
|
|
|
|
- {showPassword ? <VisibilityOff /> : <Visibility />}
|
|
|
|
- </IconButton>
|
|
|
|
- </InputAdornment>
|
|
|
|
- }
|
|
|
|
- />
|
|
|
|
- </FormControl>
|
|
|
|
-
|
|
|
|
- {!location && <FormControl variant="outlined">
|
|
|
|
- <InputLabel htmlFor="outlined-adornment-password">Подтвердите пароль</InputLabel>
|
|
|
|
- <OutlinedInput
|
|
|
|
- error={isCorrect}
|
|
|
|
- fullWidth
|
|
|
|
- id="confirmPassword"
|
|
|
|
- label="Подтвердите пароль"
|
|
|
|
- size="normal"
|
|
|
|
- type={showPasswordConfirm ? 'text' : 'password'}
|
|
|
|
- value={data.confirmPass}
|
|
|
|
- onChange={e => setData({ ...data, confirmPass: e.target.value })}
|
|
|
|
-
|
|
|
|
- endAdornment={
|
|
|
|
- <InputAdornment position="end">
|
|
|
|
- <IconButton
|
|
|
|
- aria-label="visibility"
|
|
|
|
- onClick={handleClickShowPasswordConfirm}
|
|
|
|
- onMouseDown={handleMouseDownPasswordConfirm}
|
|
|
|
- edge="end"
|
|
|
|
- >
|
|
|
|
- {showPasswordConfirm ? <VisibilityOff /> : <Visibility />}
|
|
|
|
- </IconButton>
|
|
|
|
- </InputAdornment>
|
|
|
|
- }
|
|
|
|
- />
|
|
|
|
- </FormControl>}
|
|
|
|
-
|
|
|
|
- <Button
|
|
|
|
- size="large"
|
|
|
|
- variant="contained"
|
|
|
|
- disabled={location
|
|
|
|
- ? (validation || false)
|
|
|
|
- : (validation || isCorrect) || false}
|
|
|
|
- onClick={location ? fullLogin : fullRegistration}
|
|
|
|
- >
|
|
|
|
- {location
|
|
|
|
- ? 'Войти' : 'Регистрация'}
|
|
|
|
- </Button>
|
|
|
|
- </Stack>
|
|
|
|
- </form>
|
|
|
|
-
|
|
|
|
- <div>
|
|
|
|
- <Dialog
|
|
|
|
- open={open}
|
|
|
|
- onClose={closeModalAlertWindow}
|
|
|
|
- TransitionComponent={Transition}
|
|
|
|
- // keepMounted // всегда держит компонент смонтированным в DOM
|
|
|
|
- >
|
|
|
|
- <DialogTitle>Что-то пошло не так!</DialogTitle>
|
|
|
|
- <DialogContent>
|
|
|
|
- <DialogContentText>
|
|
|
|
- {
|
|
|
|
- location
|
|
|
|
- ? 'Вы ввели неправильный логин или пароль. Повторите попытку.'
|
|
|
|
- : 'Введенные логин и/или пароль уже зарегистрированы'
|
|
|
|
- }
|
|
|
|
- </DialogContentText>
|
|
|
|
- </DialogContent>
|
|
|
|
- <DialogActions>
|
|
|
|
- <Button onClick={closeModalAlertWindow}>Ок</Button>
|
|
|
|
- </DialogActions>
|
|
|
|
- </Dialog>
|
|
|
|
- </div>
|
|
|
|
- </Box>
|
|
|
|
- )
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-// действия при нажатии по ссылке на регистрацию
|
|
|
|
|
|
+// ссылка на страницу регистрации
|
|
function RegistrationLink() {
|
|
function RegistrationLink() {
|
|
const history = useHistory()
|
|
const history = useHistory()
|
|
- // const test = useContext(MyContext)
|
|
|
|
|
|
|
|
return (
|
|
return (
|
|
- // { console.log('test: ', test.location) }
|
|
|
|
< Typography
|
|
< Typography
|
|
variant="subtitle1"
|
|
variant="subtitle1"
|
|
sx={{
|
|
sx={{
|
|
@@ -246,8 +39,6 @@ function RegistrationLink() {
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
-// const MyContext = createContext()
|
|
|
|
-
|
|
|
|
// Основное окно регистрации (без полей ввода и кнопок)
|
|
// Основное окно регистрации (без полей ввода и кнопок)
|
|
function AuthReg() {
|
|
function AuthReg() {
|
|
let location = useLocation().pathname === '/'
|
|
let location = useLocation().pathname === '/'
|
|
@@ -259,7 +50,6 @@ function AuthReg() {
|
|
justifyContent: 'center',
|
|
justifyContent: 'center',
|
|
alignItems: 'center'
|
|
alignItems: 'center'
|
|
}}>
|
|
}}>
|
|
- {/* <MyContext.Provider value={{ location: location, text: 'text' }}> */}
|
|
|
|
<Paper elevation={3}
|
|
<Paper elevation={3}
|
|
sx={{
|
|
sx={{
|
|
padding: '5px',
|
|
padding: '5px',
|
|
@@ -296,7 +86,6 @@ function AuthReg() {
|
|
|
|
|
|
{location && <RegistrationLink />}
|
|
{location && <RegistrationLink />}
|
|
</Paper>
|
|
</Paper>
|
|
- {/* </MyContext.Provider > */}
|
|
|
|
</Box >
|
|
</Box >
|
|
)
|
|
)
|
|
}
|
|
}
|