new-bigly-chat/libs/auth.php

29 lines
757 B
PHP
Raw Normal View History

2024-11-26 11:38:28 -05:00
<?php
require("../libs/test_secret.php");
function auth($token) {
2024-11-27 00:13:33 -05:00
if (is_null($token)) return null;
2024-11-26 11:38:28 -05:00
global $db;
2024-11-26 23:37:16 -05:00
$stmt = $db->prepare("SELECT * FROM main.token WHERE token = ?");
2024-11-26 11:38:28 -05:00
$stmt->execute([$token]);
$result = $stmt->fetch(PDO::FETCH_ASSOC);
2024-11-27 00:13:33 -05:00
if (!$result) return null;
2024-11-26 11:38:28 -05:00
$username = $result['username'];
2024-11-26 23:37:16 -05:00
$stmt = $db->prepare("SELECT * FROM main.auth WHERE username = ?");
2024-11-26 11:38:28 -05:00
$stmt->execute([$username]);
$result = $stmt->fetch(PDO::FETCH_ASSOC);
2024-11-27 00:13:33 -05:00
if (!$result) return null;
2024-11-26 11:38:28 -05:00
return $username;
}
2024-12-02 07:59:45 -05:00
if (array_key_exists('token',$_COOKIE)) {
$username = auth($_COOKIE['token']);
}
2024-11-26 11:38:28 -05:00
?>