v1.2
This commit is contained in:
@@ -2,321 +2,288 @@
|
||||
<html lang="ru">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=yes">
|
||||
<title>Вход | Rabota.Today</title>
|
||||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0-beta3/css/all.min.css">
|
||||
<style>
|
||||
/* Аналогичные мобильные стили как в register.html */
|
||||
* {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
box-sizing: border-box;
|
||||
font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
|
||||
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
|
||||
}
|
||||
|
||||
body {
|
||||
background: linear-gradient(145deg, #eef5fa 0%, #e0eaf5 100%);
|
||||
background: linear-gradient(145deg, #0b1c34 0%, #1a3650 100%);
|
||||
min-height: 100vh;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
padding: 20px;
|
||||
padding: 10px;
|
||||
}
|
||||
|
||||
.auth-card {
|
||||
max-width: 500px;
|
||||
.login-container {
|
||||
max-width: 400px;
|
||||
width: 100%;
|
||||
background: white;
|
||||
border-radius: 48px;
|
||||
box-shadow: 0 40px 80px -20px rgba(0, 40, 80, 0.4);
|
||||
border-radius: 32px;
|
||||
box-shadow: 0 20px 40px rgba(0, 0, 0, 0.2);
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.auth-header {
|
||||
.login-header {
|
||||
background: #0b1c34;
|
||||
color: white;
|
||||
padding: 40px;
|
||||
padding: 30px 20px;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.auth-header h1 {
|
||||
font-size: 32px;
|
||||
.login-header h1 {
|
||||
font-size: 28px;
|
||||
font-weight: 700;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
gap: 15px;
|
||||
margin-bottom: 10px;
|
||||
gap: 10px;
|
||||
margin-bottom: 5px;
|
||||
}
|
||||
|
||||
.auth-header h1 i {
|
||||
.login-header h1 i {
|
||||
color: #3b82f6;
|
||||
background: rgba(255,255,255,0.1);
|
||||
padding: 12px;
|
||||
border-radius: 20px;
|
||||
}
|
||||
|
||||
.auth-header p {
|
||||
color: #9bb8da;
|
||||
}
|
||||
|
||||
.auth-form {
|
||||
padding: 40px;
|
||||
}
|
||||
|
||||
.tabs {
|
||||
display: flex;
|
||||
gap: 10px;
|
||||
margin-bottom: 30px;
|
||||
background: #f0f7ff;
|
||||
padding: 8px;
|
||||
border-radius: 60px;
|
||||
border-radius: 16px;
|
||||
font-size: 24px;
|
||||
}
|
||||
|
||||
.tab {
|
||||
flex: 1;
|
||||
padding: 15px;
|
||||
text-align: center;
|
||||
border-radius: 50px;
|
||||
cursor: pointer;
|
||||
font-weight: 600;
|
||||
transition: 0.2s;
|
||||
.login-header p {
|
||||
color: #9bb8da;
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
.tab.active {
|
||||
background: white;
|
||||
color: #0b1c34;
|
||||
box-shadow: 0 4px 10px rgba(0,0,0,0.05);
|
||||
.login-form {
|
||||
padding: 30px 20px;
|
||||
}
|
||||
|
||||
.form-group {
|
||||
margin-bottom: 25px;
|
||||
.input-group {
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
.form-group label {
|
||||
.input-group label {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 10px;
|
||||
color: #1f3f60;
|
||||
gap: 5px;
|
||||
font-weight: 600;
|
||||
margin-bottom: 8px;
|
||||
color: #1f3f60;
|
||||
margin-bottom: 5px;
|
||||
font-size: 13px;
|
||||
}
|
||||
|
||||
.form-group label i {
|
||||
.input-group label i {
|
||||
color: #3b82f6;
|
||||
width: 20px;
|
||||
width: 16px;
|
||||
}
|
||||
|
||||
.form-group input {
|
||||
.input-group input {
|
||||
width: 100%;
|
||||
padding: 16px 20px;
|
||||
padding: 14px 16px;
|
||||
background: #f9fcff;
|
||||
border: 2px solid #dee9f5;
|
||||
border-radius: 30px;
|
||||
font-size: 16px;
|
||||
transition: 0.2s;
|
||||
font-size: 15px;
|
||||
-webkit-appearance: none;
|
||||
}
|
||||
|
||||
.form-group input:focus {
|
||||
.input-group input:focus {
|
||||
border-color: #3b82f6;
|
||||
outline: none;
|
||||
box-shadow: 0 0 0 4px rgba(59,130,246,0.15);
|
||||
box-shadow: 0 0 0 3px rgba(59,130,246,0.1);
|
||||
}
|
||||
|
||||
.btn-submit {
|
||||
.btn-login {
|
||||
width: 100%;
|
||||
background: #0f2b4f;
|
||||
color: white;
|
||||
border: none;
|
||||
padding: 18px;
|
||||
border-radius: 50px;
|
||||
padding: 16px;
|
||||
border-radius: 40px;
|
||||
font-weight: 700;
|
||||
font-size: 18px;
|
||||
font-size: 16px;
|
||||
cursor: pointer;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
gap: 10px;
|
||||
transition: 0.2s;
|
||||
gap: 8px;
|
||||
margin: 20px 0 15px;
|
||||
-webkit-tap-highlight-color: transparent;
|
||||
}
|
||||
|
||||
.btn-submit:hover {
|
||||
.btn-login:active {
|
||||
transform: scale(0.98);
|
||||
background: #1b3f6b;
|
||||
}
|
||||
|
||||
.auth-footer {
|
||||
.register-link {
|
||||
text-align: center;
|
||||
margin-top: 25px;
|
||||
color: #4f7092;
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
.auth-footer a {
|
||||
color: #0b1c34;
|
||||
font-weight: 600;
|
||||
.register-link a {
|
||||
color: #3b82f6;
|
||||
text-decoration: none;
|
||||
font-weight: 600;
|
||||
padding: 5px;
|
||||
}
|
||||
|
||||
.error-message {
|
||||
background: #fee2e2;
|
||||
color: #b91c1c;
|
||||
padding: 12px 20px;
|
||||
padding: 12px 16px;
|
||||
border-radius: 30px;
|
||||
margin-bottom: 20px;
|
||||
margin-bottom: 15px;
|
||||
display: none;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
font-size: 13px;
|
||||
}
|
||||
|
||||
.success-message {
|
||||
background: #e0f2e0;
|
||||
color: #166534;
|
||||
padding: 12px 20px;
|
||||
background: #d1fae5;
|
||||
color: #065f46;
|
||||
padding: 12px 16px;
|
||||
border-radius: 30px;
|
||||
margin-bottom: 20px;
|
||||
margin-bottom: 15px;
|
||||
display: none;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
font-size: 13px;
|
||||
}
|
||||
|
||||
.back-link {
|
||||
display: inline-block;
|
||||
margin-top: 20px;
|
||||
.forgot-password {
|
||||
text-align: right;
|
||||
margin: 10px 0;
|
||||
font-size: 13px;
|
||||
}
|
||||
|
||||
.forgot-password a {
|
||||
color: #4f7092;
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
.back-link i {
|
||||
margin-right: 5px;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="auth-card">
|
||||
<div class="auth-header">
|
||||
<div class="login-container">
|
||||
<div class="login-header">
|
||||
<h1>
|
||||
<i class="fas fa-briefcase"></i>
|
||||
МП.Ярмарка
|
||||
Rabota.Today
|
||||
</h1>
|
||||
<p>Вход в личный кабинет</p>
|
||||
</div>
|
||||
|
||||
<div class="auth-form">
|
||||
<div class="tabs">
|
||||
<div class="tab active" onclick="switchTab('login')">Вход</div>
|
||||
<div class="tab" onclick="switchTab('register')">Регистрация</div>
|
||||
<div class="login-form">
|
||||
<div id="errorMessage" class="error-message">
|
||||
<i class="fas fa-exclamation-circle"></i>
|
||||
<span id="errorText"></span>
|
||||
</div>
|
||||
|
||||
<div id="errorMessage" class="error-message"></div>
|
||||
<div id="successMessage" class="success-message"></div>
|
||||
<div id="successMessage" class="success-message">
|
||||
<i class="fas fa-check-circle"></i>
|
||||
<span id="successText"></span>
|
||||
</div>
|
||||
|
||||
<!-- Форма входа -->
|
||||
<form id="loginForm" onsubmit="handleLogin(event)">
|
||||
<div class="form-group">
|
||||
<div class="input-group">
|
||||
<label><i class="fas fa-envelope"></i> Email</label>
|
||||
<input type="email" id="loginEmail" placeholder="ivan@example.com" required>
|
||||
<input type="email" id="email" placeholder="ivan@example.com" required>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<div class="input-group">
|
||||
<label><i class="fas fa-lock"></i> Пароль</label>
|
||||
<input type="password" id="loginPassword" placeholder="Введите пароль" required>
|
||||
<input type="password" id="password" placeholder="Введите пароль" required>
|
||||
</div>
|
||||
|
||||
<button type="submit" class="btn-submit">
|
||||
<i class="fas fa-sign-in-alt"></i> Войти
|
||||
<div class="forgot-password">
|
||||
<a href="#">Забыли пароль?</a>
|
||||
</div>
|
||||
|
||||
<button type="submit" class="btn-login" id="loginBtn">
|
||||
<span>Войти</span>
|
||||
<i class="fas fa-sign-in-alt"></i>
|
||||
</button>
|
||||
</form>
|
||||
|
||||
<!-- Форма регистрации (скрыта по умолчанию) -->
|
||||
<form id="registerForm" style="display: none;" onsubmit="handleRegister(event)">
|
||||
<div class="form-group">
|
||||
<label><i class="fas fa-user"></i> ФИО</label>
|
||||
<input type="text" id="regFullName" placeholder="Иванов Иван Иванович" required>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label><i class="fas fa-envelope"></i> Email</label>
|
||||
<input type="email" id="regEmail" placeholder="ivan@example.com" required>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label><i class="fas fa-phone"></i> Телефон</label>
|
||||
<input type="tel" id="regPhone" placeholder="+7 999 123 45 67" required>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label><i class="fab fa-telegram"></i> Telegram (опционально)</label>
|
||||
<input type="text" id="regTelegram" placeholder="@username">
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label><i class="fas fa-lock"></i> Пароль</label>
|
||||
<input type="password" id="regPassword" placeholder="Минимум 6 символов" required>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label><i class="fas fa-user-tag"></i> Я</label>
|
||||
<select id="regRole" style="width: 100%; padding: 16px 20px; border: 2px solid #dee9f5; border-radius: 30px;">
|
||||
<option value="employee">Соискатель</option>
|
||||
<option value="employer">Работодатель</option>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<button type="submit" class="btn-submit">
|
||||
<i class="fas fa-check-circle"></i> Зарегистрироваться
|
||||
</button>
|
||||
</form>
|
||||
|
||||
<div class="auth-footer">
|
||||
<a href="/" class="back-link"><i class="fas fa-arrow-left"></i> На главную</a>
|
||||
<div class="register-link">
|
||||
Нет аккаунта?
|
||||
<a href="/register">Зарегистрироваться</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
const API_BASE_URL = 'http://localhost:8000/api';
|
||||
|
||||
function switchTab(tab) {
|
||||
const tabs = document.querySelectorAll('.tab');
|
||||
const loginForm = document.getElementById('loginForm');
|
||||
const registerForm = document.getElementById('registerForm');
|
||||
|
||||
tabs.forEach(t => t.classList.remove('active'));
|
||||
|
||||
if (tab === 'login') {
|
||||
tabs[0].classList.add('active');
|
||||
loginForm.style.display = 'block';
|
||||
registerForm.style.display = 'none';
|
||||
} else {
|
||||
tabs[1].classList.add('active');
|
||||
loginForm.style.display = 'none';
|
||||
registerForm.style.display = 'block';
|
||||
}
|
||||
}
|
||||
const currentProtocol = window.location.protocol; // http: или https:
|
||||
const currentHost = window.location.host; // yarmarka.rabota.today или IP:порт
|
||||
let API_BASE_URL = `${currentProtocol}//${currentHost}/api`;
|
||||
let isSubmitting = false;
|
||||
|
||||
function showError(message) {
|
||||
const errorEl = document.getElementById('errorMessage');
|
||||
errorEl.textContent = message;
|
||||
errorEl.style.display = 'block';
|
||||
const errorDiv = document.getElementById('errorMessage');
|
||||
const errorText = document.getElementById('errorText');
|
||||
errorText.textContent = message;
|
||||
errorDiv.style.display = 'flex';
|
||||
|
||||
setTimeout(() => {
|
||||
errorEl.style.display = 'none';
|
||||
}, 5000);
|
||||
errorDiv.style.display = 'none';
|
||||
}, 4000);
|
||||
}
|
||||
|
||||
function showSuccess(message) {
|
||||
const successEl = document.getElementById('successMessage');
|
||||
successEl.textContent = message;
|
||||
successEl.style.display = 'block';
|
||||
setTimeout(() => {
|
||||
successEl.style.display = 'none';
|
||||
}, 3000);
|
||||
const successDiv = document.getElementById('successMessage');
|
||||
const successText = document.getElementById('successText');
|
||||
successText.textContent = message;
|
||||
successDiv.style.display = 'flex';
|
||||
}
|
||||
|
||||
function setLoading(isLoading) {
|
||||
const btn = document.getElementById('loginBtn');
|
||||
if (isLoading) {
|
||||
btn.innerHTML = '<i class="fas fa-spinner fa-spin"></i> Вход...';
|
||||
btn.disabled = true;
|
||||
isSubmitting = true;
|
||||
} else {
|
||||
btn.innerHTML = '<span>Войти</span><i class="fas fa-sign-in-alt"></i>';
|
||||
btn.disabled = false;
|
||||
isSubmitting = false;
|
||||
}
|
||||
}
|
||||
|
||||
async function handleLogin(event) {
|
||||
event.preventDefault();
|
||||
|
||||
const email = document.getElementById('loginEmail').value;
|
||||
const password = document.getElementById('loginPassword').value;
|
||||
if (isSubmitting) return;
|
||||
|
||||
const email = document.getElementById('email').value.trim();
|
||||
const password = document.getElementById('password').value;
|
||||
|
||||
if (!email || !password) {
|
||||
showError('Введите email и пароль');
|
||||
return;
|
||||
}
|
||||
|
||||
setLoading(true);
|
||||
|
||||
try {
|
||||
const response = await fetch(`${API_BASE_URL}/login`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'Accept': 'application/json',
|
||||
'X-Requested-With': 'XMLHttpRequest'
|
||||
},
|
||||
body: JSON.stringify({ email, password })
|
||||
body: JSON.stringify({ email, password }),
|
||||
credentials: 'include'
|
||||
});
|
||||
|
||||
const data = await response.json();
|
||||
@@ -325,80 +292,26 @@
|
||||
throw new Error(data.detail || 'Ошибка входа');
|
||||
}
|
||||
|
||||
// Сохраняем токен
|
||||
// Сохраняем данные
|
||||
localStorage.setItem('accessToken', data.access_token);
|
||||
localStorage.setItem('userId', data.user_id);
|
||||
localStorage.setItem('userRole', data.role);
|
||||
localStorage.setItem('userName', data.full_name);
|
||||
|
||||
showSuccess('Вход выполнен успешно!');
|
||||
showSuccess('Вход выполнен! Перенаправляем...');
|
||||
|
||||
// Перенаправляем в зависимости от роли
|
||||
setTimeout(() => {
|
||||
if (data.role === 'employer') {
|
||||
window.location.href = '/profile';
|
||||
} else {
|
||||
window.location.href = '/profile';
|
||||
}
|
||||
}, 1000);
|
||||
|
||||
} catch (error) {
|
||||
showError(error.message);
|
||||
}
|
||||
}
|
||||
|
||||
async function handleRegister(event) {
|
||||
event.preventDefault();
|
||||
|
||||
const userData = {
|
||||
full_name: document.getElementById('regFullName').value,
|
||||
email: document.getElementById('regEmail').value,
|
||||
phone: document.getElementById('regPhone').value,
|
||||
telegram: document.getElementById('regTelegram').value || null,
|
||||
password: document.getElementById('regPassword').value,
|
||||
role: document.getElementById('regRole').value
|
||||
};
|
||||
|
||||
// Валидация
|
||||
if (userData.password.length < 6) {
|
||||
showError('Пароль должен быть не менее 6 символов');
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const response = await fetch(`${API_BASE_URL}/register`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify(userData)
|
||||
});
|
||||
|
||||
const data = await response.json();
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(data.detail || 'Ошибка регистрации');
|
||||
}
|
||||
|
||||
// Сохраняем токен
|
||||
localStorage.setItem('accessToken', data.access_token);
|
||||
localStorage.setItem('userId', data.user_id);
|
||||
localStorage.setItem('userRole', data.role);
|
||||
localStorage.setItem('userName', data.full_name);
|
||||
|
||||
showSuccess('Регистрация успешна!');
|
||||
|
||||
// Перенаправляем в профиль
|
||||
setTimeout(() => {
|
||||
window.location.href = '/profile';
|
||||
}, 1000);
|
||||
}, 1500);
|
||||
|
||||
} catch (error) {
|
||||
console.error('Login error:', error);
|
||||
showError(error.message);
|
||||
setLoading(false);
|
||||
}
|
||||
}
|
||||
|
||||
// Проверяем, может пользователь уже залогинен
|
||||
// Проверка существующей сессии
|
||||
if (localStorage.getItem('accessToken')) {
|
||||
window.location.href = '/profile';
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user