mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-18 23:43:12 +00:00
cleanup
This commit is contained in:
@@ -9,6 +9,7 @@
|
|||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
use Alchemy\Phrasea\Application;
|
||||||
use Symfony\Component\HttpFoundation\Request;
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -42,16 +43,16 @@ class gatekeeper
|
|||||||
* @var gatekeeper
|
* @var gatekeeper
|
||||||
*/
|
*/
|
||||||
protected static $_instance;
|
protected static $_instance;
|
||||||
protected $Core;
|
protected $app;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @return gatekeeper
|
* @return gatekeeper
|
||||||
*/
|
*/
|
||||||
public static function getInstance(\Alchemy\Phrasea\Core $Core)
|
public static function getInstance(Application $app)
|
||||||
{
|
{
|
||||||
if ( ! (self::$_instance instanceof self))
|
if (!(self::$_instance instanceof self))
|
||||||
self::$_instance = new self($Core);
|
self::$_instance = new self($app);
|
||||||
|
|
||||||
return self::$_instance;
|
return self::$_instance;
|
||||||
}
|
}
|
||||||
@@ -60,9 +61,9 @@ class gatekeeper
|
|||||||
*
|
*
|
||||||
* @return gatekeeper
|
* @return gatekeeper
|
||||||
*/
|
*/
|
||||||
public function __construct(\Alchemy\Phrasea\Core $Core)
|
public function __construct(Application $app)
|
||||||
{
|
{
|
||||||
$this->Core = $Core;
|
$this->app = $app;
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
@@ -75,9 +76,6 @@ class gatekeeper
|
|||||||
*/
|
*/
|
||||||
public function check_directory(Request $request)
|
public function check_directory(Request $request)
|
||||||
{
|
{
|
||||||
$appbox = appbox::get_instance($this->Core);
|
|
||||||
$session = $appbox->get_session();
|
|
||||||
|
|
||||||
if (http_request::is_command_line()) {
|
if (http_request::is_command_line()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -97,17 +95,16 @@ class gatekeeper
|
|||||||
$this->_script_name = array_pop($php_script);
|
$this->_script_name = array_pop($php_script);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( ! $session->is_authenticated()) {
|
if (!$this->app->isAuthenticated()) {
|
||||||
try {
|
try {
|
||||||
$cookie = Session_Handler::get_cookie('persistent');
|
$auth = new Session_Authentication_PersistentCookie($this->app, $request->cookies->get('persistent'));
|
||||||
$auth = new Session_Authentication_PersistentCookie($appbox, $cookie);
|
$this->app->openAccount($auth, $auth->getSessionId());
|
||||||
$session->restore($auth->get_user(), $auth->get_ses_id());
|
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( ! $session->is_authenticated()) {
|
if (!$this->app->isAuthenticated()) {
|
||||||
switch ($this->_directory) {
|
switch ($this->_directory) {
|
||||||
case 'prod':
|
case 'prod':
|
||||||
case 'client':
|
case 'client':
|
||||||
@@ -143,7 +140,7 @@ class gatekeeper
|
|||||||
case '':
|
case '':
|
||||||
return;
|
return;
|
||||||
case 'setup':
|
case 'setup':
|
||||||
if ($appbox->upgradeavailable()) {
|
if ($this->app['phraseanet.appbox']->upgradeavailable()) {
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
phrasea::redirect('/login/');
|
phrasea::redirect('/login/');
|
||||||
@@ -154,7 +151,7 @@ class gatekeeper
|
|||||||
break;
|
break;
|
||||||
case 'lightbox':
|
case 'lightbox':
|
||||||
$this->token_access();
|
$this->token_access();
|
||||||
if ( ! $session->is_authenticated()) {
|
if (!$this->app->isAuthenticated()) {
|
||||||
phrasea::redirect('/login/?redirect=' . $_SERVER['REQUEST_URI']);
|
phrasea::redirect('/login/?redirect=' . $_SERVER['REQUEST_URI']);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@@ -163,23 +160,17 @@ class gatekeeper
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
$user = $this->app['phraseanet.user'];
|
||||||
$session->open_phrasea_session();
|
|
||||||
} catch (Exception $e) {
|
|
||||||
phrasea::redirect('/login/logout/?app=' . $this->_directory);
|
|
||||||
}
|
|
||||||
|
|
||||||
$user = User_Adapter::getInstance($session->get_usr_id(), $appbox);
|
|
||||||
|
|
||||||
switch ($this->_directory) {
|
switch ($this->_directory) {
|
||||||
case 'admin':
|
case 'admin':
|
||||||
case 'taskmanager':
|
case 'taskmanager':
|
||||||
if ( ! $user->ACL()->has_access_to_module('admin')) {
|
if (!$user->ACL()->has_access_to_module('admin')) {
|
||||||
phrasea::headers(403);
|
phrasea::headers(403);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'thesaurus2':
|
case 'thesaurus2':
|
||||||
if ( ! $user->ACL()->has_access_to_module('thesaurus')) {
|
if (!$user->ACL()->has_access_to_module('thesaurus')) {
|
||||||
phrasea::headers(403);
|
phrasea::headers(403);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@@ -189,12 +180,12 @@ class gatekeeper
|
|||||||
$this->token_access();
|
$this->token_access();
|
||||||
break;
|
break;
|
||||||
case 'upload':
|
case 'upload':
|
||||||
if ( ! $user->ACL()->has_right('addrecord')) {
|
if (!$user->ACL()->has_right('addrecord')) {
|
||||||
phrasea::headers(403);
|
phrasea::headers(403);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'report':
|
case 'report':
|
||||||
if ( ! $user->ACL()->has_right('report')) {
|
if (!$user->ACL()->has_right('report')) {
|
||||||
phrasea::headers(403);
|
phrasea::headers(403);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@@ -212,16 +203,14 @@ class gatekeeper
|
|||||||
*/
|
*/
|
||||||
protected function give_guest_access()
|
protected function give_guest_access()
|
||||||
{
|
{
|
||||||
$appbox = appbox::get_instance($this->Core);
|
|
||||||
$request = http_request::getInstance();
|
$request = http_request::getInstance();
|
||||||
$session = $appbox->get_session();
|
|
||||||
|
|
||||||
$parm = $request->get_parms('nolog', 'redirect');
|
$parm = $request->get_parms('nolog', 'redirect');
|
||||||
|
|
||||||
if ( ! is_null($parm['nolog']) && phrasea::guest_allowed()) {
|
if (!is_null($parm['nolog']) && phrasea::guest_allowed($this->app)) {
|
||||||
try {
|
try {
|
||||||
$auth = new Session_Authentication_Guest($appbox);
|
$auth = new Session_Authentication_Guest($this->app);
|
||||||
$session->authenticate($auth);
|
$this->app->openAccount($auth);
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
$url = '/login/?redirect=' . $parm['redirect']
|
$url = '/login/?redirect=' . $parm['redirect']
|
||||||
. '&error=' . urlencode($e->getMessage());
|
. '&error=' . urlencode($e->getMessage());
|
||||||
@@ -240,9 +229,7 @@ class gatekeeper
|
|||||||
*/
|
*/
|
||||||
protected function token_access()
|
protected function token_access()
|
||||||
{
|
{
|
||||||
$appbox = appbox::get_instance($this->Core);
|
|
||||||
$request = new http_request();
|
$request = new http_request();
|
||||||
$session = $appbox->get_session();
|
|
||||||
$parm = $request->get_parms('LOG');
|
$parm = $request->get_parms('LOG');
|
||||||
|
|
||||||
if (is_null($parm["LOG"])) {
|
if (is_null($parm["LOG"])) {
|
||||||
@@ -250,16 +237,17 @@ class gatekeeper
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if ($session->is_authenticated())
|
if ($this->app->isAuthenticated()) {
|
||||||
$session->logout();
|
$this->app->closeAccount();
|
||||||
$auth = new Session_Authentication_Token($appbox, $parm['LOG']);
|
}
|
||||||
$session->authenticate($auth);
|
$auth = new Session_Authentication_Token($this->app, $parm['LOG']);
|
||||||
|
$this->app->openAccount($auth);
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
return phrasea::redirect("/login/?error=" . urlencode($e->getMessage()));
|
return phrasea::redirect("/login/?error=" . urlencode($e->getMessage()));
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$datas = random::helloToken($parm['LOG']);
|
$datas = random::helloToken($this->app, $parm['LOG']);
|
||||||
|
|
||||||
switch ($datas['type']) {
|
switch ($datas['type']) {
|
||||||
default:
|
default:
|
||||||
@@ -288,15 +276,7 @@ class gatekeeper
|
|||||||
*/
|
*/
|
||||||
public function require_session()
|
public function require_session()
|
||||||
{
|
{
|
||||||
$appbox = appbox::get_instance($this->Core);
|
if ($this->app->isAuthenticated()) {
|
||||||
$session = $appbox->get_session();
|
|
||||||
if ($session->is_authenticated()) {
|
|
||||||
try {
|
|
||||||
$session->open_phrasea_session();
|
|
||||||
} catch (Exception $e) {
|
|
||||||
phrasea::redirect('/login/logout/');
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
phrasea::headers(403);
|
phrasea::headers(403);
|
||||||
|
Reference in New Issue
Block a user