Initial commit

Functional, without SSO
This commit is contained in:
Jimmy Monin
2016-09-18 11:03:26 +02:00
commit 57708e3169
253 changed files with 30787 additions and 0 deletions

View File

@ -0,0 +1,70 @@
<?php
namespace Auth;
abstract class AuthAbstract
{
protected $_username;
protected $_password;
/**
*
* @var App\Storage\User
*/
protected $_storage;
public function __construct(\App\Storage\User $storage)
{
$this->_storage = $storage;
}
/**
* @param string $username
* @return Basic
*/
public function setUsername($username)
{
$this->_username = $username;
return $this;
}
/**
* @return string
*/
public function getUsername()
{
return $this->_username;
}
/**
* @param string $password
* @return Basic
*/
public function setPassword($password)
{
$this->_password = $password;
return $this;
}
/**
* @return string
*/
public function getPassword()
{
return $this->_password;
}
public function authenticate()
{
if (!$this->_username || !$this->_password) {
return null;
}
$user = $this->_storage->fetchByUsername($this->_username);
if ($user && $user->getPassword() == $this->_password) {
return $user;
}
return null;
}
public function clear() {}
}

View File

@ -0,0 +1,19 @@
<?php
namespace Auth;
require_once __DIR__."/Abstract.php";
class Basic extends AuthAbstract
{
public function __construct(\App\Storage\User $storage)
{
if (!$this->_username && isset($_SERVER["PHP_AUTH_USER"])) {
$this->setUsername($_SERVER["PHP_AUTH_USER"]);
}
if (!$this->_password && isset($_SERVER["PHP_AUTH_PW"])) {
$this->setPassword(sha1($_SERVER["PHP_AUTH_PW"]));
}
parent::__construct($storage);
}
}

View File

@ -0,0 +1,45 @@
<?php
namespace Auth;
require_once __DIR__."/Abstract.php";
class Session extends AuthAbstract
{
public function __construct(\App\Storage\User $storage)
{
session_name("lbcalerte");
session_start();
if (isset($_SESSION["lbcauth"])) {
if (isset($_SESSION["lbcauth"]["username"])) {
$this->_username = $_SESSION["lbcauth"]["username"];
}
if (isset($_SESSION["lbcauth"]["password"])) {
$this->_password = $_SESSION["lbcauth"]["password"];
}
}
parent::__construct($storage);
}
public function __destruct()
{
session_write_close();
}
public function clear()
{
unset($_SESSION["lbcauth"]);
}
public function authenticate()
{
if ($user = parent::authenticate()) {
$_SESSION["lbcauth"] = array(
"username" => $user->getUsername(),
"password" => $user->getPassword()
);
return $user;
}
return null;
}
}