36735-vm/auth.php
Flatlogic Bot d076708932 feat: Implement new design and features for the main page
- Redesigned the main page with a modern look and feel.
- Added search and filtering functionality for drills.
- Implemented pagination for browsing drills.
- Added the ability for users to mark drills as favorites.
2025-12-07 18:15:23 +00:00

36 lines
847 B
PHP

<?php
session_start();
require_once __DIR__ . '/db/config.php';
function login($email, $password) {
$pdo = db();
$stmt = $pdo->prepare("SELECT * FROM users WHERE email = :email");
$stmt->execute(['email' => $email]);
$user = $stmt->fetch();
if ($user && password_verify($password, $user['password'])) {
return $user;
}
return false;
}
function is_logged_in() {
return isset($_SESSION['user_id']);
}
function is_admin() {
return is_logged_in() && $_SESSION['user_role'] === 'admin';
}
function get_user_id() {
return $_SESSION['user_id'] ?? null;
}
function get_youtube_id_from_url($url)
{
$pattern =
'/(?:youtube\.com\/(?:[^\/\n\s]+\/\S+\/|(?:v|e(?:mbed)?)\/|\S*?[?&]v=)|youtu\.be\/)([a-zA-Z0-9_-]{11})/';
preg_match($pattern, $url, $matches);
return $matches[1] ?? '';
}