cyrilleinvalides/choupas/www/admin/app/cache/debug/libs/sense/Auth.php

66 lines
1.0 KiB
PHP

<?php
// singleton
class Auth extends Controller {
private static $instance;
private $service, $user;
static public function get ( Service $service = null ) {
if ( self::$instance )
return self::$instance;
return self::$instance = new self($service);
}
protected function __construct ( Service $service ) {
parent::__construct();
$this->service = $service;
$this->user = $this->restore('user');
}
public function getUser () {
return $this->user;
}
// Action Interface
public function login ( $user ) {
// query for ( login, pass )
$users = $this->service;
// no match ( login, pass )
if ( empty($users[$user['login']]) )
throw new Exception('Wrong user !');
if ( $users[$user['login']]['password'] !== $user['password'] )
throw new Exception('Wrong password !');
$this->user = $users[$user['login']];
$this->store('user', $this->user);
}
public function logout () {
$this->user = null;
$this->store('user', null);
$_SESSION = array();
}
}
?>