Улучшения Системы авторизации
This commit is contained in:
parent
aef12e853d
commit
13754eecc3
4 changed files with 767 additions and 78 deletions
|
|
@ -17,6 +17,17 @@ import { SITE_URL } from '@constants';
|
|||
</div>
|
||||
|
||||
<form class="auth-form" id="sign-in-form">
|
||||
<div class="form-group honeypot-field">
|
||||
<input
|
||||
type="text"
|
||||
name="website_url"
|
||||
id="website_url"
|
||||
tabindex="-1"
|
||||
autocomplete="off"
|
||||
class="honeypot"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="email">Email</label>
|
||||
<input
|
||||
|
|
@ -26,19 +37,34 @@ import { SITE_URL } from '@constants';
|
|||
placeholder="example@mail.ru"
|
||||
required
|
||||
autocomplete="email"
|
||||
inputmode="email"
|
||||
/>
|
||||
<span class="error-message" id="email-error"></span>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="password">Пароль</label>
|
||||
<input
|
||||
type="password"
|
||||
id="password"
|
||||
name="password"
|
||||
placeholder="••••••••"
|
||||
required
|
||||
autocomplete="current-password"
|
||||
/>
|
||||
<div class="password-wrapper">
|
||||
<input
|
||||
type="password"
|
||||
id="password"
|
||||
name="password"
|
||||
placeholder="••••••••"
|
||||
required
|
||||
autocomplete="current-password"
|
||||
/>
|
||||
<button type="button" class="toggle-password" data-target="password">
|
||||
<svg class="eye-open" xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
||||
<path d="M1 12s4-8 11-8 11 8 11 8-4 8-11 8-11-8-11-8z"></path>
|
||||
<circle cx="12" cy="12" r="3"></circle>
|
||||
</svg>
|
||||
<svg class="eye-closed" xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
||||
<path d="M17.94 17.94A10.07 10.07 0 0 1 12 20c-7 0-11-8-11-8a18.45 18.45 0 0 1 5.06-5.94M9.9 4.24A9.12 9.12 0 0 1 12 4c7 0 11 8 11 8a18.5 18.5 0 0 1-2.16 3.19m-6.72-1.07a3 3 0 1 1-4.24-4.24"></path>
|
||||
<line x1="1" y1="1" x2="23" y2="23"></line>
|
||||
</svg>
|
||||
</button>
|
||||
</div>
|
||||
<span class="error-message" id="password-error"></span>
|
||||
</div>
|
||||
|
||||
<div class="form-options">
|
||||
|
|
@ -82,14 +108,14 @@ import { SITE_URL } from '@constants';
|
|||
.auth-card {
|
||||
background: #ffffff;
|
||||
border-radius: 16px;
|
||||
padding: 2rem 1.75rem;
|
||||
padding: 1.5rem 1.5rem;
|
||||
box-shadow: 0 10px 40px rgba(0, 0, 0, 0.1);
|
||||
}
|
||||
|
||||
/* Заголовок */
|
||||
.auth-header {
|
||||
text-align: center;
|
||||
margin-bottom: 1.5rem;
|
||||
margin-bottom: 1rem;
|
||||
}
|
||||
|
||||
.auth-header h1 {
|
||||
|
|
@ -110,26 +136,26 @@ import { SITE_URL } from '@constants';
|
|||
.auth-form {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 1rem;
|
||||
gap: 0.5rem;
|
||||
}
|
||||
|
||||
.form-group {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.4rem;
|
||||
gap: 0.2rem;
|
||||
}
|
||||
|
||||
.form-group label {
|
||||
color: #1e3050;
|
||||
font-size: 0.85rem;
|
||||
font-size: 0.8rem;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.form-group input {
|
||||
padding: 0.7rem 0.9rem;
|
||||
padding: 0.6rem 0.75rem;
|
||||
border: 1px solid #e2e8f0;
|
||||
border-radius: 8px;
|
||||
font-size: 0.95rem;
|
||||
font-size: 0.9rem;
|
||||
transition: all 0.2s ease;
|
||||
background: #f8fafc;
|
||||
}
|
||||
|
|
@ -141,10 +167,75 @@ import { SITE_URL } from '@constants';
|
|||
background: #ffffff;
|
||||
}
|
||||
|
||||
.password-wrapper {
|
||||
position: relative;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.password-wrapper input {
|
||||
width: 100%;
|
||||
padding-right: 2.5rem;
|
||||
}
|
||||
|
||||
.toggle-password {
|
||||
position: absolute;
|
||||
right: 0.75rem;
|
||||
background: none;
|
||||
border: none;
|
||||
cursor: pointer;
|
||||
color: #94a3b8;
|
||||
padding: 0;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
transition: color 0.2s ease;
|
||||
}
|
||||
|
||||
.toggle-password:hover {
|
||||
color: #d4af37;
|
||||
}
|
||||
|
||||
.toggle-password .eye-closed {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.toggle-password.active .eye-open {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.toggle-password.active .eye-closed {
|
||||
display: block;
|
||||
}
|
||||
|
||||
.form-group input::placeholder {
|
||||
color: #94a3b8;
|
||||
}
|
||||
|
||||
/* Honeypot поле */
|
||||
.honeypot-field {
|
||||
position: absolute;
|
||||
left: -9999px;
|
||||
opacity: 0;
|
||||
pointer-events: none;
|
||||
}
|
||||
|
||||
/* Сообщения об ошибках */
|
||||
.error-message {
|
||||
color: #ef4444;
|
||||
font-size: 0.75rem;
|
||||
min-height: 1rem;
|
||||
margin-top: 0.25rem;
|
||||
}
|
||||
|
||||
.form-group input.error {
|
||||
border-color: #ef4444;
|
||||
}
|
||||
|
||||
.form-group input.error:focus {
|
||||
box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.1);
|
||||
}
|
||||
|
||||
/* Опции формы */
|
||||
.form-options {
|
||||
display: flex;
|
||||
|
|
@ -185,12 +276,12 @@ import { SITE_URL } from '@constants';
|
|||
color: #ffffff;
|
||||
border: none;
|
||||
border-radius: 8px;
|
||||
padding: 1rem;
|
||||
font-size: 1rem;
|
||||
padding: 0.75rem;
|
||||
font-size: 0.95rem;
|
||||
font-weight: 700;
|
||||
cursor: pointer;
|
||||
transition: all 0.3s ease;
|
||||
margin-top: 0.5rem;
|
||||
margin-top: 0.25rem;
|
||||
}
|
||||
|
||||
.btn-submit:hover {
|
||||
|
|
@ -246,18 +337,89 @@ import { SITE_URL } from '@constants';
|
|||
</style>
|
||||
|
||||
<script>
|
||||
// Обработка отправки формы
|
||||
const emailInput = document.getElementById('email') as HTMLInputElement;
|
||||
const passwordInput = document.getElementById('password') as HTMLInputElement;
|
||||
|
||||
function showError(input: HTMLInputElement, message: string) {
|
||||
const errorSpan = document.getElementById(`${input.id}-error`);
|
||||
if (errorSpan) {
|
||||
errorSpan.textContent = message;
|
||||
}
|
||||
input.classList.add('error');
|
||||
}
|
||||
|
||||
function clearError(input: HTMLInputElement) {
|
||||
const errorSpan = document.getElementById(`${input.id}-error`);
|
||||
if (errorSpan) {
|
||||
errorSpan.textContent = '';
|
||||
}
|
||||
input.classList.remove('error');
|
||||
}
|
||||
|
||||
function validateEmail(value: string): boolean {
|
||||
const regex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
|
||||
return regex.test(value);
|
||||
}
|
||||
|
||||
document.querySelectorAll('.toggle-password').forEach(button => {
|
||||
button.addEventListener('click', () => {
|
||||
const targetId = button.getAttribute('data-target');
|
||||
const input = document.getElementById(targetId) as HTMLInputElement;
|
||||
if (input) {
|
||||
const isPassword = input.type === 'password';
|
||||
input.type = isPassword ? 'text' : 'password';
|
||||
button.classList.toggle('active', isPassword);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
emailInput?.addEventListener('input', () => {
|
||||
const value = emailInput.value.replace(/[^\w@\.\-]/g, '');
|
||||
emailInput.value = value;
|
||||
if (emailInput.value && !validateEmail(emailInput.value)) {
|
||||
showError(emailInput, 'Введите корректный email');
|
||||
} else {
|
||||
clearError(emailInput);
|
||||
}
|
||||
});
|
||||
|
||||
passwordInput?.addEventListener('input', () => {
|
||||
if (passwordInput.value) {
|
||||
clearError(passwordInput);
|
||||
}
|
||||
});
|
||||
|
||||
document.getElementById('sign-in-form')?.addEventListener('submit', async (e) => {
|
||||
e.preventDefault();
|
||||
|
||||
const form = e.target as HTMLFormElement;
|
||||
const formData = new FormData(form);
|
||||
|
||||
const honeypot = formData.get('website_url') as string;
|
||||
if (honeypot && honeypot.trim() !== '') {
|
||||
alert('Доступ запрещён');
|
||||
return;
|
||||
}
|
||||
|
||||
const email = formData.get('email') as string;
|
||||
const password = formData.get('password') as string;
|
||||
|
||||
// Здесь будет логика отправки на сервер
|
||||
let hasErrors = false;
|
||||
|
||||
if (!validateEmail(email)) {
|
||||
showError(emailInput, 'Введите корректный email');
|
||||
hasErrors = true;
|
||||
}
|
||||
|
||||
if (!password || password.trim() === '') {
|
||||
showError(passwordInput, 'Введите пароль');
|
||||
hasErrors = true;
|
||||
}
|
||||
|
||||
if (hasErrors) {
|
||||
return;
|
||||
}
|
||||
|
||||
console.log('Вход:', { email, password });
|
||||
|
||||
// Пример: await fetch('/api/auth/signin', { method: 'POST', body: JSON.stringify({ email, password }) });
|
||||
});
|
||||
</script>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue