mirror of
https://github.com/Karaka-Management/phpOMS.git
synced 2026-01-11 09:48:40 +00:00
105 lines
2.2 KiB
PHP
105 lines
2.2 KiB
PHP
<?php
|
|
/**
|
|
* Orange Management
|
|
*
|
|
* PHP Version 7.1
|
|
*
|
|
* @category TBD
|
|
* @package TBD
|
|
* @author OMS Development Team <dev@oms.com>
|
|
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
|
* @copyright Dennis Eichhorn
|
|
* @license OMS License 1.0
|
|
* @version 1.0.0
|
|
* @link http://orange-management.com
|
|
*/
|
|
declare(strict_types=1);
|
|
|
|
namespace phpOMS\Auth;
|
|
|
|
use phpOMS\DataStorage\Database\Connection\ConnectionAbstract;
|
|
use phpOMS\DataStorage\Database\DatabaseType;
|
|
use phpOMS\DataStorage\Session\SessionInterface;
|
|
|
|
/**
|
|
* Auth class.
|
|
*
|
|
* Responsible for authenticating and initializing the connection
|
|
*
|
|
* @category Framework
|
|
* @package phpOMS\Auth
|
|
* @author OMS Development Team <dev@oms.com>
|
|
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
|
* @license OMS License 1.0
|
|
* @link http://orange-management.com
|
|
* @since 1.0.0
|
|
*/
|
|
class Auth
|
|
{
|
|
/**
|
|
* Session instance.
|
|
*
|
|
* @var SessionInterface
|
|
* @since 1.0.0
|
|
*/
|
|
private $session = null;
|
|
|
|
/**
|
|
* Database connection instance.
|
|
*
|
|
* @var ConnectionAbstract
|
|
* @since 1.0.0
|
|
*/
|
|
private $connection = null;
|
|
|
|
/**
|
|
* Constructor.
|
|
*
|
|
* @param ConnectionAbstract $connection Database connection
|
|
* @param SessionInterface $session Session
|
|
*
|
|
* @since 1.0.0
|
|
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
|
*/
|
|
public function __construct(ConnectionAbstract $connection, SessionInterface $session)
|
|
{
|
|
$this->connection = $connection;
|
|
$this->session = $session;
|
|
}
|
|
|
|
/**
|
|
* Authenticates user.
|
|
*
|
|
* @return int
|
|
*
|
|
* @since 1.0.0
|
|
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
|
*/
|
|
public function authenticate() : int
|
|
{
|
|
$uid = $this->session->get('UID');
|
|
|
|
if (empty($uid)) {
|
|
return 0;
|
|
}
|
|
|
|
return $uid;
|
|
}
|
|
|
|
/**
|
|
* Logout the given user.
|
|
*
|
|
* @param int $uid User ID
|
|
*
|
|
* @return void
|
|
*
|
|
* @since 1.0.0
|
|
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
|
*/
|
|
public function logout(int $uid = null) /* : void */
|
|
{
|
|
// TODO: logout other users? If admin wants to kick a user for updates etc.
|
|
$this->session->remove('UID');
|
|
}
|
|
}
|