Update authentication to service provider

This commit is contained in:
Romain Neutron
2013-02-15 19:58:17 +01:00
parent 71027acdbf
commit 76413165ff
42 changed files with 275 additions and 295 deletions

View File

@@ -74,6 +74,7 @@ use Alchemy\Phrasea\Controller\User\Notifications;
use Alchemy\Phrasea\Controller\User\Preferences; use Alchemy\Phrasea\Controller\User\Preferences;
use Alchemy\Phrasea\Core\Event\Subscriber\Logout; use Alchemy\Phrasea\Core\Event\Subscriber\Logout;
use Alchemy\Phrasea\Core\Event\Subscriber\PhraseaLocaleSubscriber; use Alchemy\Phrasea\Core\Event\Subscriber\PhraseaLocaleSubscriber;
use Alchemy\Phrasea\Core\Provider\AuthenticationManagerServiceProvider;
use Alchemy\Phrasea\Core\Provider\BrowserServiceProvider; use Alchemy\Phrasea\Core\Provider\BrowserServiceProvider;
use Alchemy\Phrasea\Core\Provider\BorderManagerServiceProvider; use Alchemy\Phrasea\Core\Provider\BorderManagerServiceProvider;
use Alchemy\Phrasea\Core\Provider\CacheServiceProvider; use Alchemy\Phrasea\Core\Provider\CacheServiceProvider;
@@ -101,6 +102,7 @@ use Monolog\Handler\NullHandler;
use MP4Box\MP4BoxServiceProvider; use MP4Box\MP4BoxServiceProvider;
use Neutron\Silex\Provider\BadFaithServiceProvider; use Neutron\Silex\Provider\BadFaithServiceProvider;
use Neutron\Silex\Provider\FilesystemServiceProvider; use Neutron\Silex\Provider\FilesystemServiceProvider;
use Neutron\ReCaptcha\ReCaptchaServiceProvider;
use PHPExiftool\PHPExiftoolServiceProvider; use PHPExiftool\PHPExiftoolServiceProvider;
use Silex\Application as SilexApplication; use Silex\Application as SilexApplication;
use Silex\Provider\MonologServiceProvider; use Silex\Provider\MonologServiceProvider;
@@ -188,6 +190,7 @@ class Application extends SilexApplication
ini_set('display_errors', 'off'); ini_set('display_errors', 'off');
} }
$this->register(new AuthenticationManagerServiceProvider());
$this->register(new BadFaithServiceProvider()); $this->register(new BadFaithServiceProvider());
$this->register(new BorderManagerServiceProvider()); $this->register(new BorderManagerServiceProvider());
$this->register(new BrowserServiceProvider()); $this->register(new BrowserServiceProvider());
@@ -227,6 +230,19 @@ class Application extends SilexApplication
$this->register(new PhraseanetServiceProvider()); $this->register(new PhraseanetServiceProvider());
$this->register(new PhraseaVersionServiceProvider()); $this->register(new PhraseaVersionServiceProvider());
$this->register(new PHPExiftoolServiceProvider()); $this->register(new PHPExiftoolServiceProvider());
$this->register(new ReCaptchaServiceProvider());
$this['recaptcha.public-key'] = $this->share(function (Application $app) {
if($app['phraseanet.registry']->get('GV_captchas')) {
return $app['phraseanet.registry']->get('GV_captcha_public_key');
}
});
$this['recaptcha.private-key'] = $this->share(function (Application $app) {
if($app['phraseanet.registry']->get('GV_captchas')) {
return $app['phraseanet.registry']->get('GV_captcha_private_key');
}
});
$this->register(new SearchEngineServiceProvider()); $this->register(new SearchEngineServiceProvider());
$this->register(new SessionServiceProvider(), array( $this->register(new SessionServiceProvider(), array(
'session.test' => $this->getEnvironment() == 'test' 'session.test' => $this->getEnvironment() == 'test'
@@ -332,8 +348,6 @@ class Application extends SilexApplication
} }
}); });
$this->reinitUser();
$this['date-formatter'] = $this->share(function(Application $app) { $this['date-formatter'] = $this->share(function(Application $app) {
return new \phraseadate($app); return new \phraseadate($app);
}); });
@@ -524,16 +538,6 @@ class Application extends SilexApplication
return $this['session']->getFlashBag()->get($type, $default); return $this['session']->getFlashBag()->get($type, $default);
} }
/**
* Tell if current a session is open
*
* @return boolean
*/
public function isAuthenticated()
{
return $this['session']->has('usr_id');
}
/** /**
* Returns an an array of available collection for offline queries * Returns an an array of available collection for offline queries
* *
@@ -544,38 +548,6 @@ class Application extends SilexApplication
return array(); return array();
} }
/**
* Open user session
*
* @param \Session_Authentication_Interface $auth
* @param integer $ses_id use previous phrasea session id
* @throws \Exception_InternalServerError
*/
public function openAccount(\Session_Authentication_Interface $auth, $ses_id = null)
{
$user = $auth->get_user();
$this['session']->clear();
$this['session']->set('usr_id', $user->get_id());
$session = new \Entities\Session();
$session->setBrowserName($this['browser']->getBrowser())
->setBrowserVersion($this['browser']->getVersion())
->setPlatform($this['browser']->getPlatform())
->setUserAgent($this['browser']->getUserAgent())
->setUsrId($user->get_id());
$this['EM']->persist($session);
$this['EM']->flush();
$this['session']->set('session_id', $session->getId());
foreach ($user->ACL()->get_granted_sbas() as $databox) {
\cache_databox::insertClient($this, $databox);
}
$this->reinitUser();
}
public function bindRoutes() public function bindRoutes()
{ {
$this->get('/', function(Application $app) { $this->get('/', function(Application $app) {
@@ -674,28 +646,6 @@ class Application extends SilexApplication
$this->mount('/xmlhttp', new ThesaurusXMLHttp()); $this->mount('/xmlhttp', new ThesaurusXMLHttp());
} }
private function reinitUser()
{
$this['phraseanet.user'] = $this->share(function(Application $app) {
if ($app->isAuthenticated()) {
return \User_Adapter::getInstance($app['session']->get('usr_id'), $app);
}
return null;
});
}
/**
* Closes user session
*/
public function closeAccount()
{
$this['session']->clear();
$this->reinitUser();
return $this;
}
/** /**
* Return available language for phraseanet * Return available language for phraseanet
* *

View File

@@ -33,13 +33,12 @@ class Lightbox implements ControllerProviderInterface
$app['authentication']->closeAccount(); $app['authentication']->closeAccount();
} }
try { if (false === $usr_id = $app['authentication.token-validator']->isValid($request->query->get('LOG'))) {
$auth = new \Session_Authentication_Token($app, $request->query->get('LOG'));
$app['authentication']->openAccount($auth);
} catch (Exception $e) {
return $app->redirect("/login/?error=" . urlencode($e->getMessage())); return $app->redirect("/login/?error=" . urlencode($e->getMessage()));
} }
$app['authentication']->openAccount(\User_Adapter::getInstance($usr_id, $app));
try { try {
$datas = $app['tokens']->helloToken($request->query->get('LOG')); $datas = $app['tokens']->helloToken($request->query->get('LOG'));
} catch (\Exception_NotFound $e) { } catch (\Exception_NotFound $e) {
@@ -468,7 +467,7 @@ class Lightbox implements ControllerProviderInterface
$agreed = false; $agreed = false;
/* @var $basket \Entities\Basket */ /* @var $basket \Entities\Basket */
foreach ($basket->getElements() as $element) { foreach ($basket->getElements() as $element) {
if (null !== $element->getUserValidationDatas($app['phraseanet.user'], $app)->getAgreement()) { if (null !== $element->getUserValidationDatas($app['authentication']->getUser(), $app)->getAgreement()) {
$agreed = true; $agreed = true;
} }
} }

View File

@@ -33,11 +33,8 @@ return call_user_func(function($environment = null) {
$app->before(function(Request $request) use ($app) { $app->before(function(Request $request) use ($app) {
if ($request->cookies->has('persistent') && !$app['authentication']->isAuthenticated()) { if ($request->cookies->has('persistent') && !$app['authentication']->isAuthenticated()) {
try { if (false !== $session = $app['authentication.persistent-manager']->getSession($request->cookies->get('persistent'))) {
$auth = new \Session_Authentication_PersistentCookie($app, $request->cookies->get('persistent')); $app['authentication']->refreshAccount($session);
$app['authentication']->openAccount($auth, $auth->getSessionId());
} catch (\Exception $e) {
} }
} }
}); });

View File

@@ -387,7 +387,7 @@ class Collection implements ControllerProviderInterface
$admins = array(); $admins = array();
if ($app['phraseanet.user']->ACL()->has_right_on_base($bas_id, 'manage')) { if ($app['authentication']->getUser()->ACL()->has_right_on_base($bas_id, 'manage')) {
$query = new \User_Query($app); $query = new \User_Query($app);
$admins = $query->on_base_ids(array($bas_id)) $admins = $query->on_base_ids(array($bas_id))
->who_have_right(array('order_master')) ->who_have_right(array('order_master'))

View File

@@ -217,8 +217,8 @@ class Dashboard implements ControllerProviderInterface
{ {
if (count($admins = $request->request->get('admins', array())) > 0) { if (count($admins = $request->request->get('admins', array())) > 0) {
if (!in_array($app['phraseanet.user']->get_id(), $admins)) { if (!in_array($app['authentication']->getUser()->get_id(), $admins)) {
$admins[] = $app['phraseanet.user']->get_id(); $admins[] = $app['authentication']->getUser()->get_id();
} }
if ($admins > 0) { if ($admins > 0) {

View File

@@ -580,7 +580,7 @@ class Databox implements ControllerProviderInterface
{ {
$app['phraseanet.appbox']->get_connection()->beginTransaction(); $app['phraseanet.appbox']->get_connection()->beginTransaction();
try { try {
$baseId = \collection::mount_collection($app, $app['phraseanet.appbox']->get_databox($databox_id), $collection_id, $app['phraseanet.user']); $baseId = \collection::mount_collection($app, $app['phraseanet.appbox']->get_databox($databox_id), $collection_id, $app['authentication']->getUser());
if (null == $othCollSel = $request->request->get("othcollsel")) { if (null == $othCollSel = $request->request->get("othcollsel")) {
$app->abort(400); $app->abort(400);
@@ -939,7 +939,7 @@ class Databox implements ControllerProviderInterface
try { try {
$databox = $app['phraseanet.appbox']->get_databox($databox_id); $databox = $app['phraseanet.appbox']->get_databox($databox_id);
$collection = \collection::create($app, $databox, $app['phraseanet.appbox'], $name, $app['phraseanet.user']); $collection = \collection::create($app, $databox, $app['phraseanet.appbox'], $name, $app['authentication']->getUser());
if (($request->request->get('ccusrothercoll') === "on") if (($request->request->get('ccusrothercoll') === "on")
&& ($othcollsel = $request->request->get('othcollsel') !== null)) { && ($othcollsel = $request->request->get('othcollsel') !== null)) {

View File

@@ -121,8 +121,8 @@ class Databoxes implements ControllerProviderInterface
$createBase = $mountBase = false; $createBase = $mountBase = false;
$sbasIds = array_merge( $sbasIds = array_merge(
array_keys($app['phraseanet.user']->ACL()->get_granted_sbas(array('bas_manage'))) array_keys($app['authentication']->getUser()->ACL()->get_granted_sbas(array('bas_manage')))
, array_keys($app['phraseanet.user']->ACL()->get_granted_sbas(array('bas_modify_struct'))) , array_keys($app['authentication']->getUser()->ACL()->get_granted_sbas(array('bas_modify_struct')))
); );
$sbas = array(); $sbas = array();
@@ -228,8 +228,8 @@ class Databoxes implements ControllerProviderInterface
try { try {
$base = \databox::create($app, $connbas, $dataTemplate, $app['phraseanet.registry']); $base = \databox::create($app, $connbas, $dataTemplate, $app['phraseanet.registry']);
$base->registerAdmin($app['phraseanet.user']); $base->registerAdmin($app['authentication']->getUser());
$app['phraseanet.user']->ACL()->delete_data_from_cache(); $app['authentication']->getUser()->ACL()->delete_data_from_cache();
return $app->redirect('/admin/databox/' . $base->get_sbas_id() . '/?success=1&reload-tree=1'); return $app->redirect('/admin/databox/' . $base->get_sbas_id() . '/?success=1&reload-tree=1');
} catch (\Exception $e) { } catch (\Exception $e) {
@@ -250,7 +250,7 @@ class Databoxes implements ControllerProviderInterface
$connbas = new \connection_pdo('databox_creation', $hostname, $port, $userDb, $passwordDb, $dbName, array(), $app['debug']); $connbas = new \connection_pdo('databox_creation', $hostname, $port, $userDb, $passwordDb, $dbName, array(), $app['debug']);
try { try {
$base = \databox::create($app, $connbas, $data_template, $app['phraseanet.registry']); $base = \databox::create($app, $connbas, $data_template, $app['phraseanet.registry']);
$base->registerAdmin($app['phraseanet.user']); $base->registerAdmin($app['authentication']->getUser());
return $app->redirect('/admin/databox/' . $base->get_sbas_id() . '/?success=1&reload-tree=1'); return $app->redirect('/admin/databox/' . $base->get_sbas_id() . '/?success=1&reload-tree=1');
} catch (\Exception $e) { } catch (\Exception $e) {
@@ -291,7 +291,7 @@ class Databoxes implements ControllerProviderInterface
$app['phraseanet.appbox']->get_connection()->beginTransaction(); $app['phraseanet.appbox']->get_connection()->beginTransaction();
$base = \databox::mount($app, $hostname, $port, $user, $password, $dbName, $app['phraseanet.registry']); $base = \databox::mount($app, $hostname, $port, $user, $password, $dbName, $app['phraseanet.registry']);
$base->registerAdmin($app['phraseanet.user']); $base->registerAdmin($app['authentication']->getUser());
$app['phraseanet.appbox']->get_connection()->commit(); $app['phraseanet.appbox']->get_connection()->commit();
return $app->redirect('/admin/databox/' . $base->get_sbas_id() . '/?success=1&reload-tree=1'); return $app->redirect('/admin/databox/' . $base->get_sbas_id() . '/?success=1&reload-tree=1');
@@ -312,7 +312,7 @@ class Databoxes implements ControllerProviderInterface
try { try {
$app['phraseanet.appbox']->get_connection()->beginTransaction(); $app['phraseanet.appbox']->get_connection()->beginTransaction();
$base = \databox::mount($app, $hostname, $port, $userDb, $passwordDb, $dbName, $app['phraseanet.registry']); $base = \databox::mount($app, $hostname, $port, $userDb, $passwordDb, $dbName, $app['phraseanet.registry']);
$base->registerAdmin($app['phraseanet.user']); $base->registerAdmin($app['authentication']->getUser());
$app['phraseanet.appbox']->get_connection()->commit(); $app['phraseanet.appbox']->get_connection()->commit();
return $app->redirect('/admin/databox/' . $base->get_sbas_id() . '/?success=1&reload-tree=1'); return $app->redirect('/admin/databox/' . $base->get_sbas_id() . '/?success=1&reload-tree=1');

View File

@@ -36,7 +36,7 @@ class Publications implements ControllerProviderInterface
$controllers->get('/list/', function(PhraseaApplication $app) { $controllers->get('/list/', function(PhraseaApplication $app) {
$feeds = \Feed_Collection::load_all( $feeds = \Feed_Collection::load_all(
$app, $app['phraseanet.user'] $app, $app['authentication']->getUser()
); );
return $app['twig'] return $app['twig']
@@ -46,7 +46,7 @@ class Publications implements ControllerProviderInterface
$controllers->post('/create/', function(PhraseaApplication $app, Request $request) { $controllers->post('/create/', function(PhraseaApplication $app, Request $request) {
$feed = \Feed_Adapter::create( $feed = \Feed_Adapter::create(
$app, $app['phraseanet.user'], $request->request->get('title'), $request->request->get('subtitle') $app, $app['authentication']->getUser(), $request->request->get('title'), $request->request->get('subtitle')
); );
if ($request->request->get('public') == '1') { if ($request->request->get('public') == '1') {
@@ -84,7 +84,7 @@ class Publications implements ControllerProviderInterface
})->before(function(Request $request) use ($app) { })->before(function(Request $request) use ($app) {
$feed = new \Feed_Adapter($app, $request->attributes->get('id')); $feed = new \Feed_Adapter($app, $request->attributes->get('id'));
if (!$feed->is_owner($app['phraseanet.user'])) { if (!$feed->is_owner($app['authentication']->getUser())) {
return $app->redirect('/admin/publications/feed/' . $request->attributes->get('id') . '/?error=' . _('You are not the owner of this feed, you can not edit it')); return $app->redirect('/admin/publications/feed/' . $request->attributes->get('id') . '/?error=' . _('You are not the owner of this feed, you can not edit it'));
} }
})->assert('id', '\d+'); })->assert('id', '\d+');
@@ -99,7 +99,7 @@ class Publications implements ControllerProviderInterface
$request = $app["request"]; $request = $app["request"];
if (!$feed->is_owner($app['phraseanet.user'])) { if (!$feed->is_owner($app['authentication']->getUser())) {
$datas['message'] = 'You are not allowed to do that'; $datas['message'] = 'You are not allowed to do that';
return $app->json($datas); return $app->json($datas);

View File

@@ -68,7 +68,7 @@ class Root implements ControllerProviderInterface
$databoxes = $off_databoxes = array(); $databoxes = $off_databoxes = array();
foreach ($app['phraseanet.appbox']->get_databoxes() as $databox) { foreach ($app['phraseanet.appbox']->get_databoxes() as $databox) {
try { try {
if (!$app['phraseanet.user']->ACL()->has_access_to_sbas($databox->get_sbas_id())) { if (!$app['authentication']->getUser()->ACL()->has_access_to_sbas($databox->get_sbas_id())) {
continue; continue;
} }
$databox->get_connection(); $databox->get_connection();
@@ -137,7 +137,7 @@ class Root implements ControllerProviderInterface
$databoxes = $off_databoxes = array(); $databoxes = $off_databoxes = array();
foreach ($app['phraseanet.appbox']->get_databoxes() as $databox) { foreach ($app['phraseanet.appbox']->get_databoxes() as $databox) {
try { try {
if (!$app['phraseanet.user']->ACL()->has_access_to_sbas($databox->get_sbas_id())) { if (!$app['authentication']->getUser()->ACL()->has_access_to_sbas($databox->get_sbas_id())) {
continue; continue;
} }
@@ -194,7 +194,7 @@ class Root implements ControllerProviderInterface
}); });
$controllers->get('/structure/{databox_id}/', function(Application $app, Request $request, $databox_id) { $controllers->get('/structure/{databox_id}/', function(Application $app, Request $request, $databox_id) {
if (!$app['phraseanet.user']->ACL()->has_right_on_sbas($databox_id, 'bas_modify_struct')) { if (!$app['authentication']->getUser()->ACL()->has_right_on_sbas($databox_id, 'bas_modify_struct')) {
$app->abort(403); $app->abort(403);
} }
@@ -221,7 +221,7 @@ class Root implements ControllerProviderInterface
->bind('database_display_stucture'); ->bind('database_display_stucture');
$controllers->post('/structure/{databox_id}/', function(Application $app, Request $request, $databox_id) { $controllers->post('/structure/{databox_id}/', function(Application $app, Request $request, $databox_id) {
if (!$app['phraseanet.user']->ACL()->has_right_on_sbas($databox_id, 'bas_modify_struct')) { if (!$app['authentication']->getUser()->ACL()->has_right_on_sbas($databox_id, 'bas_modify_struct')) {
$app->abort(403); $app->abort(403);
} }
@@ -247,7 +247,7 @@ class Root implements ControllerProviderInterface
->bind('database_submit_stucture'); ->bind('database_submit_stucture');
$controllers->get('/statusbit/{databox_id}/', function(Application $app, Request $request, $databox_id) { $controllers->get('/statusbit/{databox_id}/', function(Application $app, Request $request, $databox_id) {
if (!$app['phraseanet.user']->ACL()->has_right_on_sbas($databox_id, 'bas_modify_struct')) { if (!$app['authentication']->getUser()->ACL()->has_right_on_sbas($databox_id, 'bas_modify_struct')) {
$app->abort(403); $app->abort(403);
} }
@@ -258,7 +258,7 @@ class Root implements ControllerProviderInterface
->bind('database_display_statusbit'); ->bind('database_display_statusbit');
$controllers->get('/statusbit/{databox_id}/status/{bit}/', function(Application $app, Request $request, $databox_id, $bit) { $controllers->get('/statusbit/{databox_id}/status/{bit}/', function(Application $app, Request $request, $databox_id, $bit) {
if (!$app['phraseanet.user']->ACL()->has_right_on_sbas($databox_id, 'bas_modify_struct')) { if (!$app['authentication']->getUser()->ACL()->has_right_on_sbas($databox_id, 'bas_modify_struct')) {
$app->abort(403); $app->abort(403);
} }
@@ -297,7 +297,7 @@ class Root implements ControllerProviderInterface
$app->abort(400, _('Bad request format, only JSON is allowed')); $app->abort(400, _('Bad request format, only JSON is allowed'));
} }
if (!$app['phraseanet.user']->ACL()->has_right_on_sbas($databox_id, 'bas_modify_struct')) { if (!$app['authentication']->getUser()->ACL()->has_right_on_sbas($databox_id, 'bas_modify_struct')) {
$app->abort(403); $app->abort(403);
} }
@@ -313,7 +313,7 @@ class Root implements ControllerProviderInterface
})->assert('databox_id', '\d+')->assert('bit', '\d+'); })->assert('databox_id', '\d+')->assert('bit', '\d+');
$controllers->post('/statusbit/{databox_id}/status/{bit}/', function(Application $app, Request $request, $databox_id, $bit) { $controllers->post('/statusbit/{databox_id}/status/{bit}/', function(Application $app, Request $request, $databox_id, $bit) {
if (!$app['phraseanet.user']->ACL()->has_right_on_sbas($databox_id, 'bas_modify_struct')) { if (!$app['authentication']->getUser()->ACL()->has_right_on_sbas($databox_id, 'bas_modify_struct')) {
$app->abort(403); $app->abort(403);
} }

View File

@@ -209,7 +209,7 @@ class Users implements ControllerProviderInterface
$on_base = $request->query->get('on_base') ? : array(); $on_base = $request->query->get('on_base') ? : array();
$elligible_users = $user_query $elligible_users = $user_query
->on_sbas_where_i_am($app['phraseanet.user']->ACL(), $rights) ->on_sbas_where_i_am($app['authentication']->getUser()->ACL(), $rights)
->like(\User_Query::LIKE_EMAIL, $like_value) ->like(\User_Query::LIKE_EMAIL, $like_value)
->like(\User_Query::LIKE_FIRSTNAME, $like_value) ->like(\User_Query::LIKE_FIRSTNAME, $like_value)
->like(\User_Query::LIKE_LASTNAME, $like_value) ->like(\User_Query::LIKE_LASTNAME, $like_value)
@@ -267,7 +267,7 @@ class Users implements ControllerProviderInterface
$on_base = $request->request->get('base_id') ? : null; $on_base = $request->request->get('base_id') ? : null;
$on_sbas = $request->request->get('sbas_id') ? : null; $on_sbas = $request->request->get('sbas_id') ? : null;
$elligible_users = $user_query->on_bases_where_i_am($app['phraseanet.user']->ACL(), array('canadmin')) $elligible_users = $user_query->on_bases_where_i_am($app['authentication']->getUser()->ACL(), array('canadmin'))
->like($like_field, $like_value) ->like($like_field, $like_value)
->on_base_ids($on_base) ->on_base_ids($on_base)
->on_sbas_ids($on_sbas); ->on_sbas_ids($on_sbas);
@@ -341,12 +341,12 @@ class Users implements ControllerProviderInterface
$stmt->execute(array(':date' => date('Y-m-d', $lastMonth))); $stmt->execute(array(':date' => date('Y-m-d', $lastMonth)));
$stmt->closeCursor(); $stmt->closeCursor();
$baslist = array_keys($app['phraseanet.user']->ACL()->get_granted_base(array('canadmin'))); $baslist = array_keys($app['authentication']->getUser()->ACL()->get_granted_base(array('canadmin')));
$sql = 'SELECT usr_id, usr_login FROM usr WHERE model_of = :usr_id'; $sql = 'SELECT usr_id, usr_login FROM usr WHERE model_of = :usr_id';
$stmt = $app['phraseanet.appbox']->get_connection()->prepare($sql); $stmt = $app['phraseanet.appbox']->get_connection()->prepare($sql);
$stmt->execute(array(':usr_id' => $app['phraseanet.user']->get_id())); $stmt->execute(array(':usr_id' => $app['authentication']->getUser()->get_id()));
$models = $stmt->fetchAll(\PDO::FETCH_ASSOC); $models = $stmt->fetchAll(\PDO::FETCH_ASSOC);
$stmt->closeCursor(); $stmt->closeCursor();
@@ -681,12 +681,12 @@ class Users implements ControllerProviderInterface
INNER JOIN basusr INNER JOIN basusr
ON (basusr.usr_id=usr.usr_id) ON (basusr.usr_id=usr.usr_id)
WHERE usr.model_of = :usr_id WHERE usr.model_of = :usr_id
AND base_id in(" . implode(', ', array_keys($app['phraseanet.user']->ACL()->get_granted_base(array('manage')))) . ") AND base_id in(" . implode(', ', array_keys($app['authentication']->getUser()->ACL()->get_granted_base(array('manage')))) . ")
AND usr_login not like '(#deleted_%)' AND usr_login not like '(#deleted_%)'
GROUP BY usr_id"; GROUP BY usr_id";
$stmt = $app['phraseanet.appbox']->get_connection()->prepare($sql); $stmt = $app['phraseanet.appbox']->get_connection()->prepare($sql);
$stmt->execute(array(':usr_id' => $app['phraseanet.user']->get_id())); $stmt->execute(array(':usr_id' => $app['authentication']->getUser()->get_id()));
$models = $stmt->fetchAll(\PDO::FETCH_ASSOC); $models = $stmt->fetchAll(\PDO::FETCH_ASSOC);
$stmt->closeCursor(); $stmt->closeCursor();
@@ -814,7 +814,7 @@ class Users implements ControllerProviderInterface
} }
$NewUser->ACL()->apply_model( $NewUser->ACL()->apply_model(
\User_Adapter::getInstance($model, $app), array_keys($app['phraseanet.user']->ACL()->get_granted_base(array('manage'))) \User_Adapter::getInstance($model, $app), array_keys($app['authentication']->getUser()->ACL()->get_granted_base(array('manage')))
); );
$nbCreation++; $nbCreation++;

View File

@@ -140,7 +140,7 @@ class Baskets implements ControllerProviderInterface
{ {
try { try {
$repository = $app['EM']->getRepository('\Entities\BasketElement'); $repository = $app['EM']->getRepository('\Entities\BasketElement');
$basketElement = $repository->findUserElement($request->request->get('p0'), $app['phraseanet.user']); $basketElement = $repository->findUserElement($request->request->get('p0'), $app['authentication']->getUser());
$app['EM']->remove($basketElement); $app['EM']->remove($basketElement);
$app['EM']->flush(); $app['EM']->flush();
} catch (\Exception $e) { } catch (\Exception $e) {
@@ -164,7 +164,7 @@ class Baskets implements ControllerProviderInterface
try { try {
$repository = $app['EM']->getRepository('\Entities\Basket'); $repository = $app['EM']->getRepository('\Entities\Basket');
/* @var $repository \Repositories\BasketRepository */ /* @var $repository \Repositories\BasketRepository */
$basket = $repository->findUserBasket($app, $request->request->get('courChuId'), $app['phraseanet.user'], true); $basket = $repository->findUserBasket($app, $request->request->get('courChuId'), $app['authentication']->getUser(), true);
$app['EM']->remove($basket); $app['EM']->remove($basket);
$app['EM']->flush(); $app['EM']->flush();
@@ -190,7 +190,7 @@ class Baskets implements ControllerProviderInterface
try { try {
$basket = new Basket(); $basket = new Basket();
$basket->setName($request->request->get('p0')); $basket->setName($request->request->get('p0'));
$basket->setOwner($app['phraseanet.user']); $basket->setOwner($app['authentication']->getUser());
$app['EM']->persist($basket); $app['EM']->persist($basket);
$app['EM']->flush(); $app['EM']->flush();
@@ -215,7 +215,7 @@ class Baskets implements ControllerProviderInterface
{ {
$repository = $app['EM']->getRepository('\Entities\Basket'); $repository = $app['EM']->getRepository('\Entities\Basket');
/* @var $repository \Repositories\BasketRepository */ /* @var $repository \Repositories\BasketRepository */
$basket = $repository->findUserBasket($app, $request->request->get('courChuId'), $app['phraseanet.user'], true); $basket = $repository->findUserBasket($app, $request->request->get('courChuId'), $app['authentication']->getUser(), true);
if ($basket) { if ($basket) {
try { try {
@@ -249,7 +249,7 @@ class Baskets implements ControllerProviderInterface
public function getBaskets(Application $app, Request $request) public function getBaskets(Application $app, Request $request)
{ {
$selectedBasketId = trim($request->get('courChuId', '')); $selectedBasketId = trim($request->get('courChuId', ''));
$baskets = new ArrayCollection($app['EM']->getRepository('\Entities\Basket')->findActiveByUser($app['phraseanet.user'])); $baskets = new ArrayCollection($app['EM']->getRepository('\Entities\Basket')->findActiveByUser($app['authentication']->getUser()));
$selectedBasket = null; $selectedBasket = null;
if ('' === $selectedBasketId && $baskets->count() > 0) { if ('' === $selectedBasketId && $baskets->count() > 0) {
@@ -257,7 +257,7 @@ class Baskets implements ControllerProviderInterface
} }
if ('' !== $selectedBasketId) { if ('' !== $selectedBasketId) {
$selectedBasket = $app['EM']->getRepository('\Entities\Basket')->findUserBasket($app, $selectedBasketId, $app['phraseanet.user'], true); $selectedBasket = $app['EM']->getRepository('\Entities\Basket')->findUserBasket($app, $selectedBasketId, $app['authentication']->getUser(), true);
} }
$basketCollections = $baskets->partition(function($key, $basket) { $basketCollections = $baskets->partition(function($key, $basket) {
@@ -286,7 +286,7 @@ class Baskets implements ControllerProviderInterface
$repository = $app['EM']->getRepository('\Entities\Basket'); $repository = $app['EM']->getRepository('\Entities\Basket');
/* @var $repository \Repositories\BasketRepository */ /* @var $repository \Repositories\BasketRepository */
$baskets = $repository->findActiveByUser($app['phraseanet.user']); $baskets = $repository->findActiveByUser($app['authentication']->getUser());
foreach ($baskets as $basket) { foreach ($baskets as $basket) {
if (!$basket->getIsRead()) { if (!$basket->getIsRead()) {

View File

@@ -27,7 +27,12 @@ class Root implements ControllerProviderInterface
{ {
$controllers = $app['controllers_factory']; $controllers = $app['controllers_factory'];
$controllers->before(function() use ($app) { $controllers->before(function(Request $request) use ($app) {
if (!$app['authentication']->isAuthenticated() && null !== $request->query->get('nolog')) {
return $app->redirect(
$app->path('login_authenticate_as_guest', array('redirect' => '/prod/'))
);
}
$app['firewall']->requireAuthentication(); $app['firewall']->requireAuthentication();
}); });
@@ -186,9 +191,9 @@ class Root implements ControllerProviderInterface
$isImage = true; $isImage = true;
} }
$canDownload = $app['phraseanet.user']->ACL()->has_right_on_base($record->get_base_id(), 'candwnldpreview') || $canDownload = $app['authentication']->getUser()->ACL()->has_right_on_base($record->get_base_id(), 'candwnldpreview') ||
$app['phraseanet.user']->ACL()->has_right_on_base($record->get_base_id(), 'candwnldhd') || $app['authentication']->getUser()->ACL()->has_right_on_base($record->get_base_id(), 'candwnldhd') ||
$app['phraseanet.user']->ACL()->has_right_on_base($record->get_base_id(), 'cancmd'); $app['authentication']->getUser()->ACL()->has_right_on_base($record->get_base_id(), 'cancmd');
try { try {
$previewExists = $record->get_preview()->is_physically_present(); $previewExists = $record->get_preview()->is_physically_present();
@@ -207,7 +212,7 @@ class Root implements ControllerProviderInterface
'is_image' => $isImage, 'is_image' => $isImage,
'is_document' => $isDocument, 'is_document' => $isDocument,
'can_download' => $canDownload, 'can_download' => $canDownload,
'can_add_to_basket' => $app['phraseanet.user']->ACL()->has_right_on_base($record->get_base_id(), 'canputinalbum') 'can_add_to_basket' => $app['authentication']->getUser()->ACL()->has_right_on_base($record->get_base_id(), 'canputinalbum')
); );
} }
@@ -218,7 +223,7 @@ class Root implements ControllerProviderInterface
'per_page' => $perPage, 'per_page' => $perPage,
'search_engine' => $app['phraseanet.SE'], 'search_engine' => $app['phraseanet.SE'],
'search_engine_option' => $options->serialize(), 'search_engine_option' => $options->serialize(),
'history' => \queries::history($app['phraseanet.appbox'], $app['phraseanet.user']->get_id()), 'history' => \queries::history($app['phraseanet.appbox'], $app['authentication']->getUser()->get_id()),
'result' => $result, 'result' => $result,
'proposals' => $currentPage === 1 ? $result->getProposals() : null, 'proposals' => $currentPage === 1 ? $result->getProposals() : null,
'help' => count($resultData) === 0 ? $this->getHelpStartPage($app) : '', 'help' => count($resultData) === 0 ? $this->getHelpStartPage($app) : '',
@@ -300,7 +305,7 @@ class Root implements ControllerProviderInterface
} }
return new Response($app['twig']->render('client/index.html.twig', array( return new Response($app['twig']->render('client/index.html.twig', array(
'last_action' => !$app['phraseanet.user']->is_guest() && false !== $request->cookies->has('last_act') ? $request->cookies->has('last_act') : null, 'last_action' => !$app['authentication']->getUser()->is_guest() && false !== $request->cookies->has('last_act') ? $request->cookies->has('last_act') : null,
'phrasea_home' => $this->getDefaultClientStartPage($app), 'phrasea_home' => $this->getDefaultClientStartPage($app),
'render_topics' => $renderTopics, 'render_topics' => $renderTopics,
'grid_properties' => $this->getGridProperty(), 'grid_properties' => $this->getGridProperty(),
@@ -309,10 +314,10 @@ class Root implements ControllerProviderInterface
'tabs_setup' => $this->getTabSetup($app), 'tabs_setup' => $this->getTabSetup($app),
'menubar' => $app['twig']->render('common/menubar.html.twig', array('module' => 'client')), 'menubar' => $app['twig']->render('common/menubar.html.twig', array('module' => 'client')),
'css_file' => $this->getCssFile($app), 'css_file' => $this->getCssFile($app),
'basket_status' => null !== $app['phraseanet.user']->getPrefs('client_basket_status') ? $app['phraseanet.user']->getPrefs('client_basket_status') : "1", 'basket_status' => null !== $app['authentication']->getUser()->getPrefs('client_basket_status') ? $app['authentication']->getUser()->getPrefs('client_basket_status') : "1",
'mod_pres' => null !== $app['phraseanet.user']->getPrefs('client_view') ? $app['phraseanet.user']->getPrefs('client_view') : '', 'mod_pres' => null !== $app['authentication']->getUser()->getPrefs('client_view') ? $app['authentication']->getUser()->getPrefs('client_view') : '',
'start_page' => $app['phraseanet.user']->getPrefs('start_page'), 'start_page' => $app['authentication']->getUser()->getPrefs('start_page'),
'start_page_query' => null !== $app['phraseanet.user']->getPrefs('start_page_query') ? $app['phraseanet.user']->getPrefs('start_page_query') : '' 'start_page_query' => null !== $app['authentication']->getUser()->getPrefs('start_page_query') ? $app['authentication']->getUser()->getPrefs('start_page_query') : ''
))); )));
} }
@@ -344,13 +349,13 @@ class Root implements ControllerProviderInterface
{ {
$allDataboxes = $allCollections = array(); $allDataboxes = $allCollections = array();
foreach ($app['phraseanet.user']->ACL()->get_granted_sbas() as $databox) { foreach ($app['authentication']->getUser()->ACL()->get_granted_sbas() as $databox) {
if (count($app['phraseanet.appbox']->get_databoxes()) > 0) { if (count($app['phraseanet.appbox']->get_databoxes()) > 0) {
$allDataboxes[$databox->get_sbas_id()] = array('databox' => $databox, 'collections' => array()); $allDataboxes[$databox->get_sbas_id()] = array('databox' => $databox, 'collections' => array());
} }
if (count($databox->get_collections()) > 0) { if (count($databox->get_collections()) > 0) {
foreach ($app['phraseanet.user']->ACL()->get_granted_base(array(), array($databox->get_sbas_id())) as $coll) { foreach ($app['authentication']->getUser()->ACL()->get_granted_base(array(), array($databox->get_sbas_id())) as $coll) {
$allDataboxes[$databox->get_sbas_id()]['collections'][$coll->get_base_id()] = $coll; $allDataboxes[$databox->get_sbas_id()]['collections'][$coll->get_base_id()] = $coll;
$allCollections[$coll->get_base_id()] = $coll; $allCollections[$coll->get_base_id()] = $coll;
} }
@@ -396,7 +401,7 @@ class Root implements ControllerProviderInterface
$cssPath = __DIR__ . '/../../../../../www/skins/client/'; $cssPath = __DIR__ . '/../../../../../www/skins/client/';
$css = array(); $css = array();
$cssFile = $app['phraseanet.user']->getPrefs('client_css'); $cssFile = $app['authentication']->getUser()->getPrefs('client_css');
$finder = new Finder(); $finder = new Finder();
@@ -464,7 +469,7 @@ class Root implements ControllerProviderInterface
*/ */
private function getDefaultClientStartPage(Application $app) private function getDefaultClientStartPage(Application $app)
{ {
$startPage = strtoupper($app['phraseanet.user']->getPrefs('start_page')); $startPage = strtoupper($app['authentication']->getUser()->getPrefs('start_page'));
if ($startPage === 'PUBLI') { if ($startPage === 'PUBLI') {
return $this->getPublicationStartPage($app); return $this->getPublicationStartPage($app);
@@ -487,19 +492,19 @@ class Root implements ControllerProviderInterface
{ {
$collections = $queryParameters = array(); $collections = $queryParameters = array();
$searchSet = json_decode($app['phraseanet.user']->getPrefs('search')); $searchSet = json_decode($app['authentication']->getUser()->getPrefs('search'));
if ($searchSet && isset($searchSet->bases)) { if ($searchSet && isset($searchSet->bases)) {
foreach ($searchSet->bases as $bases) { foreach ($searchSet->bases as $bases) {
$collections = array_merge($collections, $bases); $collections = array_merge($collections, $bases);
} }
} else { } else {
$collections = array_keys($app['phraseanet.user']->ACL()->get_granted_base()); $collections = array_keys($app['authentication']->getUser()->ACL()->get_granted_base());
} }
$queryParameters["mod"] = $app['phraseanet.user']->getPrefs('client_view') ?: '3X6'; $queryParameters["mod"] = $app['authentication']->getUser()->getPrefs('client_view') ?: '3X6';
$queryParameters["bas"] = $collections; $queryParameters["bas"] = $collections;
$queryParameters["qry"] = $app['phraseanet.user']->getPrefs('start_page_query') ?: 'all'; $queryParameters["qry"] = $app['authentication']->getUser()->getPrefs('start_page_query') ?: 'all';
$queryParameters["pag"] = 0; $queryParameters["pag"] = 0;
$queryParameters["search_type"] = SearchEngineOptions::RECORD_RECORD; $queryParameters["search_type"] = SearchEngineOptions::RECORD_RECORD;
$queryParameters["qryAdv"] = ''; $queryParameters["qryAdv"] = '';
@@ -524,8 +529,8 @@ class Root implements ControllerProviderInterface
private function getPublicationStartPage(Application $app) private function getPublicationStartPage(Application $app)
{ {
return $app['twig']->render('client/home_inter_pub_basket.html.twig', array( return $app['twig']->render('client/home_inter_pub_basket.html.twig', array(
'feeds' => \Feed_Collection::load_all($app, $app['phraseanet.user']), 'feeds' => \Feed_Collection::load_all($app, $app['authentication']->getUser()),
'image_size' => (int) $app['phraseanet.user']->getPrefs('images_size') 'image_size' => (int) $app['authentication']->getUser()->getPrefs('images_size')
)); ));
} }

View File

@@ -31,7 +31,7 @@ class Datafiles extends AbstractDelivery
$that = $this; $that = $this;
$controllers->before(function(Request $request) use ($app) { $controllers->before(function(Request $request) use ($app) {
if (!$app->isAuthenticated()) { if (!$app['authentication']->isAuthenticated()) {
$app->abort(403, 'You are not autorized to see this'); $app->abort(403, 'You are not autorized to see this');
} }
}); });
@@ -62,12 +62,12 @@ class Datafiles extends AbstractDelivery
throw new NotFoundHttpException; throw new NotFoundHttpException;
} }
if (!$app['phraseanet.user']->ACL()->has_access_to_subdef($record, $subdef)) { if (!$app['authentication']->getUser()->ACL()->has_access_to_subdef($record, $subdef)) {
throw new \Exception_UnauthorizedAction(sprintf('User has not access to subdef %s', $subdef)); throw new \Exception_UnauthorizedAction(sprintf('User has not access to subdef %s', $subdef));
} }
$stamp = false; $stamp = false;
$watermark = !$app['phraseanet.user']->ACL()->has_right_on_base($record->get_base_id(), 'nowatermark'); $watermark = !$app['authentication']->getUser()->ACL()->has_right_on_base($record->get_base_id(), 'nowatermark');
if ($watermark && !$all_access) { if ($watermark && !$all_access) {
$subdef_class = $databox $subdef_class = $databox
@@ -75,9 +75,9 @@ class Datafiles extends AbstractDelivery
->get_subdef($record->get_type(), $subdef) ->get_subdef($record->get_type(), $subdef)
->get_class(); ->get_class();
if ($subdef_class == \databox_subdef::CLASS_PREVIEW && $app['phraseanet.user']->ACL()->has_preview_grant($record)) { if ($subdef_class == \databox_subdef::CLASS_PREVIEW && $app['authentication']->getUser()->ACL()->has_preview_grant($record)) {
$watermark = false; $watermark = false;
} elseif ($subdef_class == \databox_subdef::CLASS_DOCUMENT && $app['phraseanet.user']->ACL()->has_hd_grant($record)) { } elseif ($subdef_class == \databox_subdef::CLASS_DOCUMENT && $app['authentication']->getUser()->ACL()->has_hd_grant($record)) {
$watermark = false; $watermark = false;
} }
} }
@@ -88,8 +88,8 @@ class Datafiles extends AbstractDelivery
/* @var $repository \Repositories\BasketElementRepository */ /* @var $repository \Repositories\BasketElementRepository */
$ValidationByRecord = $repository->findReceivedValidationElementsByRecord($record, $app['phraseanet.user']); $ValidationByRecord = $repository->findReceivedValidationElementsByRecord($record, $app['authentication']->getUser());
$ReceptionByRecord = $repository->findReceivedElementsByRecord($record, $app['phraseanet.user']); $ReceptionByRecord = $repository->findReceivedElementsByRecord($record, $app['authentication']->getUser());
if ($ValidationByRecord && count($ValidationByRecord) > 0) { if ($ValidationByRecord && count($ValidationByRecord) > 0) {
$watermark = false; $watermark = false;

View File

@@ -61,8 +61,8 @@ class Permalink extends AbstractDelivery
$watermark = $stamp = false; $watermark = $stamp = false;
if ($app->isAuthenticated()) { if ($app['authentication']->isAuthenticated()) {
$user = \User_Adapter::getInstance($app['phraseanet.user']->get_id(), $app); $user = \User_Adapter::getInstance($app['authentication']->getUser()->get_id(), $app);
$watermark = !$user->ACL()->has_right_on_base($record->get_base_id(), 'nowatermark'); $watermark = !$user->ACL()->has_right_on_base($record->get_base_id(), 'nowatermark');

View File

@@ -131,7 +131,7 @@ class Basket implements ControllerProviderInterface
public function displayBasket(Application $app, Request $request, $basket_id) public function displayBasket(Application $app, Request $request, $basket_id)
{ {
$basket = $app['EM']->getRepository('\Entities\Basket') $basket = $app['EM']->getRepository('\Entities\Basket')
->findUserBasket($app, $basket_id, $app['phraseanet.user'], false); ->findUserBasket($app, $basket_id, $app['authentication']->getUser(), false);
if ($basket->getIsRead() === false) { if ($basket->getIsRead() === false) {
$basket->setIsRead(true); $basket->setIsRead(true);
@@ -139,8 +139,8 @@ class Basket implements ControllerProviderInterface
} }
if ($basket->getValidation()) { if ($basket->getValidation()) {
if ($basket->getValidation()->getParticipant($app['phraseanet.user'], $app)->getIsAware() === false) { if ($basket->getValidation()->getParticipant($app['authentication']->getUser(), $app)->getIsAware() === false) {
$basket->getValidation()->getParticipant($app['phraseanet.user'], $app)->setIsAware(true); $basket->getValidation()->getParticipant($app['authentication']->getUser(), $app)->setIsAware(true);
$app['EM']->flush(); $app['EM']->flush();
} }
} }
@@ -161,7 +161,7 @@ class Basket implements ControllerProviderInterface
$Basket = new BasketEntity(); $Basket = new BasketEntity();
$Basket->setName($request->request->get('name', '')); $Basket->setName($request->request->get('name', ''));
$Basket->setOwner($app['phraseanet.user']); $Basket->setOwner($app['authentication']->getUser());
$Basket->setDescription($request->request->get('desc')); $Basket->setDescription($request->request->get('desc'));
$app['EM']->persist($Basket); $app['EM']->persist($Basket);
@@ -206,7 +206,7 @@ class Basket implements ControllerProviderInterface
public function deleteBasket(Application $app, Request $request, $basket_id) public function deleteBasket(Application $app, Request $request, $basket_id)
{ {
$basket = $app['EM']->getRepository('\Entities\Basket') $basket = $app['EM']->getRepository('\Entities\Basket')
->findUserBasket($app, $basket_id, $app['phraseanet.user'], true); ->findUserBasket($app, $basket_id, $app['authentication']->getUser(), true);
$app['EM']->remove($basket); $app['EM']->remove($basket);
$app['EM']->flush(); $app['EM']->flush();
@@ -226,7 +226,7 @@ class Basket implements ControllerProviderInterface
public function removeBasketElement(Application $app, Request $request, $basket_id, $basket_element_id) public function removeBasketElement(Application $app, Request $request, $basket_id, $basket_element_id)
{ {
$basket = $app['EM']->getRepository('\Entities\Basket') $basket = $app['EM']->getRepository('\Entities\Basket')
->findUserBasket($app, $basket_id, $app['phraseanet.user'], true); ->findUserBasket($app, $basket_id, $app['authentication']->getUser(), true);
foreach ($basket->getElements() as $basket_element) { foreach ($basket->getElements() as $basket_element) {
/* @var $basket_element \Entities\BasketElement */ /* @var $basket_element \Entities\BasketElement */
@@ -255,7 +255,7 @@ class Basket implements ControllerProviderInterface
try { try {
$basket = $app['EM']->getRepository('\Entities\Basket') $basket = $app['EM']->getRepository('\Entities\Basket')
->findUserBasket($app, $basket_id, $app['phraseanet.user'], true); ->findUserBasket($app, $basket_id, $app['authentication']->getUser(), true);
$basket->setName($request->request->get('name', '')); $basket->setName($request->request->get('name', ''));
$basket->setDescription($request->request->get('description')); $basket->setDescription($request->request->get('description'));
@@ -290,7 +290,7 @@ class Basket implements ControllerProviderInterface
{ {
$basket = $app['EM'] $basket = $app['EM']
->getRepository('\Entities\Basket') ->getRepository('\Entities\Basket')
->findUserBasket($app, $basket_id, $app['phraseanet.user'], true); ->findUserBasket($app, $basket_id, $app['authentication']->getUser(), true);
return $app['twig']->render('prod/Baskets/Update.html.twig', array('basket' => $basket)); return $app['twig']->render('prod/Baskets/Update.html.twig', array('basket' => $basket));
} }
@@ -299,7 +299,7 @@ class Basket implements ControllerProviderInterface
{ {
$basket = $app['EM'] $basket = $app['EM']
->getRepository('\Entities\Basket') ->getRepository('\Entities\Basket')
->findUserBasket($app, $basket_id, $app['phraseanet.user'], true); ->findUserBasket($app, $basket_id, $app['authentication']->getUser(), true);
return $app['twig']->render('prod/Baskets/Reorder.html.twig', array('basket' => $basket)); return $app['twig']->render('prod/Baskets/Reorder.html.twig', array('basket' => $basket));
} }
@@ -309,7 +309,7 @@ class Basket implements ControllerProviderInterface
$ret = array('success' => false, 'message' => _('An error occured')); $ret = array('success' => false, 'message' => _('An error occured'));
try { try {
$basket = $app['EM']->getRepository('\Entities\Basket') $basket = $app['EM']->getRepository('\Entities\Basket')
->findUserBasket($app, $basket_id, $app['phraseanet.user'], true); ->findUserBasket($app, $basket_id, $app['authentication']->getUser(), true);
$order = $app['request']->request->get('element'); $order = $app['request']->request->get('element');
@@ -334,7 +334,7 @@ class Basket implements ControllerProviderInterface
public function archiveBasket(Application $app, Request $request, $basket_id) public function archiveBasket(Application $app, Request $request, $basket_id)
{ {
$basket = $app['EM']->getRepository('\Entities\Basket') $basket = $app['EM']->getRepository('\Entities\Basket')
->findUserBasket($app, $basket_id, $app['phraseanet.user'], true); ->findUserBasket($app, $basket_id, $app['authentication']->getUser(), true);
$archive_status = !!$request->request->get('archive'); $archive_status = !!$request->request->get('archive');
@@ -365,7 +365,7 @@ class Basket implements ControllerProviderInterface
public function addElements(Application $app, Request $request, $basket_id) public function addElements(Application $app, Request $request, $basket_id)
{ {
$basket = $app['EM']->getRepository('\Entities\Basket') $basket = $app['EM']->getRepository('\Entities\Basket')
->findUserBasket($app, $basket_id, $app['phraseanet.user'], true); ->findUserBasket($app, $basket_id, $app['authentication']->getUser(), true);
$n = 0; $n = 0;
@@ -416,14 +416,14 @@ class Basket implements ControllerProviderInterface
public function stealElements(Application $app, Request $request, $basket_id) public function stealElements(Application $app, Request $request, $basket_id)
{ {
$basket = $app['EM']->getRepository('\Entities\Basket') $basket = $app['EM']->getRepository('\Entities\Basket')
->findUserBasket($app, $basket_id, $app['phraseanet.user'], true); ->findUserBasket($app, $basket_id, $app['authentication']->getUser(), true);
$n = 0; $n = 0;
foreach ($request->request->get('elements') as $bask_element_id) { foreach ($request->request->get('elements') as $bask_element_id) {
try { try {
$basket_element = $app['EM']->getRepository('\Entities\BasketElement') $basket_element = $app['EM']->getRepository('\Entities\BasketElement')
->findUserElement($bask_element_id, $app['phraseanet.user']); ->findUserElement($bask_element_id, $app['authentication']->getUser());
} catch (\Exception $e) { } catch (\Exception $e) {
continue; continue;
} }

View File

@@ -52,7 +52,7 @@ class Bridge implements ControllerProviderInterface
$route = new RecordHelper\Bridge($app, $app['request']); $route = new RecordHelper\Bridge($app, $app['request']);
$params = array( $params = array(
'user_accounts' => \Bridge_Account::get_accounts_by_user($app, $app['phraseanet.user']) 'user_accounts' => \Bridge_Account::get_accounts_by_user($app, $app['authentication']->getUser())
, 'available_apis' => \Bridge_Api::get_availables($app) , 'available_apis' => \Bridge_Api::get_availables($app)
, 'route' => $route , 'route' => $route
, 'current_account_id' => '' , 'current_account_id' => ''
@@ -78,9 +78,9 @@ class Bridge implements ControllerProviderInterface
$user_id = $connector->get_user_id(); $user_id = $connector->get_user_id();
try { try {
$account = \Bridge_Account::load_account_from_distant_id($app, $api, $app['phraseanet.user'], $user_id); $account = \Bridge_Account::load_account_from_distant_id($app, $api, $app['authentication']->getUser(), $user_id);
} catch (\Bridge_Exception_AccountNotFound $e) { } catch (\Bridge_Exception_AccountNotFound $e) {
$account = \Bridge_Account::create($app, $api, $app['phraseanet.user'], $user_id, $connector->get_user_name()); $account = \Bridge_Account::create($app, $api, $app['authentication']->getUser(), $user_id, $connector->get_user_name());
} }
$settings = $account->get_settings(); $settings = $account->get_settings();
@@ -116,7 +116,7 @@ class Bridge implements ControllerProviderInterface
try { try {
$account = \Bridge_Account::load_account($app, $account_id); $account = \Bridge_Account::load_account($app, $account_id);
if ($account->get_user()->get_id() !== $app['phraseanet.user']->get_id()) { if ($account->get_user()->get_id() !== $app['authentication']->getUser()->get_id()) {
throw new HttpException(403, 'Access forbiden'); throw new HttpException(403, 'Access forbiden');
} }

View File

@@ -69,7 +69,7 @@ class Download implements ControllerProviderInterface
} }
$list = $download->prepare_export( $list = $download->prepare_export(
$app['phraseanet.user'], $app['authentication']->getUser(),
$app['filesystem'], $app['filesystem'],
$subdefs, $subdefs,
$request->request->get('title') === 'title' ? true : false, $request->request->get('title') === 'title' ? true : false,
@@ -80,7 +80,7 @@ class Download implements ControllerProviderInterface
$token = $app['tokens']->getUrlToken( $token = $app['tokens']->getUrlToken(
\random::TYPE_DOWNLOAD, \random::TYPE_DOWNLOAD,
$app['phraseanet.user']->get_id(), $app['authentication']->getUser()->get_id(),
new \DateTime('+3 hours'), // Token lifetime new \DateTime('+3 hours'), // Token lifetime
serialize($list) serialize($list)
); );
@@ -91,7 +91,7 @@ class Download implements ControllerProviderInterface
$app['events-manager']->trigger('__DOWNLOAD__', array( $app['events-manager']->trigger('__DOWNLOAD__', array(
'lst' => $lst, 'lst' => $lst,
'downloader' => $app['phraseanet.user']->get_id(), 'downloader' => $app['authentication']->getUser()->get_id(),
'subdefs' => $subdefs, 'subdefs' => $subdefs,
'from_basket' => $ssttid, 'from_basket' => $ssttid,
'export_file' => $download->getExportName() 'export_file' => $download->getExportName()

View File

@@ -119,7 +119,7 @@ class Edit implements ControllerProviderInterface
/** /**
* generate javascript status * generate javascript status
*/ */
if ($app['phraseanet.user']->ACL()->has_right('changestatus')) { if ($app['authentication']->getUser()->ACL()->has_right('changestatus')) {
$dbstatus = \databox_status::getDisplayStatus($app); $dbstatus = \databox_status::getDisplayStatus($app);
if (isset($dbstatus[$databox->get_sbas_id()])) { if (isset($dbstatus[$databox->get_sbas_id()])) {
foreach ($dbstatus[$databox->get_sbas_id()] as $n => $statbit) { foreach ($dbstatus[$databox->get_sbas_id()] as $n => $statbit) {
@@ -155,7 +155,7 @@ class Edit implements ControllerProviderInterface
); );
$elements[$indice]['statbits'] = array(); $elements[$indice]['statbits'] = array();
if ($app['phraseanet.user']->ACL()->has_right_on_base($record->get_base_id(), 'chgstatus')) { if ($app['authentication']->getUser()->ACL()->has_right_on_base($record->get_base_id(), 'chgstatus')) {
foreach ($status as $n => $s) { foreach ($status as $n => $s) {
$tmp_val = substr(strrev($record->get_status()), $n, 1); $tmp_val = substr(strrev($record->get_status()), $n, 1);
$elements[$indice]['statbits'][$n]['value'] = ($tmp_val == '1') ? '1' : '0'; $elements[$indice]['statbits'][$n]['value'] = ($tmp_val == '1') ? '1' : '0';
@@ -248,7 +248,7 @@ class Edit implements ControllerProviderInterface
$query = $request->query->get('query'); $query = $request->query->get('query');
$results = $VC->find($query, $app['phraseanet.user'], $databox); $results = $VC->find($query, $app['authentication']->getUser(), $databox);
$list = array(); $list = array();

View File

@@ -185,7 +185,7 @@ class Export implements ControllerProviderInterface
try { try {
$download->prepare_export( $download->prepare_export(
$app['phraseanet.user'], $app['authentication']->getUser(),
$app['filesystem'], $app['filesystem'],
$request->request->get('obj'), $request->request->get('obj'),
false, false,
@@ -236,7 +236,7 @@ class Export implements ControllerProviderInterface
//prepare export //prepare export
$download = new \set_export($app, $lst, $ssttid); $download = new \set_export($app, $lst, $ssttid);
$list = $download->prepare_export( $list = $download->prepare_export(
$app['phraseanet.user'], $app['authentication']->getUser(),
$app['filesystem'], $app['filesystem'],
(array) $request->request->get('obj'), (array) $request->request->get('obj'),
$request->request->get("type") == "title" ? : false, $request->request->get("type") == "title" ? : false,
@@ -256,7 +256,7 @@ class Export implements ControllerProviderInterface
$destMails[] = $mail; $destMails[] = $mail;
} else { } else {
$app['events-manager']->trigger('__EXPORT_MAIL_FAIL__', array( $app['events-manager']->trigger('__EXPORT_MAIL_FAIL__', array(
'usr_id' => $app['phraseanet.user']->get_id(), 'usr_id' => $app['authentication']->getUser()->get_id(),
'lst' => $lst, 'lst' => $lst,
'ssttid' => $ssttid, 'ssttid' => $ssttid,
'dest' => $mail, 'dest' => $mail,
@@ -282,7 +282,7 @@ class Export implements ControllerProviderInterface
$url = $app['phraseanet.registry']->get('GV_ServerName') . 'download/' . $token . '/prepare/?anonymous'; $url = $app['phraseanet.registry']->get('GV_ServerName') . 'download/' . $token . '/prepare/?anonymous';
$emitter = new Emitter($app['phraseanet.user']->get_display_name(), $app['phraseanet.user']->get_email()); $emitter = new Emitter($app['authentication']->getUser()->get_display_name(), $app['authentication']->getUser()->get_email());
foreach ($destMails as $key => $mail) { foreach ($destMails as $key => $mail) {
try { try {
@@ -303,7 +303,7 @@ class Export implements ControllerProviderInterface
if (count($remaingEmails) > 0) { if (count($remaingEmails) > 0) {
foreach ($remaingEmails as $mail) { foreach ($remaingEmails as $mail) {
$app['events-manager']->trigger('__EXPORT_MAIL_FAIL__', array( $app['events-manager']->trigger('__EXPORT_MAIL_FAIL__', array(
'usr_id' => $app['phraseanet.user']->get_id(), 'usr_id' => $app['authentication']->getUser()->get_id(),
'lst' => $lst, 'lst' => $lst,
'ssttid' => $ssttid, 'ssttid' => $ssttid,
'dest' => $mail, 'dest' => $mail,
@@ -314,7 +314,7 @@ class Export implements ControllerProviderInterface
} elseif (!$token && count($destMails) > 0) { //couldn't generate token } elseif (!$token && count($destMails) > 0) { //couldn't generate token
foreach ($destMails as $mail) { foreach ($destMails as $mail) {
$app['events-manager']->trigger('__EXPORT_MAIL_FAIL__', array( $app['events-manager']->trigger('__EXPORT_MAIL_FAIL__', array(
'usr_id' => $app['phraseanet.user']->get_id(), 'usr_id' => $app['authentication']->getUser()->get_id(),
'lst' => $lst, 'lst' => $lst,
'ssttid' => $ssttid, 'ssttid' => $ssttid,
'dest' => $mail, 'dest' => $mail,

View File

@@ -37,7 +37,7 @@ class Feed implements ControllerProviderInterface
* I got a selection of docs, which publications are available forthese docs ? * I got a selection of docs, which publications are available forthese docs ?
*/ */
$controllers->post('/requestavailable/', function(Application $app, Request $request) { $controllers->post('/requestavailable/', function(Application $app, Request $request) {
$feeds = \Feed_Collection::load_all($app, $app['phraseanet.user']); $feeds = \Feed_Collection::load_all($app, $app['authentication']->getUser());
$publishing = RecordsRequest::fromRequest($app, $request, true, array(), array('bas_chupub')); $publishing = RecordsRequest::fromRequest($app, $request, true, array(), array('bas_chupub'));
return $app['twig']->render('prod/actions/publish/publish.html.twig', array('publishing' => $publishing, 'feeds' => $feeds)); return $app['twig']->render('prod/actions/publish/publish.html.twig', array('publishing' => $publishing, 'feeds' => $feeds));
@@ -49,7 +49,7 @@ class Feed implements ControllerProviderInterface
$controllers->post('/entry/create/', function(Application $app, Request $request) { $controllers->post('/entry/create/', function(Application $app, Request $request) {
try { try {
$feed = new \Feed_Adapter($app, $request->request->get('feed_id')); $feed = new \Feed_Adapter($app, $request->request->get('feed_id'));
$publisher = \Feed_Publisher_Adapter::getPublisher($app['phraseanet.appbox'], $feed, $app['phraseanet.user']); $publisher = \Feed_Publisher_Adapter::getPublisher($app['phraseanet.appbox'], $feed, $app['authentication']->getUser());
$title = $request->request->get('title'); $title = $request->request->get('title');
$subtitle = $request->request->get('subtitle'); $subtitle = $request->request->get('subtitle');
@@ -76,11 +76,11 @@ class Feed implements ControllerProviderInterface
$controllers->get('/entry/{id}/edit/', function(Application $app, Request $request, $id) { $controllers->get('/entry/{id}/edit/', function(Application $app, Request $request, $id) {
$entry = \Feed_Entry_Adapter::load_from_id($app, $id); $entry = \Feed_Entry_Adapter::load_from_id($app, $id);
if (!$entry->is_publisher($app['phraseanet.user'])) { if (!$entry->is_publisher($app['authentication']->getUser())) {
throw new \Exception_UnauthorizedAction(); throw new \Exception_UnauthorizedAction();
} }
$feeds = \Feed_Collection::load_all($app, $app['phraseanet.user']); $feeds = \Feed_Collection::load_all($app, $app['authentication']->getUser());
$datas = $app['twig']->render('prod/actions/publish/publish_edit.html.twig', array('entry' => $entry, 'feeds' => $feeds)); $datas = $app['twig']->render('prod/actions/publish/publish_edit.html.twig', array('entry' => $entry, 'feeds' => $feeds));
@@ -97,7 +97,7 @@ class Feed implements ControllerProviderInterface
$entry = \Feed_Entry_Adapter::load_from_id($app, $id); $entry = \Feed_Entry_Adapter::load_from_id($app, $id);
if (!$entry->is_publisher($app['phraseanet.user'])) { if (!$entry->is_publisher($app['authentication']->getUser())) {
throw new \Exception_UnauthorizedAction(); throw new \Exception_UnauthorizedAction();
} }
@@ -115,12 +115,12 @@ class Feed implements ControllerProviderInterface
$new_feed_id = $request->request->get('feed_id', $current_feed_id); $new_feed_id = $request->request->get('feed_id', $current_feed_id);
if ($current_feed_id != $new_feed_id) { if ($current_feed_id != $new_feed_id) {
try { try {
$new_feed = \Feed_Adapter::load_with_user($app, $app['phraseanet.user'], $new_feed_id); $new_feed = \Feed_Adapter::load_with_user($app, $app['authentication']->getUser(), $new_feed_id);
} catch (\Exception_NotFound $e) { } catch (\Exception_NotFound $e) {
throw new \Exception_Forbidden('You have no access to this feed'); throw new \Exception_Forbidden('You have no access to this feed');
} }
if (!$new_feed->is_publisher($app['phraseanet.user'])) { if (!$new_feed->is_publisher($app['authentication']->getUser())) {
throw new \Exception_Forbidden('You are not publisher of this feed'); throw new \Exception_Forbidden('You are not publisher of this feed');
} }
@@ -170,8 +170,8 @@ class Feed implements ControllerProviderInterface
$entry = \Feed_Entry_Adapter::load_from_id($app, $id); $entry = \Feed_Entry_Adapter::load_from_id($app, $id);
if (!$entry->is_publisher($app['phraseanet.user']) if (!$entry->is_publisher($app['authentication']->getUser())
&& $entry->get_feed()->is_owner($app['phraseanet.user']) === false) { && $entry->get_feed()->is_owner($app['authentication']->getUser()) === false) {
throw new \Exception_UnauthorizedAction(_('Action Forbidden : You are not the publisher')); throw new \Exception_UnauthorizedAction(_('Action Forbidden : You are not the publisher'));
} }
@@ -197,7 +197,7 @@ class Feed implements ControllerProviderInterface
$page = (int) $request->query->get('page'); $page = (int) $request->query->get('page');
$page = $page > 0 ? $page : 1; $page = $page > 0 ? $page : 1;
$feeds = \Feed_Collection::load_all($app, $app['phraseanet.user']); $feeds = \Feed_Collection::load_all($app, $app['authentication']->getUser());
$datas = $app['twig']->render('prod/feeds/feeds.html.twig' $datas = $app['twig']->render('prod/feeds/feeds.html.twig'
, array( , array(
@@ -214,8 +214,8 @@ class Feed implements ControllerProviderInterface
$page = (int) $request->query->get('page'); $page = (int) $request->query->get('page');
$page = $page > 0 ? $page : 1; $page = $page > 0 ? $page : 1;
$feed = \Feed_Adapter::load_with_user($app, $app['phraseanet.user'], $id); $feed = \Feed_Adapter::load_with_user($app, $app['authentication']->getUser(), $id);
$feeds = \Feed_Collection::load_all($app, $app['phraseanet.user']); $feeds = \Feed_Collection::load_all($app, $app['authentication']->getUser());
$datas = $app['twig']->render('prod/feeds/feeds.html.twig', array('feed' => $feed, 'feeds' => $feeds, 'page' => $page)); $datas = $app['twig']->render('prod/feeds/feeds.html.twig', array('feed' => $feed, 'feeds' => $feeds, 'page' => $page));
@@ -225,12 +225,12 @@ class Feed implements ControllerProviderInterface
$controllers->get('/subscribe/aggregated/', function(Application $app, Request $request) { $controllers->get('/subscribe/aggregated/', function(Application $app, Request $request) {
$renew = ($request->query->get('renew') === 'true'); $renew = ($request->query->get('renew') === 'true');
$feeds = \Feed_Collection::load_all($app, $app['phraseanet.user']); $feeds = \Feed_Collection::load_all($app, $app['authentication']->getUser());
$output = array( $output = array(
'texte' => '<p>' . _('publication::Voici votre fil RSS personnel. Il vous permettra d\'etre tenu au courrant des publications.') 'texte' => '<p>' . _('publication::Voici votre fil RSS personnel. Il vous permettra d\'etre tenu au courrant des publications.')
. '</p><p>' . _('publications::Ne le partagez pas, il est strictement confidentiel') . '</p> . '</p><p>' . _('publications::Ne le partagez pas, il est strictement confidentiel') . '</p>
<div><input type="text" readonly="readonly" class="input_select_copy" value="' . $feeds->get_aggregate()->get_user_link($app['phraseanet.registry'], $app['phraseanet.user'], \Feed_Adapter::FORMAT_RSS, null, $renew)->get_href() . '"/></div>', <div><input type="text" readonly="readonly" class="input_select_copy" value="' . $feeds->get_aggregate()->get_user_link($app['phraseanet.registry'], $app['authentication']->getUser(), \Feed_Adapter::FORMAT_RSS, null, $renew)->get_href() . '"/></div>',
'titre' => _('publications::votre rss personnel') 'titre' => _('publications::votre rss personnel')
); );
@@ -239,12 +239,12 @@ class Feed implements ControllerProviderInterface
$controllers->get('/subscribe/{id}/', function(Application $app, Request $request, $id) { $controllers->get('/subscribe/{id}/', function(Application $app, Request $request, $id) {
$renew = ($request->query->get('renew') === 'true'); $renew = ($request->query->get('renew') === 'true');
$feed = \Feed_Adapter::load_with_user($app, $app['phraseanet.user'], $id); $feed = \Feed_Adapter::load_with_user($app, $app['authentication']->getUser(), $id);
$output = array( $output = array(
'texte' => '<p>' . _('publication::Voici votre fil RSS personnel. Il vous permettra d\'etre tenu au courrant des publications.') 'texte' => '<p>' . _('publication::Voici votre fil RSS personnel. Il vous permettra d\'etre tenu au courrant des publications.')
. '</p><p>' . _('publications::Ne le partagez pas, il est strictement confidentiel') . '</p> . '</p><p>' . _('publications::Ne le partagez pas, il est strictement confidentiel') . '</p>
<div><input type="text" style="width:100%" value="' . $feed->get_user_link($app['phraseanet.registry'], $app['phraseanet.user'], \Feed_Adapter::FORMAT_RSS, null, $renew)->get_href() . '"/></div>', <div><input type="text" style="width:100%" value="' . $feed->get_user_link($app['phraseanet.registry'], $app['authentication']->getUser(), \Feed_Adapter::FORMAT_RSS, null, $renew)->get_href() . '"/></div>',
'titre' => _('publications::votre rss personnel') 'titre' => _('publications::votre rss personnel')
); );

View File

@@ -174,7 +174,7 @@ class Lazaret implements ControllerProviderInterface
*/ */
public function listElement(Application $app, Request $request) public function listElement(Application $app, Request $request)
{ {
$baseIds = array_keys($app['phraseanet.user']->ACL()->get_granted_base(array('canaddrecord'))); $baseIds = array_keys($app['authentication']->getUser()->ACL()->get_granted_base(array('canaddrecord')));
$lazaretFiles = null; $lazaretFiles = null;

View File

@@ -48,7 +48,7 @@ class MoveCollection implements ControllerProviderInterface
return $databox->get_sbas_id(); return $databox->get_sbas_id();
}, $records->databoxes()); }, $records->databoxes());
$collections = $app['phraseanet.user']->ACL() $collections = $app['authentication']->getUser()->ACL()
->get_granted_base(array('canaddrecord'), $sbas_ids); ->get_granted_base(array('canaddrecord'), $sbas_ids);
$parameters = array( $parameters = array(
@@ -76,7 +76,7 @@ class MoveCollection implements ControllerProviderInterface
return $app->json($datas); return $app->json($datas);
} }
if (!$app['phraseanet.user']->ACL()->has_right_on_base($request->request->get('base_id'), 'canaddrecord')) { if (!$app['authentication']->getUser()->ACL()->has_right_on_base($request->request->get('base_id'), 'canaddrecord')) {
$datas['message'] = sprintf(_("You do not have the permission to move records to %s"), \phrasea::bas_names($move->getBaseIdDestination(), $app)); $datas['message'] = sprintf(_("You do not have the permission to move records to %s"), \phrasea::bas_names($move->getBaseIdDestination(), $app));
return $app->json($datas); return $app->json($datas);
@@ -95,7 +95,7 @@ class MoveCollection implements ControllerProviderInterface
if ($request->request->get("chg_coll_son") == "1") { if ($request->request->get("chg_coll_son") == "1") {
foreach ($record->get_children() as $child) { foreach ($record->get_children() as $child) {
if ($app['phraseanet.user']->ACL()->has_right_on_base($child->get_base_id(), 'candeleterecord')) { if ($app['authentication']->getUser()->ACL()->has_right_on_base($child->get_base_id(), 'candeleterecord')) {
$child->move_to_collection($collection, $app['phraseanet.appbox']); $child->move_to_collection($collection, $app['phraseanet.appbox']);
} }
} }

View File

@@ -190,7 +190,7 @@ class Order implements ControllerProviderInterface
if (count($records) > 0) { if (count($records) > 0) {
\set_order::create( \set_order::create(
$app, $records, $app['phraseanet.user'], $request->request->get('use', ''), ( (null !== $deadLine = $request->request->get('deadline')) ? new \DateTime($deadLine) : $deadLine) $app, $records, $app['authentication']->getUser(), $request->request->get('use', ''), ( (null !== $deadLine = $request->request->get('deadline')) ? new \DateTime($deadLine) : $deadLine)
); );
$success = true; $success = true;
@@ -230,7 +230,7 @@ class Order implements ControllerProviderInterface
$perPage = (int) $request->query->get('per-page', 10); $perPage = (int) $request->query->get('per-page', 10);
$sort = $request->query->get('sort'); $sort = $request->query->get('sort');
$baseIds = array_keys($app['phraseanet.user']->ACL()->get_granted_base(array('order_master'))); $baseIds = array_keys($app['authentication']->getUser()->ACL()->get_granted_base(array('order_master')));
$ordersList = \set_order::listOrders($app, $baseIds, $offsetStart, $perPage, $sort); $ordersList = \set_order::listOrders($app, $baseIds, $offsetStart, $perPage, $sort);
$total = \set_order::countTotalOrder($app['phraseanet.appbox'], $baseIds); $total = \set_order::countTotalOrder($app['phraseanet.appbox'], $baseIds);

View File

@@ -119,7 +119,7 @@ class Push implements ControllerProviderInterface
$params = array( $params = array(
'push' => $push, 'push' => $push,
'message' => '', 'message' => '',
'lists' => $repository->findUserLists($app['phraseanet.user']), 'lists' => $repository->findUserLists($app['authentication']->getUser()),
'context' => 'Push', 'context' => 'Push',
'RecommendedUsers' => $RecommendedUsers 'RecommendedUsers' => $RecommendedUsers
); );
@@ -137,7 +137,7 @@ class Push implements ControllerProviderInterface
$params = array( $params = array(
'push' => $push, 'push' => $push,
'message' => '', 'message' => '',
'lists' => $repository->findUserLists($app['phraseanet.user']), 'lists' => $repository->findUserLists($app['authentication']->getUser()),
'context' => 'Feedback', 'context' => 'Feedback',
'RecommendedUsers' => $RecommendedUsers 'RecommendedUsers' => $RecommendedUsers
); );
@@ -159,7 +159,7 @@ class Push implements ControllerProviderInterface
$push_name = $request->request->get('name'); $push_name = $request->request->get('name');
if (trim($push_name) === '') { if (trim($push_name) === '') {
$push_name = sprintf(_('Push from %s'), $app['phraseanet.user']->get_display_name()); $push_name = sprintf(_('Push from %s'), $app['authentication']->getUser()->get_display_name());
} }
$push_description = $request->request->get('push_description'); $push_description = $request->request->get('push_description');
@@ -185,7 +185,7 @@ class Push implements ControllerProviderInterface
$Basket->setName($push_name); $Basket->setName($push_name);
$Basket->setDescription($push_description); $Basket->setDescription($push_description);
$Basket->setOwner($user_receiver); $Basket->setOwner($user_receiver);
$Basket->setPusher($app['phraseanet.user']); $Basket->setPusher($app['authentication']->getUser());
$Basket->setIsRead(false); $Basket->setIsRead(false);
$app['EM']->persist($Basket); $app['EM']->persist($Basket);
@@ -202,13 +202,13 @@ class Push implements ControllerProviderInterface
if ($receiver['HD']) { if ($receiver['HD']) {
$user_receiver->ACL()->grant_hd_on( $user_receiver->ACL()->grant_hd_on(
$BasketElement->getRecord($app) $BasketElement->getRecord($app)
, $app['phraseanet.user'] , $app['authentication']->getUser()
, \ACL::GRANT_ACTION_PUSH , \ACL::GRANT_ACTION_PUSH
); );
} else { } else {
$user_receiver->ACL()->grant_preview_on( $user_receiver->ACL()->grant_preview_on(
$BasketElement->getRecord($app) $BasketElement->getRecord($app)
, $app['phraseanet.user'] , $app['authentication']->getUser()
, \ACL::GRANT_ACTION_PUSH , \ACL::GRANT_ACTION_PUSH
); );
} }
@@ -223,8 +223,8 @@ class Push implements ControllerProviderInterface
$receipt = $request->get('recept') ? $app['phraseanet.user']->get_email() : ''; $receipt = $request->get('recept') ? $app['phraseanet.user']->get_email() : '';
$params = array( $params = array(
'from' => $app['phraseanet.user']->get_id() 'from' => $app['authentication']->getUser()->get_id()
, 'from_email' => $app['phraseanet.user']->get_email() , 'from_email' => $app['authentication']->getUser()->get_email()
, 'to' => $user_receiver->get_id() , 'to' => $user_receiver->get_id()
, 'to_email' => $user_receiver->get_email() , 'to_email' => $user_receiver->get_email()
, 'to_name' => $user_receiver->get_display_name() , 'to_name' => $user_receiver->get_display_name()
@@ -277,7 +277,7 @@ class Push implements ControllerProviderInterface
$validation_name = $request->request->get('name'); $validation_name = $request->request->get('name');
if (trim($validation_name) === '') { if (trim($validation_name) === '') {
$validation_name = sprintf(_('Validation from %s'), $app['phraseanet.user']->get_display_name()); $validation_name = sprintf(_('Validation from %s'), $app['authentication']->getUser()->get_display_name());
} }
$validation_description = $request->request->get('validation_description'); $validation_description = $request->request->get('validation_description');
@@ -298,7 +298,7 @@ class Push implements ControllerProviderInterface
$Basket = new \Entities\Basket(); $Basket = new \Entities\Basket();
$Basket->setName($validation_name); $Basket->setName($validation_name);
$Basket->setDescription($validation_description); $Basket->setDescription($validation_description);
$Basket->setOwner($app['phraseanet.user']); $Basket->setOwner($app['authentication']->getUser());
$Basket->setIsRead(false); $Basket->setIsRead(false);
$app['EM']->persist($Basket); $app['EM']->persist($Basket);
@@ -319,7 +319,7 @@ class Push implements ControllerProviderInterface
if (!$Basket->getValidation()) { if (!$Basket->getValidation()) {
$Validation = new \Entities\ValidationSession(); $Validation = new \Entities\ValidationSession();
$Validation->setInitiator($app['phraseanet.user']); $Validation->setInitiator($app['authentication']->getUser());
$Validation->setBasket($Basket); $Validation->setBasket($Basket);
$duration = (int) $request->request->get('duration'); $duration = (int) $request->request->get('duration');
@@ -337,16 +337,16 @@ class Push implements ControllerProviderInterface
$found = false; $found = false;
foreach ($participants as $key => $participant) { foreach ($participants as $key => $participant) {
if ($participant['usr_id'] == $app['phraseanet.user']->get_id()) { if ($participant['usr_id'] == $app['authentication']->getUser()->get_id()) {
$found = true; $found = true;
break; break;
} }
} }
if (!$found) { if (!$found) {
$participants[$app['phraseanet.user']->get_id()] = array( $participants[$app['authentication']->getUser()->get_id()] = array(
'see_others' => 1, 'see_others' => 1,
'usr_id' => $app['phraseanet.user']->get_id(), 'usr_id' => $app['authentication']->getUser()->get_id(),
'agree' => 0, 'agree' => 0,
'HD' => 0 'HD' => 0
); );
@@ -389,13 +389,13 @@ class Push implements ControllerProviderInterface
if ($participant['HD']) { if ($participant['HD']) {
$participant_user->ACL()->grant_hd_on( $participant_user->ACL()->grant_hd_on(
$BasketElement->getRecord($app) $BasketElement->getRecord($app)
, $app['phraseanet.user'] , $app['authentication']->getUser()
, \ACL::GRANT_ACTION_VALIDATE , \ACL::GRANT_ACTION_VALIDATE
); );
} else { } else {
$participant_user->ACL()->grant_preview_on( $participant_user->ACL()->grant_preview_on(
$BasketElement->getRecord($app) $BasketElement->getRecord($app)
, $app['phraseanet.user'] , $app['authentication']->getUser()
, \ACL::GRANT_ACTION_VALIDATE , \ACL::GRANT_ACTION_VALIDATE
); );
} }
@@ -420,8 +420,8 @@ class Push implements ControllerProviderInterface
$receipt = $request->get('recept') ? $app['phraseanet.user']->get_email() : ''; $receipt = $request->get('recept') ? $app['phraseanet.user']->get_email() : '';
$params = array( $params = array(
'from' => $app['phraseanet.user']->get_id() 'from' => $app['authentication']->getUser()->get_id()
, 'from_email' => $app['phraseanet.user']->get_email() , 'from_email' => $app['authentication']->getUser()->get_email()
, 'to' => $participant_user->get_id() , 'to' => $participant_user->get_id()
, 'to_email' => $participant_user->get_email() , 'to_email' => $participant_user->get_email()
, 'to_name' => $participant_user->get_display_name() , 'to_name' => $participant_user->get_display_name()
@@ -466,7 +466,7 @@ class Push implements ControllerProviderInterface
$query = new \User_Query($app); $query = new \User_Query($app);
$query->on_bases_where_i_am($app['phraseanet.user']->ACL(), array('canpush')); $query->on_bases_where_i_am($app['authentication']->getUser()->ACL(), array('canpush'));
$query->in(array($usr_id)); $query->in(array($usr_id));
@@ -488,7 +488,7 @@ class Push implements ControllerProviderInterface
$repository = $app['EM']->getRepository('\Entities\UsrList'); $repository = $app['EM']->getRepository('\Entities\UsrList');
$list = $repository->findUserListByUserAndId($app, $app['phraseanet.user'], $list_id); $list = $repository->findUserListByUserAndId($app, $app['authentication']->getUser(), $list_id);
if ($list) { if ($list) {
$datas = $listFormatter($list); $datas = $listFormatter($list);
@@ -501,7 +501,7 @@ class Push implements ControllerProviderInterface
$result = array('success' => false, 'message' => '', 'user' => null); $result = array('success' => false, 'message' => '', 'user' => null);
try { try {
if (!$app['phraseanet.user']->ACL()->has_right('manageusers')) if (!$app['authentication']->getUser()->ACL()->has_right('manageusers'))
throw new ControllerException(_('You are not allowed to add users')); throw new ControllerException(_('You are not allowed to add users'));
if (!$request->request->get('firstname')) if (!$request->request->get('firstname'))
@@ -573,7 +573,7 @@ class Push implements ControllerProviderInterface
$query = new \User_Query($app); $query = new \User_Query($app);
$query->on_bases_where_i_am($app['phraseanet.user']->ACL(), array('canpush')); $query->on_bases_where_i_am($app['authentication']->getUser()->ACL(), array('canpush'));
$query->like(\User_Query::LIKE_FIRSTNAME, $request->query->get('query')) $query->like(\User_Query::LIKE_FIRSTNAME, $request->query->get('query'))
->like(\User_Query::LIKE_LASTNAME, $request->query->get('query')) ->like(\User_Query::LIKE_LASTNAME, $request->query->get('query'))
@@ -586,7 +586,7 @@ class Push implements ControllerProviderInterface
$repository = $app['EM']->getRepository('\Entities\UsrList'); $repository = $app['EM']->getRepository('\Entities\UsrList');
$lists = $repository->findUserListLike($app['phraseanet.user'], $request->query->get('query')); $lists = $repository->findUserListLike($app['authentication']->getUser(), $request->query->get('query'));
$datas = array(); $datas = array();
@@ -609,11 +609,11 @@ class Push implements ControllerProviderInterface
$repository = $app['EM']->getRepository('\Entities\UsrList'); $repository = $app['EM']->getRepository('\Entities\UsrList');
$list = $repository->findUserListByUserAndId($app, $app['phraseanet.user'], $list_id); $list = $repository->findUserListByUserAndId($app, $app['authentication']->getUser(), $list_id);
$query = new \User_Query($app); $query = new \User_Query($app);
$query->on_bases_where_i_am($app['phraseanet.user']->ACL(), array('canpush')); $query->on_bases_where_i_am($app['authentication']->getUser()->ACL(), array('canpush'));
if ($request->get('query')) { if ($request->get('query')) {
$query->like($request->get('like_field'), $request->get('query')) $query->like($request->get('like_field'), $request->get('query'))

View File

@@ -96,7 +96,7 @@ class Query implements ControllerProviderInterface
{ {
$query = (string) $request->request->get('qry'); $query = (string) $request->request->get('qry');
$mod = $app['phraseanet.user']->getPrefs('view'); $mod = $app['authentication']->getUser()->getPrefs('view');
$json = array(); $json = array();
@@ -104,7 +104,7 @@ class Query implements ControllerProviderInterface
$form = $options->serialize(); $form = $options->serialize();
$perPage = (int) $app['phraseanet.user']->getPrefs('images_per_page'); $perPage = (int) $app['authentication']->getUser()->getPrefs('images_per_page');
$app['phraseanet.SE']->setOptions($options); $app['phraseanet.SE']->setOptions($options);

View File

@@ -174,7 +174,7 @@ class Records implements ControllerProviderInterface
)), )),
"others" => $app['twig']->render('prod/preview/appears_in.html.twig', array( "others" => $app['twig']->render('prod/preview/appears_in.html.twig', array(
'parents' => $record->get_grouping_parents(), 'parents' => $record->get_grouping_parents(),
'baskets' => $record->get_container_baskets($app['EM'], $app['phraseanet.user']) 'baskets' => $record->get_container_baskets($app['EM'], $app['authentication']->getUser())
)), )),
"current" => $train, "current" => $train,
"history" => $app['twig']->render('prod/preview/short_history.html.twig', array( "history" => $app['twig']->render('prod/preview/short_history.html.twig', array(

View File

@@ -33,11 +33,10 @@ class Root implements ControllerProviderInterface
$controllers->before(function(Request $request) use ($app) { $controllers->before(function(Request $request) use ($app) {
if (!$app->isAuthenticated() && null !== $request->query->get('nolog') && \phrasea::guest_allowed($app)) { if (!$app['authentication']->isAuthenticated() && null !== $request->query->get('nolog')) {
$auth = new Session_Authentication_Guest($app); return $app->redirect(
$app->openAccount($auth); $app->path('login_authenticate_as_guest', array('redirect' => '/prod/'))
);
return $app->redirect('/prod/');
} }
$app['firewall']->requireAuthentication(); $app['firewall']->requireAuthentication();
@@ -70,13 +69,13 @@ class Root implements ControllerProviderInterface
$css[$baseName] = $baseName; $css[$baseName] = $baseName;
} }
$cssfile = $app['phraseanet.user']->getPrefs('css'); $cssfile = $app['authentication']->getUser()->getPrefs('css');
if (!$cssfile && isset($css['000000'])) { if (!$cssfile && isset($css['000000'])) {
$cssfile = '000000'; $cssfile = '000000';
} }
$user_feeds = \Feed_Collection::load_all($app, $app['phraseanet.user']); $user_feeds = \Feed_Collection::load_all($app, $app['authentication']->getUser());
$feeds = array_merge(array($user_feeds->get_aggregate()), $user_feeds->get_feeds()); $feeds = array_merge(array($user_feeds->get_aggregate()), $user_feeds->get_feeds());
$thjslist = ""; $thjslist = "";
@@ -123,7 +122,7 @@ class Root implements ControllerProviderInterface
'GV_google_api' => $app['phraseanet.registry']->get('GV_google_api'), 'GV_google_api' => $app['phraseanet.registry']->get('GV_google_api'),
'queries_topics' => $queries_topics, 'queries_topics' => $queries_topics,
'search_status' => \databox_status::getSearchStatus($app), 'search_status' => \databox_status::getSearchStatus($app),
'queries_history' => \queries::history($app['phraseanet.appbox'], $app['phraseanet.user']->get_id()), 'queries_history' => \queries::history($app['phraseanet.appbox'], $app['authentication']->getUser()->get_id()),
'thesau_js_list' => $thjslist, 'thesau_js_list' => $thjslist,
'thesau_json_sbas' => json_encode($sbas), 'thesau_json_sbas' => json_encode($sbas),
'thesau_json_bas2sbas' => json_encode($bas2sbas), 'thesau_json_bas2sbas' => json_encode($bas2sbas),

View File

@@ -65,7 +65,7 @@ class Share implements ControllerProviderInterface
{ {
$record = new \record_adapter($app, \phrasea::sbasFromBas($app, $base_id), $record_id); $record = new \record_adapter($app, \phrasea::sbasFromBas($app, $base_id), $record_id);
if (!$app['phraseanet.user']->ACL()->has_access_to_subdef($record, 'preview')) { if (!$app['authentication']->getUser()->ACL()->has_access_to_subdef($record, 'preview')) {
$app->abort(403); $app->abort(403);
} }

View File

@@ -42,7 +42,7 @@ class Story implements ControllerProviderInterface
/* @var $request \Symfony\Component\HttpFoundation\Request */ /* @var $request \Symfony\Component\HttpFoundation\Request */
$collection = \collection::get_from_base_id($app, $request->request->get('base_id')); $collection = \collection::get_from_base_id($app, $request->request->get('base_id'));
if (!$app['phraseanet.user']->ACL()->has_right_on_base($collection->get_base_id(), 'canaddrecord')) { if (!$app['authentication']->getUser()->ACL()->has_right_on_base($collection->get_base_id(), 'canaddrecord')) {
throw new \Exception_Forbidden('You can not create a story on this collection'); throw new \Exception_Forbidden('You can not create a story on this collection');
} }
@@ -79,7 +79,7 @@ class Story implements ControllerProviderInterface
$Story->set_metadatas($metadatas)->rebuild_subdefs(); $Story->set_metadatas($metadatas)->rebuild_subdefs();
$StoryWZ = new \Entities\StoryWZ(); $StoryWZ = new \Entities\StoryWZ();
$StoryWZ->setUser($app['phraseanet.user']); $StoryWZ->setUser($app['authentication']->getUser());
$StoryWZ->setRecord($Story); $StoryWZ->setRecord($Story);
$app['EM']->persist($StoryWZ); $app['EM']->persist($StoryWZ);
@@ -114,7 +114,7 @@ class Story implements ControllerProviderInterface
$controllers->post('/{sbas_id}/{record_id}/addElements/', function(Application $app, Request $request, $sbas_id, $record_id) { $controllers->post('/{sbas_id}/{record_id}/addElements/', function(Application $app, Request $request, $sbas_id, $record_id) {
$Story = new \record_adapter($app, $sbas_id, $record_id); $Story = new \record_adapter($app, $sbas_id, $record_id);
if (!$app['phraseanet.user']->ACL()->has_right_on_base($Story->get_base_id(), 'canmodifrecord')) if (!$app['authentication']->getUser()->ACL()->has_right_on_base($Story->get_base_id(), 'canmodifrecord'))
throw new \Exception_Forbidden('You can not add document to this Story'); throw new \Exception_Forbidden('You can not add document to this Story');
$n = 0; $n = 0;
@@ -147,7 +147,7 @@ class Story implements ControllerProviderInterface
$record = new \record_adapter($app, $child_sbas_id, $child_record_id); $record = new \record_adapter($app, $child_sbas_id, $child_record_id);
if (!$app['phraseanet.user']->ACL()->has_right_on_base($Story->get_base_id(), 'canmodifrecord')) if (!$app['authentication']->getUser()->ACL()->has_right_on_base($Story->get_base_id(), 'canmodifrecord'))
throw new \Exception_Forbidden('You can not add document to this Story'); throw new \Exception_Forbidden('You can not add document to this Story');
$Story->removeChild($record); $Story->removeChild($record);
@@ -198,7 +198,7 @@ class Story implements ControllerProviderInterface
throw new \Exception('This is not a story'); throw new \Exception('This is not a story');
} }
if (!$app['phraseanet.user']->ACL()->has_right_on_base($story->get_base_id(), 'canmodifrecord')) { if (!$app['authentication']->getUser()->ACL()->has_right_on_base($story->get_base_id(), 'canmodifrecord')) {
throw new ControllerException(_('You can not edit this story')); throw new ControllerException(_('You can not edit this story'));
} }

View File

@@ -82,12 +82,12 @@ class TOU implements ControllerProviderInterface
try { try {
$databox = $app['phraseanet.appbox']->get_databox((int) $sbas_id); $databox = $app['phraseanet.appbox']->get_databox((int) $sbas_id);
$app['phraseanet.user']->ACL()->revoke_access_from_bases( $app['authentication']->getUser()->ACL()->revoke_access_from_bases(
array_keys($app['phraseanet.user']->ACL()->get_granted_base(array(), array($databox->get_sbas_id()))) array_keys($app['authentication']->getUser()->ACL()->get_granted_base(array(), array($databox->get_sbas_id())))
); );
$app['phraseanet.user']->ACL()->revoke_unused_sbas_rights(); $app['authentication']->getUser()->ACL()->revoke_unused_sbas_rights();
$app->closeAccount(); $app['authentication']->closeAccount();
$ret['success'] = true; $ret['success'] = true;
} catch (\Exception $e) { } catch (\Exception $e) {

View File

@@ -72,7 +72,7 @@ class Tooltip implements ControllerProviderInterface
public function displayBasket(Application $app, $basket_id) public function displayBasket(Application $app, $basket_id)
{ {
$basket = $app['EM']->getRepository('\Entities\Basket') $basket = $app['EM']->getRepository('\Entities\Basket')
->findUserBasket($app, $basket_id, $app['phraseanet.user'], false); ->findUserBasket($app, $basket_id, $app['authentication']->getUser(), false);
return $app['twig']->render('prod/Tooltip/Basket.html.twig', array('basket' => $basket)); return $app['twig']->render('prod/Tooltip/Basket.html.twig', array('basket' => $basket));
} }

View File

@@ -113,7 +113,7 @@ class Upload implements ControllerProviderInterface
return $app['twig']->render( return $app['twig']->render(
'prod/upload/upload-flash.html.twig', array( 'prod/upload/upload-flash.html.twig', array(
'sessionId' => session_id(), 'sessionId' => session_id(),
'collections' => $this->getGrantedCollections($app['phraseanet.user']), 'collections' => $this->getGrantedCollections($app['authentication']->getUser()),
'maxFileSize' => $maxFileSize, 'maxFileSize' => $maxFileSize,
'maxFileSizeReadable' => \p4string::format_octets($maxFileSize) 'maxFileSizeReadable' => \p4string::format_octets($maxFileSize)
)); ));
@@ -133,7 +133,7 @@ class Upload implements ControllerProviderInterface
return $app['twig']->render( return $app['twig']->render(
'prod/upload/upload.html.twig', array( 'prod/upload/upload.html.twig', array(
'collections' => $this->getGrantedCollections($app['phraseanet.user']), 'collections' => $this->getGrantedCollections($app['authentication']->getUser()),
'maxFileSize' => $maxFileSize, 'maxFileSize' => $maxFileSize,
'maxFileSizeReadable' => \p4string::format_octets($maxFileSize) 'maxFileSizeReadable' => \p4string::format_octets($maxFileSize)
)); ));
@@ -172,7 +172,7 @@ class Upload implements ControllerProviderInterface
throw new \Exception_BadRequest('Missing base_id parameter'); throw new \Exception_BadRequest('Missing base_id parameter');
} }
if (!$app['phraseanet.user']->ACL()->has_right_on_base($base_id, 'canaddrecord')) { if (!$app['authentication']->getUser()->ACL()->has_right_on_base($base_id, 'canaddrecord')) {
throw new \Exception_Forbidden('User is not allowed to add record on this collection'); throw new \Exception_Forbidden('User is not allowed to add record on this collection');
} }
@@ -193,7 +193,7 @@ class Upload implements ControllerProviderInterface
$collection = \collection::get_from_base_id($app, $base_id); $collection = \collection::get_from_base_id($app, $base_id);
$lazaretSession = new LazaretSession(); $lazaretSession = new LazaretSession();
$lazaretSession->setUsrId($app['phraseanet.user']->get_id()); $lazaretSession->setUsrId($app['authentication']->getUser()->get_id());
$app['EM']->persist($lazaretSession); $app['EM']->persist($lazaretSession);

View File

@@ -109,7 +109,7 @@ class UsrLists implements ControllerProviderInterface
try { try {
$repository = $app['EM']->getRepository('\Entities\UsrList'); $repository = $app['EM']->getRepository('\Entities\UsrList');
$lists = $repository->findUserLists($app['phraseanet.user']); $lists = $repository->findUserLists($app['authentication']->getUser());
$result = array(); $result = array();
@@ -191,7 +191,7 @@ class UsrLists implements ControllerProviderInterface
$Owner = new UsrListOwner(); $Owner = new UsrListOwner();
$Owner->setRole(UsrListOwner::ROLE_ADMIN); $Owner->setRole(UsrListOwner::ROLE_ADMIN);
$Owner->setUser($app['phraseanet.user']); $Owner->setUser($app['authentication']->getUser());
$Owner->setList($List); $Owner->setList($List);
$List->setName($list_name); $List->setName($list_name);
@@ -222,7 +222,7 @@ class UsrLists implements ControllerProviderInterface
{ {
$repository = $app['EM']->getRepository('\Entities\UsrList'); $repository = $app['EM']->getRepository('\Entities\UsrList');
$list = $repository->findUserListByUserAndId($app, $app['phraseanet.user'], $list_id); $list = $repository->findUserListByUserAndId($app, $app['authentication']->getUser(), $list_id);
$entries = new ArrayCollection(); $entries = new ArrayCollection();
$owners = new ArrayCollection(); $owners = new ArrayCollection();
@@ -280,9 +280,9 @@ class UsrLists implements ControllerProviderInterface
$repository = $app['EM']->getRepository('\Entities\UsrList'); $repository = $app['EM']->getRepository('\Entities\UsrList');
$list = $repository->findUserListByUserAndId($app, $app['phraseanet.user'], $list_id); $list = $repository->findUserListByUserAndId($app, $app['authentication']->getUser(), $list_id);
if ($list->getOwner($app['phraseanet.user'], $app)->getRole() < UsrListOwner::ROLE_EDITOR) { if ($list->getOwner($app['authentication']->getUser(), $app)->getRole() < UsrListOwner::ROLE_EDITOR) {
throw new ControllerException(_('You are not authorized to do this')); throw new ControllerException(_('You are not authorized to do this'));
} }
@@ -311,9 +311,9 @@ class UsrLists implements ControllerProviderInterface
try { try {
$repository = $app['EM']->getRepository('\Entities\UsrList'); $repository = $app['EM']->getRepository('\Entities\UsrList');
$list = $repository->findUserListByUserAndId($app, $app['phraseanet.user'], $list_id); $list = $repository->findUserListByUserAndId($app, $app['authentication']->getUser(), $list_id);
if ($list->getOwner($app['phraseanet.user'], $app)->getRole() < UsrListOwner::ROLE_ADMIN) { if ($list->getOwner($app['authentication']->getUser(), $app)->getRole() < UsrListOwner::ROLE_ADMIN) {
throw new ControllerException(_('You are not authorized to do this')); throw new ControllerException(_('You are not authorized to do this'));
} }
@@ -345,10 +345,10 @@ class UsrLists implements ControllerProviderInterface
try { try {
$repository = $app['EM']->getRepository('\Entities\UsrList'); $repository = $app['EM']->getRepository('\Entities\UsrList');
$list = $repository->findUserListByUserAndId($app, $app['phraseanet.user'], $list_id); $list = $repository->findUserListByUserAndId($app, $app['authentication']->getUser(), $list_id);
/* @var $list \Entities\UsrList */ /* @var $list \Entities\UsrList */
if ($list->getOwner($app['phraseanet.user'], $app)->getRole() < UsrListOwner::ROLE_EDITOR) { if ($list->getOwner($app['authentication']->getUser(), $app)->getRole() < UsrListOwner::ROLE_EDITOR) {
throw new ControllerException(_('You are not authorized to do this')); throw new ControllerException(_('You are not authorized to do this'));
} }
@@ -388,10 +388,10 @@ class UsrLists implements ControllerProviderInterface
$repository = $app['EM']->getRepository('\Entities\UsrList'); $repository = $app['EM']->getRepository('\Entities\UsrList');
$list = $repository->findUserListByUserAndId($app, $app['phraseanet.user'], $list_id); $list = $repository->findUserListByUserAndId($app, $app['authentication']->getUser(), $list_id);
/* @var $list \Entities\UsrList */ /* @var $list \Entities\UsrList */
if ($list->getOwner($app['phraseanet.user'], $app)->getRole() < UsrListOwner::ROLE_EDITOR) { if ($list->getOwner($app['authentication']->getUser(), $app)->getRole() < UsrListOwner::ROLE_EDITOR) {
throw new ControllerException(_('You are not authorized to do this')); throw new ControllerException(_('You are not authorized to do this'));
} }
@@ -452,10 +452,10 @@ class UsrLists implements ControllerProviderInterface
try { try {
$repository = $app['EM']->getRepository('\Entities\UsrList'); $repository = $app['EM']->getRepository('\Entities\UsrList');
$list = $repository->findUserListByUserAndId($app, $app['phraseanet.user'], $list_id); $list = $repository->findUserListByUserAndId($app, $app['authentication']->getUser(), $list_id);
/* @var $list \Entities\UsrList */ /* @var $list \Entities\UsrList */
if ($list->getOwner($app['phraseanet.user'], $app)->getRole() < UsrListOwner::ROLE_ADMIN) { if ($list->getOwner($app['authentication']->getUser(), $app)->getRole() < UsrListOwner::ROLE_ADMIN) {
$list = null; $list = null;
throw new \Exception(_('You are not authorized to do this')); throw new \Exception(_('You are not authorized to do this'));
} }
@@ -482,17 +482,17 @@ class UsrLists implements ControllerProviderInterface
try { try {
$repository = $app['EM']->getRepository('\Entities\UsrList'); $repository = $app['EM']->getRepository('\Entities\UsrList');
$list = $repository->findUserListByUserAndId($app, $app['phraseanet.user'], $list_id); $list = $repository->findUserListByUserAndId($app, $app['authentication']->getUser(), $list_id);
/* @var $list \Entities\UsrList */ /* @var $list \Entities\UsrList */
if ($list->getOwner($app['phraseanet.user'], $app)->getRole() < UsrListOwner::ROLE_EDITOR) { if ($list->getOwner($app['authentication']->getUser(), $app)->getRole() < UsrListOwner::ROLE_EDITOR) {
throw new ControllerException(_('You are not authorized to do this')); throw new ControllerException(_('You are not authorized to do this'));
} }
$new_owner = \User_Adapter::getInstance($usr_id, $app); $new_owner = \User_Adapter::getInstance($usr_id, $app);
if ($list->hasAccess($new_owner, $app)) { if ($list->hasAccess($new_owner, $app)) {
if ($new_owner->get_id() == $app['phraseanet.user']->get_id()) { if ($new_owner->get_id() == $app['authentication']->getUser()->get_id()) {
throw new ControllerException('You can not downgrade your Admin right'); throw new ControllerException('You can not downgrade your Admin right');
} }
@@ -538,10 +538,10 @@ class UsrLists implements ControllerProviderInterface
try { try {
$repository = $app['EM']->getRepository('\Entities\UsrList'); $repository = $app['EM']->getRepository('\Entities\UsrList');
$list = $repository->findUserListByUserAndId($app, $app['phraseanet.user'], $list_id); $list = $repository->findUserListByUserAndId($app, $app['authentication']->getUser(), $list_id);
/* @var $list \Entities\UsrList */ /* @var $list \Entities\UsrList */
if ($list->getOwner($app['phraseanet.user'], $app)->getRole() < UsrListOwner::ROLE_ADMIN) { if ($list->getOwner($app['authentication']->getUser(), $app)->getRole() < UsrListOwner::ROLE_ADMIN) {
throw new \Exception(_('You are not authorized to do this')); throw new \Exception(_('You are not authorized to do this'));
} }

View File

@@ -80,7 +80,7 @@ class WorkZone implements ControllerProviderInterface
$offsetStart = max(($Page - 1) * $PerPage, 0); $offsetStart = max(($Page - 1) * $PerPage, 0);
$Baskets = $BasketRepo->findWorkzoneBasket( $Baskets = $BasketRepo->findWorkzoneBasket(
$app['phraseanet.user'] $app['authentication']->getUser()
, $request->query->get('Query') , $request->query->get('Query')
, $request->query->get('Year') , $request->query->get('Year')
, $request->query->get('Type') , $request->query->get('Type')
@@ -108,7 +108,7 @@ class WorkZone implements ControllerProviderInterface
{ {
$basket = $app['EM'] $basket = $app['EM']
->getRepository('\Entities\Basket') ->getRepository('\Entities\Basket')
->findUserBasket($app, $basket_id, $app['phraseanet.user'], false); ->findUserBasket($app, $basket_id, $app['authentication']->getUser(), false);
return $app['twig']->render('prod/WorkZone/Browser/Basket.html.twig', array('Basket' => $basket)); return $app['twig']->render('prod/WorkZone/Browser/Basket.html.twig', array('Basket' => $basket));
} }
@@ -133,17 +133,17 @@ class WorkZone implements ControllerProviderInterface
throw new \Exception('You can only attach stories'); throw new \Exception('You can only attach stories');
} }
if (!$app['phraseanet.user']->ACL()->has_access_to_base($Story->get_base_id())) { if (!$app['authentication']->getUser()->ACL()->has_access_to_base($Story->get_base_id())) {
throw new \Exception_Forbidden('You do not have access to this Story'); throw new \Exception_Forbidden('You do not have access to this Story');
} }
if ($StoryWZRepo->findUserStory($app, $app['phraseanet.user'], $Story)) { if ($StoryWZRepo->findUserStory($app, $app['authentication']->getUser(), $Story)) {
$alreadyFixed++; $alreadyFixed++;
continue; continue;
} }
$StoryWZ = new StoryWZ(); $StoryWZ = new StoryWZ();
$StoryWZ->setUser($app['phraseanet.user']); $StoryWZ->setUser($app['authentication']->getUser());
$StoryWZ->setRecord($Story); $StoryWZ->setRecord($Story);
$app['EM']->persist($StoryWZ); $app['EM']->persist($StoryWZ);
@@ -197,7 +197,7 @@ class WorkZone implements ControllerProviderInterface
$repository = $app['EM']->getRepository('\Entities\StoryWZ'); $repository = $app['EM']->getRepository('\Entities\StoryWZ');
/* @var $repository \Repositories\StoryWZRepository */ /* @var $repository \Repositories\StoryWZRepository */
$StoryWZ = $repository->findUserStory($app, $app['phraseanet.user'], $Story); $StoryWZ = $repository->findUserStory($app, $app['authentication']->getUser(), $Story);
if (!$StoryWZ) { if (!$StoryWZ) {
throw new \Exception_NotFound('Story not found'); throw new \Exception_NotFound('Story not found');

View File

@@ -199,7 +199,7 @@ class RecordsRequest extends ArrayCollection
if ($request->get('ssel')) { if ($request->get('ssel')) {
$repository = $app['EM']->getRepository('\Entities\Basket'); $repository = $app['EM']->getRepository('\Entities\Basket');
$basket = $repository->findUserBasket($app, $request->get('ssel'), $app['phraseanet.user'], false); $basket = $repository->findUserBasket($app, $request->get('ssel'), $app['authentication']->getUser(), false);
foreach ($basket->getElements() as $basket_element) { foreach ($basket->getElements() as $basket_element) {
$received[$basket_element->getRecord($app)->get_serialize_key()] = $basket_element->getRecord($app); $received[$basket_element->getRecord($app)->get_serialize_key()] = $basket_element->getRecord($app);
@@ -208,7 +208,7 @@ class RecordsRequest extends ArrayCollection
$repository = $app['EM']->getRepository('\Entities\StoryWZ'); $repository = $app['EM']->getRepository('\Entities\StoryWZ');
$storyWZ = $repository->findByUserAndId( $storyWZ = $repository->findByUserAndId(
$app, $app['phraseanet.user'] $app, $app['authentication']->getUser()
, $request->get('story') , $request->get('story')
); );
@@ -235,20 +235,20 @@ class RecordsRequest extends ArrayCollection
foreach ($elements as $id => $record) { foreach ($elements as $id => $record) {
if (!$app['phraseanet.user']->ACL()->has_access_to_record($record)) { if (!$app['authentication']->getUser()->ACL()->has_access_to_record($record)) {
$to_remove[] = $id; $to_remove[] = $id;
continue; continue;
} }
foreach ($rightsColl as $right) { foreach ($rightsColl as $right) {
if (!$app['phraseanet.user']->ACL()->has_right_on_base($record->get_base_id(), $right)) { if (!$app['authentication']->getUser()->ACL()->has_right_on_base($record->get_base_id(), $right)) {
$to_remove[] = $id; $to_remove[] = $id;
continue; continue;
} }
} }
foreach ($rightsDatabox as $right) { foreach ($rightsDatabox as $right) {
if (!$app['phraseanet.user']->ACL()->has_right_on_sbas($record->get_sbas_id(), $right)) { if (!$app['authentication']->getUser()->ACL()->has_right_on_sbas($record->get_sbas_id(), $right)) {
$to_remove[] = $id; $to_remove[] = $id;
continue; continue;
} }

View File

@@ -81,7 +81,7 @@ class Notifications implements ControllerProviderInterface
try { try {
$app['events-manager']->read( $app['events-manager']->read(
explode('_', (string) $request->request->get('notifications')), explode('_', (string) $request->request->get('notifications')),
$app['phraseanet.user']->get_id() $app['authentication']->getUser()->get_id()
); );
return $app->json(array('success' => true, 'message' => '')); return $app->json(array('success' => true, 'message' => ''));

View File

@@ -111,7 +111,7 @@ class Preferences implements ControllerProviderInterface
$success = false; $success = false;
if ($prop && $value) { if ($prop && $value) {
$success = !!$app['phraseanet.user']->setPrefs($prop, $value); $success = !!$app['authentication']->getUser()->setPrefs($prop, $value);
$msg = _('Preference saved !'); $msg = _('Preference saved !');
} }

View File

@@ -16,6 +16,7 @@ use Alchemy\Phrasea\Authentication\Manager;
use Alchemy\Phrasea\Authentication\ProvidersCollection; use Alchemy\Phrasea\Authentication\ProvidersCollection;
use Alchemy\Phrasea\Authentication\Provider\Facebook; use Alchemy\Phrasea\Authentication\Provider\Facebook;
use Alchemy\Phrasea\Authentication\Phrasea\FailureManager; use Alchemy\Phrasea\Authentication\Phrasea\FailureManager;
use Alchemy\Phrasea\Authentication\PersistentCookie\Manager as CookieManager;
use Alchemy\Phrasea\Authentication\Phrasea\NativeAuthentication; use Alchemy\Phrasea\Authentication\Phrasea\NativeAuthentication;
use Alchemy\Phrasea\Authentication\Phrasea\OldPasswordEncoder; use Alchemy\Phrasea\Authentication\Phrasea\OldPasswordEncoder;
use Alchemy\Phrasea\Authentication\Phrasea\PasswordEncoder; use Alchemy\Phrasea\Authentication\Phrasea\PasswordEncoder;
@@ -36,6 +37,10 @@ class AuthenticationManagerServiceProvider implements ServiceProviderInterface
return new TokenValidator($app); return new TokenValidator($app);
}); });
$app['authentication.persistent-manager'] = $app->share(function (Application $app){
return new CookieManager($app['auth.password-encoder'], $app['EM'], $app['browser']);
});
// $app['authentication.suggestion-finder'] = $app->share(function (Application $app) { // $app['authentication.suggestion-finder'] = $app->share(function (Application $app) {
// return new SuggestionFinder($app); // return new SuggestionFinder($app);
@@ -43,14 +48,14 @@ class AuthenticationManagerServiceProvider implements ServiceProviderInterface
$app['authentication.providers'] = $app->share(function (Application $app) { $app['authentication.providers'] = $app->share(function (Application $app) {
$config = array(); // $config = array();
$config['appId'] = '252378391562465'; // $config['appId'] = '252378391562465';
$config['secret'] = 'd9df4bb1ad34aab4f6728b4076e1f9c4'; // $config['secret'] = 'd9df4bb1ad34aab4f6728b4076e1f9c4';
//
$facebook = new \Facebook($config); // $facebook = new \Facebook($config);
$providers = new ProvidersCollection(); $providers = new ProvidersCollection();
$providers->register(new Facebook($facebook, $app['url_generator'])); // $providers->register(new Facebook($facebook, $app['url_generator']));
return $providers; return $providers;
}); });

View File

@@ -11,6 +11,10 @@
use Alchemy\Phrasea\Application; use Alchemy\Phrasea\Application;
use Alchemy\Phrasea\Authentication\Exception\AccountLockedException;
use Alchemy\Phrasea\Authentication\Exception\RequireCaptchaException;
use Symfony\Component\HttpFoundation\Request;
/** /**
* *
* *
@@ -373,10 +377,10 @@ class API_OAuth2_Adapter extends OAuth2
/** /**
* *
* @param Symfony\Component\HttpFoundation\Request $request * @param Request $request
* @return array * @return array
*/ */
public function getAuthorizationRequestParameters(Symfony\Component\HttpFoundation\Request $request) public function getAuthorizationRequestParameters(Request $request)
{ {
$datas = array( $datas = array(
@@ -715,9 +719,9 @@ class API_OAuth2_Adapter extends OAuth2
$stored = $this->checkUserCredentials($client[0], $input["username"], $input["password"]); $stored = $this->checkUserCredentials($client[0], $input["username"], $input["password"]);
if ($stored === FALSE) if ($stored === false) {
$this->errorJsonResponse(OAUTH2_HTTP_BAD_REQUEST, OAUTH2_ERROR_INVALID_GRANT, 'Unknow user'); $this->errorJsonResponse(OAUTH2_HTTP_BAD_REQUEST, OAUTH2_ERROR_INVALID_GRANT, 'Username/password mismatch or account locked, please try to log in via Web Application');
}
break; break;
case OAUTH2_GRANT_TYPE_ASSERTION: case OAUTH2_GRANT_TYPE_ASSERTION:
if ( ! $input["assertion_type"] || ! $input["assertion"]) if ( ! $input["assertion_type"] || ! $input["assertion"])
@@ -796,17 +800,25 @@ class API_OAuth2_Adapter extends OAuth2
try { try {
$application = API_OAuth2_Application::load_from_client_id($this->app, $client_id); $application = API_OAuth2_Application::load_from_client_id($this->app, $client_id);
$auth = new \Session_Authentication_Native($this->app, $username, $password); $usr_id = $this->app['auth']->isValid($username, $password, Request::createFromGlobals());
$auth->challenge_password(); if (!$usr_id) {
return false;
}
$account = API_OAuth2_Account::load_with_user($this->app, $application, $auth->get_user()); $user = \User_Adapter::getInstance($usr_id, $this->app);
$account = API_OAuth2_Account::load_with_user($this->app, $application, $user);
return array( return array(
'redirect_uri' => $application->get_redirect_uri() 'redirect_uri' => $application->get_redirect_uri()
, 'client_id' => $application->get_client_id() , 'client_id' => $application->get_client_id()
, 'account_id' => $account->get_id() , 'account_id' => $account->get_id()
); );
} catch (AccountLockedException $e) {
return false;
} catch (RequireCaptchaException $e) {
return false;
} catch (\Exception $e) { } catch (\Exception $e) {
return false; return false;
} }

View File

@@ -126,7 +126,7 @@ class Session_Logger
':ses_id' => $app['session']->get('session_id'), ':ses_id' => $app['session']->get('session_id'),
':usr_login' => $app['authentication']->getUser() ? $app['authentication']->getUser()->get_login() : null, ':usr_login' => $app['authentication']->getUser() ? $app['authentication']->getUser()->get_login() : null,
':site_id' => $app['phraseanet.registry']->get('GV_sit'), ':site_id' => $app['phraseanet.registry']->get('GV_sit'),
':usr_id' => $app['phraseanet.user'] ? $app['phraseanet.user']->get_id() : null, ':usr_id' => $app['authentication']->isAuthenticated() ? $app['authentication']->getUser()->get_id() : null,
':browser' => $browser->getBrowser(), ':browser' => $browser->getBrowser(),
':browser_version' => $browser->getExtendedVersion(), ':browser_version' => $browser->getExtendedVersion(),
':platform' => $browser->getPlatform(), ':platform' => $browser->getPlatform(),

View File

@@ -315,6 +315,8 @@ class User_Adapter implements User_Interface, cache_cacheableInterface
*/ */
protected $template_owner; protected $template_owner;
protected $password;
/** /**
* *
* @param Integer $id * @param Integer $id
@@ -1045,7 +1047,7 @@ class User_Adapter implements User_Interface, cache_cacheableInterface
*/ */
public function load($id) public function load($id)
{ {
$sql = 'SELECT usr_id, ldap_created, create_db, usr_login, usr_nom, activite, $sql = 'SELECT usr_id, ldap_created, create_db, usr_login, usr_password, usr_nom, activite,
usr_prenom, usr_sexe as gender, usr_mail, adresse, usr_creationdate, usr_modificationdate, usr_prenom, usr_sexe as gender, usr_mail, adresse, usr_creationdate, usr_modificationdate,
ville, cpostal, tel, fax, fonction, societe, geonameid, lastModel, invite, ville, cpostal, tel, fax, fonction, societe, geonameid, lastModel, invite,
defaultftpdatasent, mail_notifications, activeftp, addrftp, loginftp, defaultftpdatasent, mail_notifications, activeftp, addrftp, loginftp,
@@ -1065,6 +1067,7 @@ class User_Adapter implements User_Interface, cache_cacheableInterface
$this->id = (int) $row['usr_id']; $this->id = (int) $row['usr_id'];
$this->email = $row['usr_mail']; $this->email = $row['usr_mail'];
$this->login = $row['usr_login']; $this->login = $row['usr_login'];
$this->password = $row['usr_password'];
$this->ldap_created = $row['ldap_created']; $this->ldap_created = $row['ldap_created'];
@@ -1166,6 +1169,11 @@ class User_Adapter implements User_Interface, cache_cacheableInterface
return $this->login; return $this->login;
} }
public function get_password()
{
return $this->password;
}
public function get_email() public function get_email()
{ {
return $this->email; return $this->email;

View File

@@ -233,11 +233,16 @@ class User_Query implements User_QueryInterface
} }
if ($this->only_templates === true) { if ($this->only_templates === true) {
if (!$this->app['authentication']->getUser()) {
throw new InvalidArgumentException('Unable to load templates while disconnected');
}
$sql .= ' AND model_of = ' . $this->app['authentication']->getUser()->get_id(); $sql .= ' AND model_of = ' . $this->app['authentication']->getUser()->get_id();
} elseif ($this->include_templates === false) { } elseif ($this->include_templates === false) {
$sql .= ' AND model_of=0'; $sql .= ' AND model_of=0';
} else { } elseif ($this->app['authentication']->getUser()) {
$sql .= ' AND (model_of=0 OR model_of = ' . $this->app['authentication']->getUser()->get_id() . ' ) '; $sql .= ' AND (model_of=0 OR model_of = ' . $this->app['authentication']->getUser()->get_id() . ' ) ';
} else {
$sql .= ' AND model_of=0';
} }
if ($this->activities) { if ($this->activities) {