Commit 1ea31ee9 authored by Nurasyl's avatar Nurasyl

Initial commit

parents
document.addEventListener("DOMContentLoaded", () => {
let authLoginInputVal = "";
let authPasswordInputVal = "";
let regisLoginInputVal = "";
let regisPasswordInputVal = "";
let regisPasswordVerifyInputVal = "";
const changeHandler = (event) => {
switch (event.target.className) {
case "authLogin":
authLoginInputVal = event.target.value;
break;
case "authPassword":
authPasswordInputVal = event.target.value;
break;
case "regisLogin":
regisLoginInputVal = event.target.value;
break;
case "regisPassword":
regisPasswordInputVal = event.target.value;
break;
case "regisVerifyPassword":
regisPasswordVerifyInputVal = event.target.value;
break;
default:
break;
};
};
const clickHandler = (event) => {
if(event.target.className === "spanCreate") {
formLogin.style.display = "none";
formRegister.style.display = "flex";
} else {
formLogin.style.display = "flex";
formRegister.style.display = "none";
};
};
const formLogin = document.getElementById("form_login");
const authLoginInput = formLogin.children[1];
const authPasswordInput = formLogin.children[2];
const authSpan = formLogin.children[4];
const formRegister = document.getElementById("register_form");
const regisLoginInput = formRegister.children[1];
const regisPasswordInput = formRegister.children[2];
const regisPasswordVerifyInput = formRegister.children[3];
const regisSpan = formRegister.children[5];
authLoginInput.addEventListener("keydown", changeHandler);
authPasswordInput.addEventListener("keydown", changeHandler);
regisLoginInput.addEventListener("keydown", changeHandler);
regisPasswordInput.addEventListener("keydown", changeHandler);
regisPasswordVerifyInput.addEventListener("keydown", changeHandler);
authSpan.addEventListener("click", clickHandler);
regisSpan.addEventListener("click", clickHandler);
formLogin.addEventListener("submit", (event) => {
event.preventDefault();
if(!authLoginInputVal || !authPasswordInputVal) {
alert("Заполните все поля!");
} else {
const storageLogin = localStorage.getItem("login");
if(authLoginInputVal === storageLogin) {
alert(`Добро пожаловать! ${authLoginInputVal}`);
} else {
alert("Пользователь с таким логином не найден.")
};
};
});
formRegister.addEventListener("submit", (event) => {
event.preventDefault();
if(!regisLoginInputVal || !regisPasswordInputVal || !regisPasswordVerifyInputVal) {
alert("Заполните все поля!");
} else {
console.log(regisPasswordVerifyInputVal, regisPasswordInputVal);
if(regisPasswordInputVal === regisPasswordVerifyInputVal) {
alert(`Добро пожаловать! ${regisLoginInputVal}`);
localStorage.setItem("login", regisLoginInputVal);
} else {
alert("Пароль не совпадает");
};
};
});
});
\ No newline at end of file
* {
box-sizing: border-box;
}
.container {
width: 1200px;
margin: 0 auto;
display: flex;
justify-content: center;
}
.form {
border: 1px solid gray;
border-radius: 15px;
padding: 15px 25px;
display: flex;
flex-direction: column;
align-items: center;
justify-content: space-around;
background-color: bisque;
height: 300px;
width: 300px;
}
.form input, button {
width: 90%;
height: 35px;
border-radius: 5px;
}
.form span {
cursor: pointer;
}
.form span:hover {
color: cadetblue;
}
#register_form {
display: none;
}
\ No newline at end of file
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="./Styles/style.css">
<script src="./JS/index.js"></script>
<title>Document</title>
</head>
<body>
<div class="container">
<form class="form" id="form_login">
<h1>Авторизация</h1>
<input class="authLogin" type="text" placeholder="Логин">
<input class="authPassword" type="password" placeholder="Пароль">
<button type="submit">Войти</button>
<span class="spanCreate">Нет аккаунта? Создать...</span>
</form>
<form class="form" id="register_form">
<h1>Регистрация</h1>
<input class="regisLogin" type="text" placeholder="Логин">
<input class="regisPassword" type="password" placeholder="Пароль">
<input class="regisVerifyPassword" type="password" placeholder="Повторно введите пароль">
<button type="submit">Регистрация</button>
<span class="spanLogin">Уже есть аккаунта? Войти...</span>
</form>
</div>
</body>
</html>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment