Fix LESS import error and refactor project structure
This commit is contained in:
@@ -5,9 +5,6 @@ namespace App\Controllers;
|
||||
use App\Core\Controller;
|
||||
use App\Models\User;
|
||||
|
||||
/**
|
||||
* AuthController - контроллер авторизации
|
||||
*/
|
||||
class AuthController extends Controller
|
||||
{
|
||||
private User $userModel;
|
||||
@@ -17,9 +14,6 @@ class AuthController extends Controller
|
||||
$this->userModel = new User();
|
||||
}
|
||||
|
||||
/**
|
||||
* Форма входа
|
||||
*/
|
||||
public function loginForm(): void
|
||||
{
|
||||
if ($this->isAuthenticated()) {
|
||||
@@ -35,9 +29,6 @@ class AuthController extends Controller
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Обработка входа
|
||||
*/
|
||||
public function login(): void
|
||||
{
|
||||
$email = $this->getPost('email', '');
|
||||
@@ -62,7 +53,6 @@ class AuthController extends Controller
|
||||
return;
|
||||
}
|
||||
|
||||
// Устанавливаем сессию
|
||||
$this->setSession($user);
|
||||
|
||||
$this->json([
|
||||
@@ -71,9 +61,6 @@ class AuthController extends Controller
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Форма регистрации
|
||||
*/
|
||||
public function registerForm(): void
|
||||
{
|
||||
if ($this->isAuthenticated()) {
|
||||
@@ -86,15 +73,11 @@ class AuthController extends Controller
|
||||
'success' => $_SESSION['registration_success'] ?? null
|
||||
]);
|
||||
|
||||
// Очищаем flash данные
|
||||
unset($_SESSION['registration_errors']);
|
||||
unset($_SESSION['old_data']);
|
||||
unset($_SESSION['registration_success']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Обработка регистрации
|
||||
*/
|
||||
public function register(): void
|
||||
{
|
||||
$errors = [];
|
||||
@@ -107,7 +90,6 @@ class AuthController extends Controller
|
||||
$confirmPassword = $this->getPost('confirm-password', '');
|
||||
$privacy = $this->getPost('privacy');
|
||||
|
||||
// Валидация
|
||||
if (empty($fullName) || strlen($fullName) < 3) {
|
||||
$errors[] = 'ФИО должно содержать минимум 3 символа';
|
||||
}
|
||||
@@ -136,7 +118,6 @@ class AuthController extends Controller
|
||||
$errors[] = 'Необходимо согласие с условиями обработки персональных данных';
|
||||
}
|
||||
|
||||
// Проверяем существование email
|
||||
if (empty($errors) && $this->userModel->emailExists($email)) {
|
||||
$errors[] = 'Пользователь с таким email уже существует';
|
||||
}
|
||||
@@ -153,7 +134,6 @@ class AuthController extends Controller
|
||||
return;
|
||||
}
|
||||
|
||||
// Создаем пользователя
|
||||
try {
|
||||
$userId = $this->userModel->register([
|
||||
'email' => $email,
|
||||
@@ -167,10 +147,7 @@ class AuthController extends Controller
|
||||
throw new \Exception('Ошибка при создании пользователя');
|
||||
}
|
||||
|
||||
// Получаем созданного пользователя
|
||||
$user = $this->userModel->find($userId);
|
||||
|
||||
// Устанавливаем сессию
|
||||
$this->setSession($user);
|
||||
|
||||
$_SESSION['registration_success'] = 'Регистрация прошла успешно!';
|
||||
@@ -188,9 +165,6 @@ class AuthController extends Controller
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Выход из системы
|
||||
*/
|
||||
public function logout(): void
|
||||
{
|
||||
session_destroy();
|
||||
@@ -199,9 +173,6 @@ class AuthController extends Controller
|
||||
$this->redirect('/');
|
||||
}
|
||||
|
||||
/**
|
||||
* Установить сессию пользователя
|
||||
*/
|
||||
private function setSession(array $user): void
|
||||
{
|
||||
$_SESSION['user_id'] = $user['user_id'];
|
||||
@@ -214,4 +185,3 @@ class AuthController extends Controller
|
||||
$_SESSION['login_time'] = time();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user