Cleanup controllers

This commit is contained in:
Romain Neutron
2012-09-28 13:01:31 +02:00
parent f68cae2bb4
commit 75d6ce4982
11 changed files with 361 additions and 407 deletions

View File

@@ -29,8 +29,7 @@ class Permalink extends AbstractDelivery
$that = $this; $that = $this;
$controllers->get('/v1/{label}/{sbas_id}/{record_id}/{key}/{subdef}/view/' $controllers->get('/v1/{label}/{sbas_id}/{record_id}/{key}/{subdef}/view/', function($label, $sbas_id, $record_id, $key, $subdef, PhraseaApplication $app) {
, function($label, $sbas_id, $record_id, $key, $subdef, PhraseaApplication $app) {
$databox = $app['phraseanet.appbox']->get_databox((int) $sbas_id); $databox = $app['phraseanet.appbox']->get_databox((int) $sbas_id);
@@ -48,7 +47,7 @@ class Permalink extends AbstractDelivery
, 'record' => $record , 'record' => $record
); );
return new Response($app['twig']->render('overview.html.twig', $params)); return $app['twig']->render('overview.html.twig', $params);
})->assert('sbas_id', '\d+')->assert('record_id', '\d+'); })->assert('sbas_id', '\d+')->assert('record_id', '\d+');
$controllers->get('/v1/{label}/{sbas_id}/{record_id}/{key}/{subdef}/', function(Application $app, $label, $sbas_id, $record_id, $key, $subdef) use ($that) { $controllers->get('/v1/{label}/{sbas_id}/{record_id}/{key}/{subdef}/', function(Application $app, $label, $sbas_id, $record_id, $key, $subdef) use ($that) {
@@ -95,9 +94,7 @@ class Permalink extends AbstractDelivery
} }
return $that->deliverContent($app['request'], $record, $subdef, $watermark, $stamp, $app); return $that->deliverContent($app['request'], $record, $subdef, $watermark, $stamp, $app);
} })->assert('sbas_id', '\d+')->assert('record_id', '\d+');
)
->assert('sbas_id', '\d+')->assert('record_id', '\d+');
return $controllers; return $controllers;
} }

View File

@@ -208,8 +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, $app['phraseanet.user']
$app['phraseanet.user']
, $request->get('story') , $request->get('story')
); );

View File

