nativegallery/app/Services/Auth.php

32 lines
767 B
PHP
Raw Permalink Normal View History

2024-07-04 12:04:41 +03:00
<?php
namespace App\Services;
use App\Services\{DB, GenerateRandomStr};
class Auth
{
public static function userid()
{
$userid = 0;
2024-07-05 06:09:25 +03:00
if (!empty($_COOKIE['NGALLERYSESS']) && !empty($_COOKIE['NGALLERYSESS_'])) {
2024-07-04 12:04:41 +03:00
$userInfo = DB::query('SELECT user_id FROM login_tokens WHERE token=:token', array(':token' => $_COOKIE['NGALLERYSESS']));
if ($userInfo && count($userInfo) > 0) {
$userid = $userInfo[0]['user_id'];
2024-07-05 06:09:25 +03:00
2024-07-05 06:33:46 +03:00
DB::query('UPDATE users SET online=:timed WHERE id=:id', array(':id'=>$userid, ':timed'=>time()));
2024-07-04 12:04:41 +03:00
}
}
2024-07-05 06:09:25 +03:00
return (int)$userid;
2024-07-04 12:04:41 +03:00
}
public static function token()
{
return $_COOKIE['NGALLERYSESS'];
}
}
?>