reset password form 1.0
This commit is contained in:
@@ -16,7 +16,7 @@
|
||||
<div class="options">
|
||||
<input type="checkbox" id="remember" name="remember">
|
||||
<label for="remember"> Remember me</label>
|
||||
<a href="#">Forgot Password?</a>
|
||||
<a href="./../reset/index.html" id="reset">Forgot Password?</a>
|
||||
</div>
|
||||
<button type="submit">Login</button>
|
||||
<p>Don't have an account? <a href="./../register/index.html" id="register">Register</a></p>
|
||||
|
||||
22
server/front/reset/index.html
Normal file
22
server/front/reset/index.html
Normal file
@@ -0,0 +1,22 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Login</title>
|
||||
<link rel="stylesheet" href="./style.css">
|
||||
</head>
|
||||
<body>
|
||||
<div class="glass-container">
|
||||
<div class="login-box">
|
||||
<h2>Login</h2>
|
||||
<form id="loginForm">
|
||||
<input type="text" id="email" name="email" required placeholder="Email">
|
||||
<button type="submit">Reset</button>
|
||||
<p>Have an account? <a href="./../login/" id="login">Login</a></p>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
<script src="js.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
66
server/front/reset/js.js
Normal file
66
server/front/reset/js.js
Normal file
@@ -0,0 +1,66 @@
|
||||
function getToken() {
|
||||
return localStorage.getItem("token") || sessionStorage.getItem("token");
|
||||
}
|
||||
function tokenCheck(){
|
||||
const token = getToken();
|
||||
if (!token) {
|
||||
window.location.href = "./../main/index.html";
|
||||
}
|
||||
}
|
||||
document.getElementById('loginForm').addEventListener('submit', async function (e) {
|
||||
e.preventDefault();
|
||||
const email = document.getElementById('email').value;
|
||||
const userData = {
|
||||
email
|
||||
};
|
||||
try {
|
||||
const response = await fetch("http://localhost:8000/reset", {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify(userData)
|
||||
});
|
||||
const data = await response.json(); // читаем только один раз
|
||||
if (response.ok) { // сохраняем только при успехе
|
||||
window.location.href = './../login/index.html';
|
||||
} else { //парсинг и вывод ошибок, если есть
|
||||
if (Array.isArray(data.detail)) {
|
||||
const messages = data.detail.map(e => {
|
||||
const field = e.loc.filter(locPart => locPart !== 'body').join(' -> ');
|
||||
return `${field}: ${e.msg}`;
|
||||
});
|
||||
showError(messages);
|
||||
} else if (typeof data.detail === 'string') {
|
||||
showError([data.detail]);
|
||||
} else {
|
||||
showError(['Unknown error']);
|
||||
}
|
||||
}
|
||||
} catch (err) {
|
||||
showError(['Connection error: ' + err.message]);
|
||||
}
|
||||
});
|
||||
function showError(messages){ //Добавление их на form со стилями
|
||||
let errorElem = document.getElementById('formError');
|
||||
let container = document.getElementById('glass-container');
|
||||
if (!errorElem){
|
||||
errorElem = document.createElement('div');
|
||||
errorElem.style.transition="3s";
|
||||
errorElem.id = 'formError';
|
||||
errorElem.style.color = 'red';
|
||||
errorElem.style.marginTop = '20px';
|
||||
errorElem.style.fontSize = '14px';
|
||||
errorElem.style.fontWeight = '100';
|
||||
errorElem.style.marginBottom = '20px';
|
||||
errorElem.style.lineHeight="120%";
|
||||
errorElem.style.height = 'auto';
|
||||
const form = document.getElementById('loginForm');
|
||||
form.insertAdjacentElement('afterend', errorElem);
|
||||
};
|
||||
errorElem.innerHTML = '';
|
||||
messages.forEach(msg => {
|
||||
const li = document.createElement('li');
|
||||
li.style.listStyleType="none";
|
||||
li.textContent = msg;
|
||||
errorElem.appendChild(li);
|
||||
});
|
||||
}
|
||||
102
server/front/reset/style.css
Normal file
102
server/front/reset/style.css
Normal file
@@ -0,0 +1,102 @@
|
||||
* {
|
||||
margin: 0;
|
||||
box-sizing: border-box;
|
||||
font-family: 'Poppins', sans-serif;
|
||||
}
|
||||
|
||||
body {
|
||||
margin: 0;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
height: 100vh;
|
||||
background-image: url('./../login/background-image.jpeg');
|
||||
background-size: cover;
|
||||
}
|
||||
|
||||
.glass-container {
|
||||
width: 300px;
|
||||
height: 350px;
|
||||
position: relative;
|
||||
z-index: 1;
|
||||
background: rgba(255, 255, 255, 0.1);
|
||||
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
|
||||
border-radius: 10px;
|
||||
border: 1px solid #fff;
|
||||
}
|
||||
|
||||
.glass-container::before {
|
||||
content: '';
|
||||
position: absolute;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
border-radius: 10px;
|
||||
backdrop-filter: blur(5px);
|
||||
-webkit-backdrop-filter: blur(5px);
|
||||
z-index: -1;
|
||||
}
|
||||
|
||||
.login-box {
|
||||
max-width: 250px;
|
||||
margin: 0 auto;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
h2 {
|
||||
color: #fff;
|
||||
margin-top: 30px;
|
||||
margin-bottom: -20px;
|
||||
}
|
||||
|
||||
form {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
margin-top: 20px;
|
||||
}
|
||||
|
||||
input {
|
||||
padding: 10px;
|
||||
margin-top: 25px;
|
||||
border: none;
|
||||
border-radius: 10px;
|
||||
background: transparent;
|
||||
border: 1px solid #fff;
|
||||
color: #fff;
|
||||
font-size: 13px;
|
||||
}
|
||||
|
||||
input::placeholder {
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
input:focus {
|
||||
outline: none;
|
||||
}
|
||||
|
||||
button {
|
||||
background: #fff;
|
||||
color: black;
|
||||
padding: 10px;
|
||||
border: none;
|
||||
border-radius: 10px;
|
||||
cursor: pointer;
|
||||
margin-top: 15px;
|
||||
}
|
||||
|
||||
button:hover {
|
||||
background: transparent;
|
||||
color: white;
|
||||
outline: 1px solid #fff;
|
||||
}
|
||||
|
||||
p {
|
||||
font-size: 12px;
|
||||
color: #fff;
|
||||
margin-top: 15px;
|
||||
}
|
||||
|
||||
#login {
|
||||
text-decoration: none;
|
||||
color: #fff;
|
||||
font-weight: bold;
|
||||
}
|
||||
Reference in New Issue
Block a user