/
Skiqa
/
eduwork.local
Обзор
Документация
Войти
/
Skiqa
/
eduwork.local
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
modules/auth/Auth.php
36 строк
978 B
olbin
Небольшой рефакторинг
22 мар 2025, 18:26
22 мар 2025, 18:26
fa32ddc
Код
Авторство
О чём код?
<?php class Auth { public PDO $conn; public function __construct(PDO $conn) { $this->conn = $conn; } public function login() { $username = $_POST['username']; $password = $_POST['password']; $stmt = $this->conn->prepare("SELECT id, password, role FROM users WHERE username = ?"); $stmt->execute([$username]); $user = $stmt->fetch(PDO::FETCH_ASSOC); if ($user && password_verify($password, $user['password'])) { $_SESSION['user_id'] = $user['id']; $_SESSION['role'] = $user['role']; if ($user['role'] == 'admin') { header('Location: ../../../admin/admin_panel.php'); } else { header('Location: ../../../index.php'); } exit(); } } public function logout() { session_destroy(); header('Location: http://localhost/eduwork.local/index.php'); exit(); } } ?>