@@ -33,7 +33,7 @@ class Account implements ControllerProviderInterface
$controllers->before(function() use ($app) { $controllers->before(function() use ($app) {
$response = $app['firewall']->requireAuthentication(); $response = $app['firewall']->requireAuthentication();
if($response instanceof Response) { if ($response instanceof Response) {
return $response; return $response;
} }
}); });
@@ -248,9 +248,9 @@ class Account implements ControllerProviderInterface
} }
} }
return new Response($app['twig']->render('account/reset-password.html.twig', array( return $app['twig']->render('account/reset-password.html.twig', array(
'passwordMsg' => $passwordMsg 'passwordMsg' => $passwordMsg
))); ));
} }
/** /**
@@ -291,21 +291,17 @@ class Account implements ControllerProviderInterface
$auth = new \Session_Authentication_Native($app, $user->get_login(), $password); $auth = new \Session_Authentication_Native($app, $user->get_login(), $password);
$auth->challenge_password(); $auth->challenge_password();
} catch (\Exception $e) { } catch (\Exception $e) {
return $app->redirect('/account/reset-email/?notice=bad-password'); return $app->redirect('/account/reset-email/?notice=bad-password');
} }
if ( ! \PHPMailer::ValidateAddress($email)) { if (!\PHPMailer::ValidateAddress($email)) {
return $app->redirect('/account/reset-email/?notice=mail-invalid'); return $app->redirect('/account/reset-email/?notice=mail-invalid');
} }
if ($email !== $emailConfirm) { if ($email !== $emailConfirm) {
return $app->redirect('/account/reset-email/?notice=mail-match'); return $app->redirect('/account/reset-email/?notice=mail-match');
} }
if ( ! \mail::reset_email($app, $email, $user->get_id()) === true) { if (!\mail::reset_email($app, $email, $user->get_id()) === true) {
return $app->redirect('/account/reset-email/?notice=mail-server'); return $app->redirect('/account/reset-email/?notice=mail-server');
} }
@@ -352,10 +348,10 @@ class Account implements ControllerProviderInterface
} }
} }
return new Response($app['twig']->render('account/reset-email.html.twig', array( return $app['twig']->render('account/reset-email.html.twig', array(
'noticeMsg' => $noticeMsg, 'noticeMsg' => $noticeMsg,
'updateMsg' => $updateMsg, 'updateMsg' => $updateMsg,
))); ));
} }
/** /**
@@ -371,13 +367,10 @@ class Account implements ControllerProviderInterface
if ((null !== $password = $request->request->get('form_password')) && (null !== $passwordConfirm = $request->request->get('form_password_confirm'))) { if ((null !== $password = $request->request->get('form_password')) && (null !== $passwordConfirm = $request->request->get('form_password_confirm'))) {
if ($password !== $passwordConfirm) { if ($password !== $passwordConfirm) {
return $app->redirect('/account/reset-password/?pass-error=pass-match'); return $app->redirect('/account/reset-password/?pass-error=pass-match');
} elseif (strlen(trim($password)) < 5) { } elseif (strlen(trim($password)) < 5) {
return $app->redirect('/account/reset-password/?pass-error=pass-short'); return $app->redirect('/account/reset-password/?pass-error=pass-short');
} elseif (trim($password) != str_replace(array("\r\n", "\n", "\r", "\t", " "), "_", $password)) { } elseif (trim($password) != str_replace(array("\r\n", "\n", "\r", "\t", " "), "_", $password)) {
return $app->redirect('/account/reset-password/?pass-error=pass-invalid'); return $app->redirect('/account/reset-password/?pass-error=pass-invalid');
} }
@@ -405,7 +398,7 @@ class Account implements ControllerProviderInterface
*/ */
public function grantAccess(Application $app, Request $request, $application_id) public function grantAccess(Application $app, Request $request, $application_id)
{ {
if ( ! $request->isXmlHttpRequest() || ! array_key_exists($request->getMimeType('json'), array_flip($request->getAcceptableContentTypes()))) { if (!$request->isXmlHttpRequest() || !array_key_exists($request->getMimeType('json'), array_flip($request->getAcceptableContentTypes()))) {
$app->abort(400, _('Bad request format, only JSON is allowed')); $app->abort(400, _('Bad request format, only JSON is allowed'));
} }
@@ -424,7 +417,7 @@ class Account implements ControllerProviderInterface
$error = true; $error = true;
} }
return $app->json(array('success' => ! $error)); return $app->json(array('success' => !$error));
} }
/** /**
@@ -438,9 +431,9 @@ class Account implements ControllerProviderInterface
{ {
require_once $app['phraseanet.registry']->get('GV_RootPath') . 'lib/classes/deprecated/inscript.api.php'; require_once $app['phraseanet.registry']->get('GV_RootPath') . 'lib/classes/deprecated/inscript.api.php';
return new Response($app['twig']->render('account/access.html.twig', array( return $app['twig']->render('account/access.html.twig', array(
'inscriptions' => giveMeBases($app, $app['phraseanet.user']->get_id()) 'inscriptions' => giveMeBases($app, $app['phraseanet.user']->get_id())
))); ));
} }
/** /**
@@ -466,46 +459,15 @@ class Account implements ControllerProviderInterface
*/ */
public function accountSessionsAccess(Application $app, Request $request) public function accountSessionsAccess(Application $app, Request $request)
{ {
$dql = 'SELECT s FROM Entities\Session s $dql = 'SELECT s FROM Entities\Session s
WHERE s.usr_id = :usr_id WHERE s.usr_id = :usr_id
ORDER BY s.created DESC'; ORDER BY s.created DESC';
$query = $app['EM']->createQuery($dql); $query = $app['EM']->createQuery($dql);
$query->setParameters(array('usr_id'=>$app['session']->get('usr_id'))); $query->setParameters(array('usr_id' => $app['session']->get('usr_id')));
$sessions = $query->getResult(); $sessions = $query->getResult();
// $sql = 'SELECT session_id, lastaccess, ip, platform, browser, screen return $app['twig']->render('account/sessions.html.twig', array('sessions' => $sessions));
// , created_on, browser_version, token
// FROM cache WHERE usr_id = :usr_id';
//
//
// $stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql);
// $stmt->execute(array(':usr_id' => $this->get_usr_id()));
// $rs = $stmt->fetchAll(PDO::FETCH_ASSOC);
// $stmt->closeCursor();
//
// $geonames = new geonames();
//
// foreach ($rs as $k => $row) {
// $datas = $geonames->find_geoname_from_ip($row['ip'], $this->app);
//
// if ($datas['city']) {
// $infos = $datas['city'] . ' (' . $datas['country'] . ')';
// } elseif ($datas['fips']) {
// $infos = $datas['fips'] . ' (' . $datas['country'] . ')';
// } elseif ($datas['country']) {
// $infos = $datas['country'];
// } else {
// $infos = '';
// }
// $rs[$k]['session_id'] = (int) $rs[$k]['session_id'];
// $rs[$k]['ip_infos'] = $infos;
// $rs[$k]['created_on'] = new \DateTime($row['created_on']);;
// $rs[$k]['lastaccess'] = new \DateTime($row['lastaccess']);
// }
return new Response($app['twig']->render('account/sessions.html.twig', array('sessions'=>$sessions)));
} }
/** /**
@@ -539,12 +501,12 @@ class Account implements ControllerProviderInterface
break; break;
} }
return new Response($app['twig']->render('account/account.html.twig', array( return $app['twig']->render('account/account.html.twig', array(
'user' => $user, 'user' => $user,
'notice' => $notice, 'notice' => $notice,
'evt_mngr' => $evtMngr, 'evt_mngr' => $evtMngr,
'notifications' => $evtMngr->list_notifications_available($user->get_id()), 'notifications' => $evtMngr->list_notifications_available($user->get_id()),
))); ));
} }
/** /**

View File

@@ -184,7 +184,7 @@ class Developers implements ControllerProviderInterface
*/ */
public function deleteApp(Application $app, Request $request, $id) public function deleteApp(Application $app, Request $request, $id)
{ {
if ( ! $request->isXmlHttpRequest() || ! array_key_exists($request->getMimeType('json'), array_flip($request->getAcceptableContentTypes()))) { if (!$request->isXmlHttpRequest() || !array_key_exists($request->getMimeType('json'), array_flip($request->getAcceptableContentTypes()))) {
$app->abort(400, _('Bad request format, only JSON is allowed')); $app->abort(400, _('Bad request format, only JSON is allowed'));
} }
@@ -197,7 +197,7 @@ class Developers implements ControllerProviderInterface
$error = true; $error = true;
} }
return $app->json(array('success' => ! $error)); return $app->json(array('success' => !$error));
} }
/** /**
@@ -210,7 +210,7 @@ class Developers implements ControllerProviderInterface
*/ */
public function renewAppCallback(Application $app, Request $request, $id) public function renewAppCallback(Application $app, Request $request, $id)
{ {
if ( ! $request->isXmlHttpRequest() || ! array_key_exists($request->getMimeType('json'), array_flip($request->getAcceptableContentTypes()))) { if (!$request->isXmlHttpRequest() || !array_key_exists($request->getMimeType('json'), array_flip($request->getAcceptableContentTypes()))) {
$app->abort(400, _('Bad request format, only JSON is allowed')); $app->abort(400, _('Bad request format, only JSON is allowed'));
} }
@@ -228,7 +228,7 @@ class Developers implements ControllerProviderInterface
$error = true; $error = true;
} }
return $app->json(array('success' => ! $error)); return $app->json(array('success' => !$error));
} }
/** /**
@@ -241,7 +241,7 @@ class Developers implements ControllerProviderInterface
*/ */
public function renewAccessToken(Application $app, Request $request, $id) public function renewAccessToken(Application $app, Request $request, $id)
{ {
if ( ! $request->isXmlHttpRequest() || ! array_key_exists($request->getMimeType('json'), array_flip($request->getAcceptableContentTypes()))) { if (!$request->isXmlHttpRequest() || !array_key_exists($request->getMimeType('json'), array_flip($request->getAcceptableContentTypes()))) {
$app->abort(400, _('Bad request format, only JSON is allowed')); $app->abort(400, _('Bad request format, only JSON is allowed'));
} }
@@ -266,7 +266,7 @@ class Developers implements ControllerProviderInterface
$error = true; $error = true;
} }
return $app->json(array('success' => ! $error, 'token' => $accessToken)); return $app->json(array('success' => !$error, 'token' => $accessToken));
} }
/** /**
@@ -279,7 +279,7 @@ class Developers implements ControllerProviderInterface
*/ */
public function authorizeGrantpassword(Application $app, Request $request, $id) public function authorizeGrantpassword(Application $app, Request $request, $id)
{ {
if ( ! $request->isXmlHttpRequest() || ! array_key_exists($request->getMimeType('json'), array_flip($request->getAcceptableContentTypes()))) { if (!$request->isXmlHttpRequest() || !array_key_exists($request->getMimeType('json'), array_flip($request->getAcceptableContentTypes()))) {
$app->abort(400, _('Bad request format, only JSON is allowed')); $app->abort(400, _('Bad request format, only JSON is allowed'));
} }
@@ -292,7 +292,7 @@ class Developers implements ControllerProviderInterface
$error = true; $error = true;
} }
return $app->json(array('success' => ! $error)); return $app->json(array('success' => !$error));
} }
/** /**
@@ -341,9 +341,8 @@ class Developers implements ControllerProviderInterface
public function listApps(Application $app, Request $request) public function listApps(Application $app, Request $request)
{ {
return $app['twig']->render('developers/applications.html.twig', array( return $app['twig']->render('developers/applications.html.twig', array(
"applications" => \API_OAuth2_Application::load_dev_app_by_user( "applications" => \API_OAuth2_Application::load_dev_app_by_user($app, $app['phraseanet.user'])
$app, $app['phraseanet.user'] ));
)));
} }
/** /**

View File

@@ -418,12 +418,12 @@ class Login implements ControllerProviderInterface
} }
} }
return new Response($app['twig']->render('login/forgot-password.html.twig', array( return $app['twig']->render('login/forgot-password.html.twig', array(
'tokenize' => $tokenize, 'tokenize' => $tokenize,
'passwordMsg' => $passwordMsg, 'passwordMsg' => $passwordMsg,
'errorMsg' => $errorMsg, 'errorMsg' => $errorMsg,
'sentMsg' => $sentMsg 'sentMsg' => $sentMsg
))); ));
} }
/** /**
@@ -476,14 +476,14 @@ class Login implements ControllerProviderInterface
$arrayVerif = $this->getRegisterFieldConfiguration($app); $arrayVerif = $this->getRegisterFieldConfiguration($app);
return new Response($app['twig']->render('login/register.html.twig', array( return $app['twig']->render('login/register.html.twig', array(
'inscriptions' => giveMeBases($app), 'inscriptions' => giveMeBases($app),
'parms' => $request->query->all(), 'parms' => $request->query->all(),
'needed' => $needed, 'needed' => $needed,
'arrayVerif' => $arrayVerif, 'arrayVerif' => $arrayVerif,
'demandes' => $request->query->get('demand', array()), 'demandes' => $request->query->get('demand', array()),
'lng' => $app['locale'] 'lng' => $app['locale']
))); ));
} }
/** /**

View File

@@ -143,8 +143,7 @@ class Installer implements ControllerProviderInterface
, 'current_servername' => $request->getScheme() . '://' . $request->getHttpHost() . '/' , 'current_servername' => $request->getScheme() . '://' . $request->getHttpHost() . '/'
, 'discovered_binaries' => \setup::discover_binaries() , 'discovered_binaries' => \setup::discover_binaries()
, 'rootpath' => dirname(dirname(dirname(dirname(__DIR__)))) . '/' , 'rootpath' => dirname(dirname(dirname(dirname(__DIR__)))) . '/'
) ));
);
} }
public function doInstall(Application $app, Request $request) public function doInstall(Application $app, Request $request)

View File

@@ -28,7 +28,6 @@ class PathFileTest implements ControllerProviderInterface
$controllers = $app['controllers_factory']; $controllers = $app['controllers_factory'];
$controllers->get('/path/', function(Application $app, Request $request) { $controllers->get('/path/', function(Application $app, Request $request) {
return $app->json(array( return $app->json(array(
'exists' => file_exists($request->query->get('path')) 'exists' => file_exists($request->query->get('path'))
, 'file' => is_file($request->query->get('path')) , 'file' => is_file($request->query->get('path'))
@@ -40,7 +39,6 @@ class PathFileTest implements ControllerProviderInterface
}); });
$controllers->get('/url/', function(Application $app, Request $request) { $controllers->get('/url/', function(Application $app, Request $request) {
return $app->json(array('code' => \http_query::getHttpCodeFromUrl($request->query->get('url')))); return $app->json(array('code' => \http_query::getHttpCodeFromUrl($request->query->get('url'))));
}); });