This repository has been archived on 2024-06-26. You can view files and clone it, but cannot push or open issues or pull requests.
sakura/app/ActiveUser.php

49 lines
1.2 KiB
PHP
Raw Normal View History

2016-03-31 20:03:25 +00:00
<?php
/**
* Holds information about the currently active session
*
* @package Sakura
*/
namespace Sakura;
use Sakura\Perms\Site;
/**
* Information about the current active user and session.
*
* @package Sakura
* @author Julian van de Groep <me@flash.moe>
*/
class ActiveUser
{
public static $user = null;
public static $session = null;
public static function init($userId, $sessionId)
{
// Create a session object
self::$session = new Session($userId, $sessionId);
// Create a user object
$user = User::construct($userId);
// Check if the session exists and check if the user is activated
if (self::$session->validate() > 0
&& !$user->permission(Site::DEACTIVATED)) {
// Assign the user object
self::$user = $user;
// Update last online
DB::table('users')
->where('user_id', self::$user->id)
->update([
'user_last_online' => time(),
2016-04-25 02:01:14 +00:00
'last_ip' => Net::pton(Net::ip()),
2016-03-31 20:03:25 +00:00
]);
} else {
self::$user = User::construct(0);
}
}
}