From 9f1906c4cbb9878c5888723b7923fa8e4bebb51f Mon Sep 17 00:00:00 2001 From: ilotterytea Date: Sun, 27 Apr 2025 21:12:02 +0500 Subject: feat: roles --- src/accounts.php | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'src/accounts.php') diff --git a/src/accounts.php b/src/accounts.php index 87c8ef0..f97998a 100644 --- a/src/accounts.php +++ b/src/accounts.php @@ -41,6 +41,19 @@ function authorize_user(bool $required = false): bool $stmt = $db->prepare("UPDATE users SET last_active_at = UTC_TIMESTAMP WHERE id = ?"); $stmt->execute([$row["id"]]); + + // fetching role + $stmt = $db->prepare("SELECT * FROM roles r + INNER JOIN role_assigns ra ON ra.user_id = ? + WHERE r.id = ra.role_id + "); + $stmt->execute([$row["id"]]); + + $_SESSION["user_role"] = null; + + if ($role_row = $stmt->fetch(PDO::FETCH_ASSOC)) { + $_SESSION["user_role"] = $role_row; + } } else { session_regenerate_id(); session_unset(); @@ -61,5 +74,6 @@ function authorize_user(bool $required = false): bool } $db = null; + $stmt = null; return isset($_SESSION["user_name"]); } \ No newline at end of file -- cgit v1.2.3