Code cleanup

This commit is contained in:
Romain Neutron
2012-07-18 19:11:15 +02:00
parent 5d99aa0b03
commit 431e1278b0
13 changed files with 489 additions and 382 deletions

View File

@@ -36,10 +36,10 @@ class ConnectedUsers implements ControllerProviderInterface
$controllers->get('/', function(Application $app, Request $request) { $controllers->get('/', function(Application $app, Request $request) {
$app['Core']['Twig']->addFilter('AppName', new \Twig_Filter_Function(__CLASS__ . '::appName')); $app['phraseanet.core']['Twig']->addFilter('AppName', new \Twig_Filter_Function(__CLASS__ . '::appName'));
return new Response( return new Response(
$app['Core']['Twig']->render( $app['phraseanet.core']['Twig']->render(
'admin/connected-users.html.twig', array('datas' => \Session_Handler::get_active_sessions() 'admin/connected-users.html.twig', array('datas' => \Session_Handler::get_active_sessions()
) )
) )

View File

@@ -11,10 +11,11 @@
namespace Alchemy\Phrasea\Controller\Admin; namespace Alchemy\Phrasea\Controller\Admin;
use Alchemy\Phrasea\Vocabulary\Controller as VocabularyController;
use PHPExiftool\Driver\TagProvider; use PHPExiftool\Driver\TagProvider;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\RedirectResponse; use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
use Silex\Application; use Silex\Application;
use Silex\ControllerProviderInterface; use Silex\ControllerProviderInterface;
@@ -155,43 +156,33 @@ class Description implements ControllerProviderInterface
return $app->json($res); return $app->json($res);
}); });
$controllers->post('/{sbas_id}/', function(Application $app, $sbas_id) { $controllers->post('/{sbas_id}/', function(Application $app, Request $request, $sbas_id) {
$user = $app['phraseanet.core']->getAuthenticatedUser();
$request = $app['request'];
if ( ! $user->ACL()->has_right_on_sbas($sbas_id, 'bas_modify_struct')) {
throw new \Exception_Forbidden('You are not allowed to access this zone');
}
$databox = $app['phraseanet.appbox']->get_databox((int) $sbas_id); $databox = $app['phraseanet.appbox']->get_databox((int) $sbas_id);
$fields = $databox->get_meta_structure();
$available_dc_fields = $databox->get_available_dcfields();
$databox->get_connection()->beginTransaction(); $databox->get_connection()->beginTransaction();
$error = false;
try { try {
if (is_array($request->get('field_ids'))) { if (is_array($request->get('field_ids'))) {
foreach ($request->get('field_ids') as $id) { foreach ($request->get('field_ids') as $id) {
try { try {
$field = \databox_field::get_instance($databox, $id); $field = \databox_field::get_instance($databox, $id);
$field->set_name($request->get('name_' . $id)); $field->set_name($request->get('name_' . $id))
$field->set_thumbtitle($request->get('thumbtitle_' . $id)); ->set_thumbtitle($request->get('thumbtitle_' . $id))
$field->set_tag(\databox_field::loadClassFromTagName($request->get('src_' . $id))); ->set_tag(\databox_field::loadClassFromTagName($request->get('src_' . $id)))
$field->set_business($request->get('business_' . $id)); ->set_multi($request->get('multi_' . $id))
$field->set_indexable($request->get('indexable_' . $id)); ->set_business($request->get('business_' . $id))
$field->set_required($request->get('required_' . $id)); ->set_indexable($request->get('indexable_' . $id))
$field->set_separator($request->get('separator_' . $id)); ->set_required($request->get('required_' . $id))
$field->set_readonly($request->get('readonly_' . $id)); ->set_separator($request->get('separator_' . $id))
$field->set_type($request->get('type_' . $id)); ->set_readonly($request->get('readonly_' . $id))
$field->set_tbranch($request->get('tbranch_' . $id)); ->set_type($request->get('type_' . $id))
$field->set_report($request->get('report_' . $id)); ->set_tbranch($request->get('tbranch_' . $id))
->set_report($request->get('report_' . $id))
$field->setVocabularyControl(null); ->setVocabularyControl(null)
$field->setVocabularyRestricted(false); ->setVocabularyRestricted(false);
try { try {
$vocabulary = \Alchemy\Phrasea\Vocabulary\Controller::get($request->get('vocabulary_' . $id)); $vocabulary = VocabularyController::get($request->get('vocabulary_' . $id));
$field->setVocabularyControl($vocabulary); $field->setVocabularyControl($vocabulary);
$field->setVocabularyRestricted($request->get('vocabularyrestricted_' . $id)); $field->setVocabularyRestricted($request->get('vocabularyrestricted_' . $id));
} catch (\Exception $e) { } catch (\Exception $e) {
@@ -201,11 +192,11 @@ class Description implements ControllerProviderInterface
$dces_element = null; $dces_element = null;
$class = 'databox_Field_DCES_' . $request->get('dces_' . $id); $class = 'databox_Field_DCES_' . $request->get('dces_' . $id);
if (class_exists($class)) if (class_exists($class)) {
$dces_element = new $class(); $dces_element = new $class();
}
$field->set_dces_element($dces_element); $field->set_dces_element($dces_element)->save();
$field->save();
} catch (\Exception $e) { } catch (\Exception $e) {
continue; continue;
} }
@@ -226,41 +217,37 @@ class Description implements ControllerProviderInterface
} }
} }
} }
} catch (\Exception $e) {
$error = true;
}
if ($error) {
$databox->get_connection()->rollBack();
} else {
$databox->get_connection()->commit(); $databox->get_connection()->commit();
} catch (\Exception $e) {
$databox->get_connection()->rollBack();
} }
return $app->redirect('/admin/description/' . $sbas_id . '/'); return $app->redirect('/admin/description/' . $sbas_id . '/');
})->before(function(Request $request) use ($app) {
if (false === $app['phraseanet.core']->getAuthenticatedUser()->ACL()
->has_right_on_sbas($request->get('sbas_id'), 'bas_modify_struct')) {
throw new AccessDeniedHttpException('You are not allowed to access this zone');
}
})->assert('sbas_id', '\d+'); })->assert('sbas_id', '\d+');
$controllers->get('/{sbas_id}/', function(Application $app, $sbas_id) { $controllers->get('/{sbas_id}/', function(Application $app, $sbas_id) {
$user = $app['phraseanet.core']->getAuthenticatedUser();
$request = $app['request'];
if ( ! $user->ACL()->has_right_on_sbas($sbas_id, 'bas_modify_struct')) {
throw new \Exception_Forbidden('You are not allowed to access this zone');
}
$databox = \databox::get_instance((int) $sbas_id); $databox = \databox::get_instance((int) $sbas_id);
$fields = $databox->get_meta_structure();
$available_dc_fields = $databox->get_available_dcfields();
$params = array( $params = array(
'databox' => $databox, 'databox' => $databox,
'fields' => $fields, 'fields' => $databox->get_meta_structure(),
'available_dc_fields' => $available_dc_fields, 'available_dc_fields' => $databox->get_available_dcfields(),
'vocabularies' => \Alchemy\Phrasea\Vocabulary\Controller::getAvailable(), 'vocabularies' => VocabularyController::getAvailable(),
); );
return new Response($app['phraseanet.core']->getTwig()->render('admin/databox/doc_structure.twig', $params)); return new Response($app['phraseanet.core']->getTwig()->render('admin/databox/doc_structure.twig', $params));
})->before(function(Request $request) use ($app) {
if (false === $app['phraseanet.core']->getAuthenticatedUser()->ACL()
->has_right_on_sbas($request->get('sbas_id'), 'bas_modify_struct')) {
throw new AccessDeniedHttpException('You are not allowed to access this zone');
}
})->assert('sbas_id', '\d+'); })->assert('sbas_id', '\d+');
return $controllers; return $controllers;

View File

@@ -11,11 +11,10 @@
namespace Alchemy\Phrasea\Controller\Admin; namespace Alchemy\Phrasea\Controller\Admin;
use Alchemy\Phrasea\Application as PhraseaApplication;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Silex\Application; use Silex\Application;
use Silex\ControllerProviderInterface; use Silex\ControllerProviderInterface;
use Silex\ControllerCollection;
/** /**
* *
@@ -27,12 +26,9 @@ class Fields implements ControllerProviderInterface
public function connect(Application $app) public function connect(Application $app)
{ {
$appbox = $app['phraseanet.appbox'];
$controllers = $app['controllers_factory']; $controllers = $app['controllers_factory'];
$controllers->get('/checkmulti/', function() use ($app, $appbox) { $controllers->get('/checkmulti/', function(PhraseaApplication $app, Request $request) {
$request = $app['request'];
$multi = ($request->get('multi') === 'true'); $multi = ($request->get('multi') === 'true');
@@ -43,17 +39,10 @@ class Fields implements ControllerProviderInterface
'is_multi' => $tag->isMulti(), 'is_multi' => $tag->isMulti(),
); );
$Serializer = $app['phraseanet.core']['Serializer']; return $app->json($app['phraseanet.core']['Serializer']->serialize($datas, 'json'));
return new Response(
$Serializer->serialize($datas, 'json')
, 200
, array('Content-Type' => 'application/json')
);
}); });
$controllers->get('/checkreadonly/', function() use ($app, $appbox) { $controllers->get('/checkreadonly/', function(PhraseaApplication $app, Request $request) {
$request = $app['request'];
$readonly = ($request->get('readonly') === 'true'); $readonly = ($request->get('readonly') === 'true');
$tag = \databox_field::loadClassFromTagName($request->get('source')); $tag = \databox_field::loadClassFromTagName($request->get('source'));
@@ -63,13 +52,7 @@ class Fields implements ControllerProviderInterface
'is_readonly' => ! $tag->isWritable(), 'is_readonly' => ! $tag->isWritable(),
); );
$Serializer = $app['phraseanet.core']['Serializer']; return $app->json($app['phraseanet.core']['Serializer']->serialize($datas, 'json'));
return new Response(
$Serializer->serialize($datas, 'json'),
200,
array('Content-Type' => 'application/json')
);
}); });
return $controllers; return $controllers;

View File

@@ -11,11 +11,11 @@
namespace Alchemy\Phrasea\Controller\Admin; namespace Alchemy\Phrasea\Controller\Admin;
use Alchemy\Phrasea\Application as PhraseaApplication;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpFoundation\Response;
use Silex\Application; use Silex\Application;
use Silex\ControllerProviderInterface; use Silex\ControllerProviderInterface;
use Silex\ControllerCollection;
/** /**
* *
@@ -27,93 +27,84 @@ class Publications implements ControllerProviderInterface
public function connect(Application $app) public function connect(Application $app)
{ {
$appbox = $app['phraseanet.appbox'];
$session = $appbox->get_session();
$controllers = $app['controllers_factory']; $controllers = $app['controllers_factory'];
$controllers->get('/list/', function() use ($app, $appbox) { $controllers->get('/list/', function(PhraseaApplication $app) {
$user = \User_Adapter::getInstance($appbox->get_session()->get_usr_id(), $appbox);
$feeds = \Feed_Collection::load_all($appbox, $user);
$template = 'admin/publications/list.html'; $feeds = \Feed_Collection::load_all(
/* @var $twig \Twig_Environment */ $app['phraseanet.appbox'], $app['phraseanet.core']->getAuthenticatedUser()
$twig = $app['phraseanet.core']->getTwig();
return $twig->render($template, array('feeds' => $feeds));
});
$controllers->post('/create/', function() use ($app, $appbox) {
$user = \User_Adapter::getInstance($appbox->get_session()->get_usr_id(), $appbox);
$request = $app['request'];
$feed = \Feed_Adapter::create($appbox, $user, $request->get('title'), $request->get('subtitle'));
if ($request->get('public') == '1')
$feed->set_public(true);
elseif ($request->get('base_id'))
$feed->set_collection(\collection::get_from_base_id($request->get('base_id')));
return $app->redirect('/admin/publications/list/');
});
$controllers->get('/feed/{id}/', function($id) use ($app, $appbox) {
$feed = new \Feed_Adapter($appbox, $id);
/* @var $twig \Twig_Environment */
$twig = $app['phraseanet.core']->getTwig();
return $twig->render('admin/publications/fiche.html.twig'
, array(
'feed' => $feed
, 'error' => $app['request']->get('error')
)
); );
})->assert('id', '\d+');
$controllers->post('/feed/{id}/update/', function($id) use ($app, $appbox) { return $app['phraseanet.core']->getTwig()
->render('admin/publications/list.html', array('feeds' => $feeds));
});
$feed = new \Feed_Adapter($appbox, $id); $controllers->post('/create/', function(PhraseaApplication $app, Request $request) {
$user = \User_Adapter::getInstance($appbox->get_session()->get_usr_id(), $appbox);
if ( ! $feed->is_owner($user)) { $user = $app['phraseanet.core']->getAuthenticatedUser();
return $app->redirect('/admin/publications/feed/' . $id . '/?error=' . _('You are not the owner of this feed, you can not edit it'));
$feed = \Feed_Adapter::create(
$app['phraseanet.appbox'], $user, $request->get('title'), $request->get('subtitle')
);
if ($request->get('public') == '1') {
$feed->set_public(true);
} elseif ($request->get('base_id')) {
$feed->set_collection(\collection::get_from_base_id($request->get('base_id')));
} }
$request = $app['request'];
try {
$collection = \collection::get_from_base_id($request->get('base_id'));
} catch (\Exception $e) {
$collection = null;
}
$feed->set_title($request->get('title'));
$feed->set_subtitle($request->get('subtitle'));
$feed->set_collection($collection);
$feed->set_public($request->get('public'));
return $app->redirect('/admin/publications/list/'); return $app->redirect('/admin/publications/list/');
});
$controllers->get('/feed/{id}/', function(PhraseaApplication $app, Request $request, $id) {
$feed = new \Feed_Adapter($app['phraseanet.appbox'], $id);
return $app['phraseanet.core']->getTwig()
->render('admin/publications/fiche.html.twig', array('feed' => $feed, 'error' => $app['request']->get('error')));
})->assert('id', '\d+'); })->assert('id', '\d+');
$controllers->post('/feed/{id}/iconupload/', function($id) use ($app, $appbox) { $controllers->post('/feed/{id}/update/', function(PhraseaApplication $app, Request $request, $id) {
try {
$datas = array(
'success' => false,
'message' => '',
);
$feed = new \Feed_Adapter($appbox, $id); $feed = new \Feed_Adapter($app['phraseanet.appbox'], $id);
$user = $app['phraseanet.core']->getAuthenticatedUser(); try {
$collection = \collection::get_from_base_id($request->get('base_id'));
$request = $app["request"]; } catch (\Exception $e) {
$collection = null;
if ( ! $feed->is_owner($user)) {
throw new \Exception_Forbidden('ERROR:you are not allowed');
} }
$feed->set_title($request->get('title'));
$feed->set_subtitle($request->get('subtitle'));
$feed->set_collection($collection);
$feed->set_public($request->get('public'));
return $app->redirect('/admin/publications/list/');
})->before(function(Request $request) use ($app) {
$feed = new \Feed_Adapter($app['phraseanet.appbox'], $request->get('id'));
if ( ! $feed->is_owner($app['phraseanet.core']->getAuthenticatedUser())) {
return $app->redirect('/admin/publications/feed/' . $request->get('id') . '/?error=' . _('You are not the owner of this feed, you can not edit it'));
}
})
->assert('id', '\d+');
$controllers->post('/feed/{id}/iconupload/', function(PhraseaApplication $app, Request $request, $id) {
$datas = array(
'success' => false,
'message' => '',
);
$feed = new \Feed_Adapter($appbox, $id);
$user = $app['phraseanet.core']->getAuthenticatedUser();
$request = $app["request"];
if ( ! $feed->is_owner($user)) {
throw new \Exception_Forbidden('ERROR:you are not allowed');
}
try {
if ( ! $request->files->get('files')) { if ( ! $request->files->get('files')) {
throw new \Exception_BadRequest('Missing file parameter'); throw new \Exception_BadRequest('Missing file parameter');
} }

View File

@@ -20,7 +20,6 @@ use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpFoundation\Response;
use Silex\Application; use Silex\Application;
use Silex\ControllerProviderInterface; use Silex\ControllerProviderInterface;
use Silex\ControllerCollection;
/** /**
* *
@@ -36,8 +35,8 @@ class Root implements ControllerProviderInterface
$controllers->get('/', function(Application $app, Request $request) { $controllers->get('/', function(Application $app, Request $request) {
$Core = $app['Core']; $Core = $app['phraseanet.core'];
$appbox = \appbox::get_instance($app['Core']); $appbox = $app['phraseanet.appbox'];
$user = $Core->getAuthenticatedUser(); $user = $Core->getAuthenticatedUser();
\User_Adapter::updateClientInfos(3); \User_Adapter::updateClientInfos(3);

View File

@@ -0,0 +1,114 @@
<?php
namespace Alchemy\Phrasea\Controller\Login;
use Silex\Application;
use Silex\ControllerProviderInterface;
use Symfony\Component\HttpFoundation\Request;
class Authenticate implements ControllerProviderInterface
{
public function connect(Application $app)
{
$controllers = $app['controllers_factory'];
$controllers->post('/', __CLASS__ . '::authenticate')
->before('Alchemy\Phrasea\Security\Firewall::requrieNotAuthenticated');
return $controllers;
}
public function authenticate(Application $app, Request $request)
{
/* @var $Core \Alchemy\Phrasea\Core */
$Core = $app['phraseanet.core'];
$appbox = \appbox::get_instance($Core);
$session = $appbox->get_session();
$registry = $appbox->get_registry();
if ($registry->get('GV_captchas')
&& trim($registry->get('GV_captcha_private_key')) !== ''
&& trim($registry->get('GV_captcha_public_key')) !== '')
include($registry->get('GV_RootPath') . 'lib/vendor/recaptcha/recaptchalib.php');
$is_guest = false;
if (null !== $request->get('nolog') && \phrasea::guest_allowed()) {
$is_guest = true;
}
if ((null !== $request->get('login') && null !== $request->get('pwd')) || $is_guest) {
/**
* @todo dispatch an event that can be used to tweak the authentication
* (LDAP....)
*/
// $app['dispatcher']->dispatch();
try {
if ($is_guest) {
$auth = new \Session_Authentication_Guest($appbox);
} else {
$captcha = false;
if ($registry->get('GV_captchas')
&& trim($registry->get('GV_captcha_private_key')) !== ''
&& trim($registry->get('GV_captcha_public_key')) !== ''
&& ! is_null($request->get("recaptcha_challenge_field")
&& ! is_null($request->get("recaptcha_response_field")))) {
$checkCaptcha = recaptcha_check_answer($registry->get('GV_captcha_private_key'), $_SERVER["REMOTE_ADDR"], $request->get("recaptcha_challenge_field"), $request->get("recaptcha_response_field"));
if ($checkCaptcha->is_valid) {
$captcha = true;
}
}
$auth = new \Session_Authentication_Native($appbox, $request->get('login'), $request->get('pwd'));
$auth->set_captcha_challenge($captcha);
}
$session->authenticate($auth);
} catch (\Exception_Session_StorageClosed $e) {
return $app->redirect("/login/?redirect=" . $request->get('redirect') . "&error=session");
} catch (\Exception_Session_RequireCaptcha $e) {
return $app->redirect("/login/?redirect=" . $request->get('redirect') . "&error=captcha");
} catch (\Exception_Unauthorized $e) {
return $app->redirect("/login/?redirect=" . $request->get('redirect') . "&error=auth");
} catch (\Exception_Session_MailLocked $e) {
return $app->redirect("/login/?redirect=" . $request->get('redirect') . "&error=mailNotConfirm&usr=" . $e->get_usr_id());
} catch (\Exception_Session_WrongToken $e) {
return $app->redirect("/login/?redirect=" . $request->get('redirect') . "&error=token");
} catch (\Exception_InternalServerError $e) {
return $app->redirect("/login/?redirect=" . $request->get('redirect') . "&error=session");
} catch (\Exception_ServiceUnavailable $e) {
return $app->redirect("/login/?redirect=" . $request->get('redirect') . "&error=maintenance");
} catch (\Exception_Session_BadSalinity $e) {
$date = new \DateTime('5 minutes');
$usr_id = \User_Adapter::get_usr_id_from_login($request->get('login'));
$url = \random::getUrlToken(\random::TYPE_PASSWORD, $usr_id, $date);
$url = '/account/forgot-password/?token=' . $url . '&salt=1';
return $app->redirect($url);
} catch (\Exception $e) {
return $app->redirect("/login/?redirect=" . $request->get('redirect') . "&error=" . _('An error occured'));
}
$browser = \Browser::getInstance();
if($browser->isMobile()) {
return $app->redirect("/lightbox/");
} elseif ($request->get('redirect')) {
return $app->redirect($request->get('redirect'));
} elseif (true !== $browser->isNewGeneration()) {
return $app->redirect('/client/');
} else {
return $app->redirect('/prod/');
}
} else {
return $app->redirect("/login/");
}
}
}

View File

@@ -46,13 +46,10 @@ class Account implements ControllerProviderInterface
* *
* return : HTML Response * return : HTML Response
*/ */
$controllers->get('/', $this->call('displayAccount')) $controllers->get('/', $this->call('displayAccount'))->bind('account');
->bind('get_account');
/** /**
* Create account route * Update account route
*
* name : create_account
* *
* description : update your account informations * description : update your account informations
* *
@@ -91,8 +88,7 @@ class Account implements ControllerProviderInterface
* *
* return : HTML Response * return : HTML Response
*/ */
$controllers->post('/', $this->call('updateAccount')) $controllers->post('/', $this->call('updateAccount'));
->bind('create_account');
/** /**
@@ -108,8 +104,8 @@ class Account implements ControllerProviderInterface
* *
* return : HTML Response * return : HTML Response
*/ */
$controllers->get('/access/', $this->call('accountAccess')) $controllers->get('/forgot-password/', $this->call('displayForgotPasswordForm'))
->bind('account_access'); ->bind('forgot_password');
/** /**
* Get reset email * Get reset email
@@ -140,90 +136,7 @@ class Account implements ControllerProviderInterface
* *
* return : HTML Response * return : HTML Response
*/ */
$controllers->post('/reset-email/', $this->call('resetEmail')) $controllers->post('/forgot-password/', $this->call('renewPassword'));
->bind('post_account_reset_email');
/**
* Get reset password
*
* name : account_reset_password
*
* description : Display form to reset password
*
* method : GET
*
* parameters : none
*
* return : HTML Response
*/
$controllers->get('/reset-password/', $this->call('resetPassword'))
->bind('account_reset_password');
/**
* Reset user password
*
* name : post_account_reset_password
*
* description : Reset user password
*
* method : POST
*
* parameters : none
*
* return : HTML Response
*/
$controllers->post('/reset-password/', $this->call('renewPassword'))
->bind('post_account_reset_password');
/**
* Get security session
*
* name : account_security_sessions
*
* description : Display user's open sessions
*
* method : GET
*
* parameters : none
*
* return : HTML Response
*/
$controllers->get('/security/sessions/', $this->call('accountSessionsAccess'))
->bind('account_security_sessions');
/**
* Get authorized apps
*
* name : account_security_applications
*
* description : Give authorized applications that can access user informations
*
* method : GET
*
* parameters : none
*
* return : HTML Response
*/
$controllers->get('/security/applications/', $this->call('accountAuthorizedApps'))
->bind('account_security_applications');
/**
* Grant access to an authorized app
*
* name : account_security_applications_grant
*
* description : Grant or revoke access to a client application
*
* method : POST
*
* parameters : none
*
* return : JSON Response
*/
$controllers->post('/security/application/{application_id}/grant/', $this->call('grantAccess'))
->assert('application_id', '\d+')
->bind('account_security_applications_grant');
/** /**
* Give account access * Give account access
@@ -238,8 +151,52 @@ class Account implements ControllerProviderInterface
* *
* return : HTML Response * return : HTML Response
*/ */
$controllers->get('/access/', $this->call('accountAccess')) $controllers->get('/access/', $this->call('accountAccess'))->bind('account_access');
->bind('account_access');
// /**
// * Give account open sessions
// *
// * name : register_account
// *
// * description : Display form to create a new account
// *
// * method : GET
// *
// * parameters : none
// *
// * return : HTML Response
// */
// $controllers->get('/register/', $this->call('registerAccount'))->bind('register_account');
/**
* Give authorized applications that can access user informations
*
* name : reset_email
*
* description : Display form to create a new account
*
* method : GET
*
* parameters : none
*
* return : HTML Response
*/
$controllers->get('/reset-email/', $this->call('resetEmail'))->bind('reset_email');
/**
* Grant access to an authorized app
*
* name : reset_password
*
* description : Display form to create a new account
*
* method : GET
*
* parameters : none
*
* return : HTML Response
*/
$controllers->get('/reset-password/', $this->call('resetPassword'))->bind('reset_password');
/** /**
* Give account open sessions * Give account open sessions
@@ -293,13 +250,11 @@ class Account implements ControllerProviderInterface
return $controllers; return $controllers;
} }
/** public function registerAccount(Application $app, Request $request)
* Display form to reset a password {
* return new Response($app['phraseanet.core']['Twig']->render('account/register.html.twig'));
* @param \Silex\Application $app }
* @param \Symfony\Component\HttpFoundation\Request $request
* @return \Symfony\Component\HttpFoundation\JsonResponse
*/
public function resetPassword(Application $app, Request $request) public function resetPassword(Application $app, Request $request)
{ {
if (null !== $passwordMsg = $request->get('pass-error')) { if (null !== $passwordMsg = $request->get('pass-error')) {
@@ -316,7 +271,7 @@ class Account implements ControllerProviderInterface
} }
} }
return new Response($app['Core']['Twig']->render('account/reset-password.html.twig', array( return new Response($app['phraseanet.core']['Twig']->render('account/reset-password.html.twig', array(
'passwordMsg' => $passwordMsg 'passwordMsg' => $passwordMsg
))); )));
} }
@@ -353,7 +308,7 @@ class Account implements ControllerProviderInterface
$app->abort(400, _('Could not perform request, please contact an administrator.')); $app->abort(400, _('Could not perform request, please contact an administrator.'));
} }
$user = $app['Core']->getAuthenticatedUser(); $user = $app['phraseanet.core']->getAuthenticatedUser();
try { try {
$auth = new \Session_Authentication_Native($appbox, $user->get_login(), $password); $auth = new \Session_Authentication_Native($appbox, $user->get_login(), $password);
@@ -420,7 +375,7 @@ class Account implements ControllerProviderInterface
} }
} }
return new Response($app['Core']['Twig']->render('account/reset-email.html.twig', array( return new Response($app['phraseanet.core']['Twig']->render('account/reset-email.html.twig', array(
'noticeMsg' => $noticeMsg, 'noticeMsg' => $noticeMsg,
'updateMsg' => $updateMsg, 'updateMsg' => $updateMsg,
))); )));
@@ -435,7 +390,7 @@ class Account implements ControllerProviderInterface
*/ */
public function renewPassword(Application $app, Request $request) public function renewPassword(Application $app, Request $request)
{ {
$appbox = \appbox::get_instance($app['Core']); $appbox = \appbox::get_instance($app['phraseanet.core']);
if ((null !== $password = $request->get('form_password')) && (null !== $passwordConfirm = $request->get('form_password_confirm'))) { if ((null !== $password = $request->get('form_password')) && (null !== $passwordConfirm = $request->get('form_password_confirm'))) {
if ($password !== $passwordConfirm) { if ($password !== $passwordConfirm) {
@@ -450,7 +405,7 @@ class Account implements ControllerProviderInterface
} }
try { try {
$user = $app['Core']->getAuthenticatedUser(); $user = $app['phraseanet.core']->getAuthenticatedUser();
$auth = new \Session_Authentication_Native($appbox, $user->get_login(), $request->get('form_old_password', '')); $auth = new \Session_Authentication_Native($appbox, $user->get_login(), $request->get('form_old_password', ''));
$auth->challenge_password(); $auth->challenge_password();
@@ -478,14 +433,14 @@ class Account implements ControllerProviderInterface
$app->abort(400, _('Bad request format, only JSON is allowed')); $app->abort(400, _('Bad request format, only JSON is allowed'));
} }
$appbox = \appbox::get_instance($app['Core']); $appbox = \appbox::get_instance($app['phraseanet.core']);
$error = false; $error = false;
try { try {
$account = \API_OAuth2_Account::load_with_user( $account = \API_OAuth2_Account::load_with_user(
$appbox $appbox
, new \API_OAuth2_Application($appbox, $application_id) , new \API_OAuth2_Application($appbox, $application_id)
, $app['Core']->getAuthenticatedUser() , $app['phraseanet.core']->getAuthenticatedUser()
); );
} catch (\Exception_NotFound $e) { } catch (\Exception_NotFound $e) {
$error = true; $error = true;
@@ -496,8 +451,6 @@ class Account implements ControllerProviderInterface
return new JsonResponse(array('success' => ! $error)); return new JsonResponse(array('success' => ! $error));
} }
/** /**
* Display account base access * Display account base access
* *
@@ -508,10 +461,10 @@ class Account implements ControllerProviderInterface
*/ */
public function accountAccess(Application $app, Request $request) public function accountAccess(Application $app, Request $request)
{ {
require_once $app['Core']['Registry']->get('GV_RootPath') . 'lib/classes/deprecated/inscript.api.php'; require_once $app['phraseanet.core']['Registry']->get('GV_RootPath') . 'lib/classes/deprecated/inscript.api.php';
return new Response($app['Core']['Twig']->render('account/access.html.twig', array( return new Response($app['phraseanet.core']['Twig']->render('account/access.html.twig', array(
'inscriptions' => giveMeBases($app['Core']->getAuthenticatedUser()->get_id()) 'inscriptions' => giveMeBases($app['phraseanet.core']->getAuthenticatedUser()->get_id())
))); )));
} }
@@ -525,9 +478,9 @@ class Account implements ControllerProviderInterface
*/ */
public function accountAuthorizedApps(Application $app, Request $request) public function accountAuthorizedApps(Application $app, Request $request)
{ {
return $app['Core']['Twig']->render('account/authorized_apps.html.twig', array( return $app['phraseanet.core']['Twig']->render('account/authorized_apps.html.twig', array(
"apps" => \API_OAuth2_Application::load_app_by_user(\appbox::get_instance($app['Core']), $user), "apps" => \API_OAuth2_Application::load_app_by_user(\appbox::get_instance($app['phraseanet.core']), $user),
'user' => $app['Core']->getAuthenticatedUser() 'user' => $app['phraseanet.core']->getAuthenticatedUser()
)); ));
} }

View File

@@ -220,8 +220,8 @@ class Developers implements ControllerProviderInterface
try { try {
$clientApp = new \API_OAuth2_Application($app['phraseanet.appbox'], $id); $clientApp = new \API_OAuth2_Application($app['phraseanet.appbox'], $id);
if ($callback = $request->get("callback")) { if (null !== $request->get("callback")) {
$clientApp->set_redirect_uri($callback); $clientApp->set_redirect_uri($request->get("callback"));
} else { } else {
$error = true; $error = true;
} }

View File

@@ -28,6 +28,15 @@ class Login implements ControllerProviderInterface
{ {
$controllers = $app['controllers_factory']; $controllers = $app['controllers_factory'];
$controllers->get('/', $this->call('login'))
->before(function() use ($app) {
return $app['phraseanet.core']['Firewall']->requireNotAuthenticated($app);
});
/** /**
* Logout * Logout
* *
@@ -136,7 +145,7 @@ class Login implements ControllerProviderInterface
*/ */
public function sendConfirmMail(Application $app, Request $request) public function sendConfirmMail(Application $app, Request $request)
{ {
$appbox = \appbox::get_instance($app['Core']); $appbox = $app['phraseanet.appbox'];
if (null === $usrId = $request->get('usr_id')) { if (null === $usrId = $request->get('usr_id')) {
$app->abort(400, sprintf(_('Request to send you the confirmation mail failed, please retry'))); $app->abort(400, sprintf(_('Request to send you the confirmation mail failed, please retry')));
@@ -163,7 +172,7 @@ class Login implements ControllerProviderInterface
*/ */
public function registerConfirm(Application $app, Request $request) public function registerConfirm(Application $app, Request $request)
{ {
$appbox = \appbox::get_instance($app['Core']); $appbox = $app['phraseanet.appbox'];
if (null === $code = $request->get('code')) { if (null === $code = $request->get('code')) {
return $app->redirect('/login/?redirect=/prod&error=code-not-found'); return $app->redirect('/login/?redirect=/prod&error=code-not-found');
@@ -224,7 +233,7 @@ class Login implements ControllerProviderInterface
*/ */
public function renewPassword(Application $app, Request $request) public function renewPassword(Application $app, Request $request)
{ {
$appbox = \appbox::get_instance($app['Core']); $appbox = $app['phraseanet.appbox'];
if (null !== $mail = trim($request->get('mail'))) { if (null !== $mail = trim($request->get('mail'))) {
if ( ! \PHPMailer::ValidateAddress($mail)) { if ( ! \PHPMailer::ValidateAddress($mail)) {
@@ -240,7 +249,7 @@ class Login implements ControllerProviderInterface
$token = \random::getUrlToken(\random::TYPE_PASSWORD, $user->get_id(), new \DateTime('+1 day')); $token = \random::getUrlToken(\random::TYPE_PASSWORD, $user->get_id(), new \DateTime('+1 day'));
if ($token) { if ($token) {
$url = sprintf('%slogin/forgot-password/?token=%s', $app['Core']['Registry']->get('GV_ServerName'), $token); $url = sprintf('%slogin/forgot-password/?token=%s', $app['phraseanet.core']['Registry']->get('GV_ServerName'), $token);
if (\mail::forgot_passord($mail, $user->get_login(), $url)) { if (\mail::forgot_passord($mail, $user->get_login(), $url)) {
return $app->redirect('/login/forgot-password/?sent=ok'); return $app->redirect('/login/forgot-password/?sent=ok');
@@ -345,7 +354,7 @@ class Login implements ControllerProviderInterface
} }
} }
return new Response($app['Core']['Twig']->render('login/forgot-password.html.twig', array( return new Response($app['phraseanet.core']['Twig']->render('login/forgot-password.html.twig', array(
'tokenize' => $tokenize, 'tokenize' => $tokenize,
'passwordMsg' => $passwordMsg, 'passwordMsg' => $passwordMsg,
'errorMsg' => $errorMsg, 'errorMsg' => $errorMsg,
@@ -362,7 +371,7 @@ class Login implements ControllerProviderInterface
*/ */
public function displayRegisterForm(Application $app, Request $request) public function displayRegisterForm(Application $app, Request $request)
{ {
return new Response($app['Core']['Twig']->render('login/register.html.twig')); return new Response($app['phraseanet.core']['Twig']->render('login/register.html.twig'));
} }
/** /**
@@ -376,19 +385,137 @@ class Login implements ControllerProviderInterface
{ {
$appRedirect = $request->get("app"); $appRedirect = $request->get("app");
try { // try {
$appbox = \appbox::get_instance($app['Core']); $session = $app['phraseanet.appbox']->get_session();
$session = $appbox->get_session();
$session->logout(); $session->logout();
$session->remove_cookies(); $session->remove_cookies();
} catch (\Exception $e) { // } catch (\Exception $e) {
return $app->redirect("/" . ($appRedirect ? $appRedirect : 'prod')); // return $app->redirect("/" . ($appRedirect ? $appRedirect : 'prod'));
} // }
return $app->redirect("/login/?logged_out=user" . ($appRedirect ? sprintf("&redirect=/%s", $appRedirect) : "")); return $app->redirect("/login/?logged_out=user" . ($appRedirect ? sprintf("&redirect=/%s", $appRedirect) : ""));
} }
public function login(Application $app, Request $request)
{
$appbox = $app['phraseanet.appbox'];
$session = $appbox->get_session();
$registry = $appbox->get_registry();
require_once($registry->get('GV_RootPath') . 'lib/classes/deprecated/inscript.api.php');
if ($registry->get('GV_captchas') && trim($registry->get('GV_captcha_private_key')) !== '' && trim($registry->get('GV_captcha_public_key')) !== '') {
include($registry->get('GV_RootPath') . 'lib/vendor/recaptcha/recaptchalib.php');
}
if ($request->get('postlog')) {
$session->set_postlog(true);
return $app->redirect("/login/index.php?redirect=" . $request->get('redirect'));
}
if ( ! $session->isset_postlog() && $session->is_authenticated() && $request->get('error') != 'no-connection') {
return $app->redirect($request->get('redirect', '/prod/'));
}
$noconn = false;
try {
$conn = $appbox->get_connection();
} catch (Exception $e) {
$noconn = true;
}
$client = \Browser::getInstance();
$warning = $notice = '';
$linkMailConfirm = false;
if (ctype_digit($request->get('usr'))) {
$linkMailConfirm = true;
$errorWarning .= '<div class="notice"><a href="/login/sendmail-confirm.php?usr_id=' . $request->get('usr') . '" target ="_self" style="color:black;text-decoration:none;">' . _('login:: Envoyer a nouveau le mail de confirmation') . '</a></div>';
}
switch (true) {
case $registry->get('GV_maintenance'):
case $request->get('error') === 'maintenance':
$warning = _('login::erreur: maintenance en cours, merci de nous excuser pour la gene occasionee');
break;
case $noconn:
case $request->get('error') === 'no-connection':
$warning = _('login::erreur: No available connection - Please contact sys-admin');
break;
case $request->get('error') === 'auth':
$warning = _('login::erreur: Erreur d\'authentification');
break;
case $request->get('error') === 'captcha':
$warning = _('login::erreur: Erreur de captcha');
break;
case $request->get('error') === 'mailNotConfirm' :
$warning = _('login::erreur: Vous n\'avez pas confirme votre email');
break;
case $request->get('error') === 'no-base' :
$warning = _('login::erreur: Aucune base n\'est actuellment accessible');
break;
}
switch ($request->get('notice')) {
case 'ok':
$notice = _('login::register: sujet email : confirmation de votre adresse email') . '</div>';
break;
case 'already':
$notice = _('login::notification: cette email est deja confirmee') . '</div>';
break;
case 'mail-sent':
$notice = _('login::notification: demande de confirmation par mail envoyee') . '</div>';
break;
case 'register-ok':
$notice = _('login::notification: votre email est desormais confirme') . '</div>';
break;
case 'register-ok-wait':
$notice = _('Your email is now confirmed. You will be informed as soon as your pending request will be managed');
break;
case 'password-update-ok':
$notice = _('login::notification: Mise a jour du mot de passe avec succes');
break;
}
$captchaSys = '';
if ( ! $registry->get('GV_maintenance')
&& $registry->get('GV_captchas')
&& trim($registry->get('GV_captcha_private_key')) !== ''
&& trim($registry->get('GV_captcha_public_key')) !== ''
&& $request->get('error') == 'captcha') {
$captchaSys = '<div style="margin:0;float: left;width:330px;"><div id="recaptcha_image" style="float: left;margin:10px 15px 5px"></div>
<div style="text-align:center;float: left;margin:0 15px 5px;width:300px;">
<a href="javascript:Recaptcha.reload()" class="link">' . _('login::captcha: obtenir une autre captcha') . '</a>
</div>
<div style="text-align:center;float: left;width:300px;margin:0 15px 0px;">
<span class="recaptcha_only_if_image">' . _('login::captcha: recopier les mots ci dessous') . ' : </span>
<input name="recaptcha_response_field" id="recaptcha_response_field" value="" type="text" style="width:180px;"/>
</div>' . recaptcha_get_html($registry->get('GV_captcha_public_key')) . '</div>';
}
$public_feeds = \Feed_Collection::load_public_feeds($appbox);
$feeds = array_merge(array($public_feeds->get_aggregate()), $public_feeds->get_feeds());
//$twig = new supertwig(array('Escaper' => false));
$core = \bootstrap::getCore();
$twig = $core->getTwig();
return $twig->render('login/index.twig', array(
'module_name' => _('Accueil'),
'notice' => $notice,
'warning' => $warning,
'redirect' => $request->get('redirect'),
'logged_out' => $request->get('logged_out'),
'captcha_system' => $captchaSys,
'login' => new \login(),
'feeds' => $feeds,
'display_layout' => $registry->get('GV_home_publi')
));
}
/** /**
* Prefix the method to call with the controller class name * Prefix the method to call with the controller class name
* *

View File

@@ -11,11 +11,12 @@
namespace Alchemy\Phrasea\Controller\Setup; namespace Alchemy\Phrasea\Controller\Setup;
use Symfony\Component\HttpFoundation\Request; use Alchemy\Phrasea\Core\Configuration;
use Symfony\Component\HttpFoundation\Response; use \Alchemy\Phrasea\Core\Service\Builder as ServiceBuilder;
use Doctrine\ORM\Tools\SchemaTool;
use Silex\Application; use Silex\Application;
use Silex\ControllerProviderInterface; use Silex\ControllerProviderInterface;
use Silex\ControllerCollection; use Symfony\Component\HttpFoundation\Request;
/** /**
* *
@@ -29,8 +30,7 @@ class Installer implements ControllerProviderInterface
{ {
$controllers = $app['controllers_factory']; $controllers = $app['controllers_factory'];
$controllers->get('/', function() use ($app) { $controllers->get('/', function(Application $app, Request $request) {
$request = $app['request'];
$php_constraint = \setup::check_php_version(); $php_constraint = \setup::check_php_version();
$writability_constraints = \setup::check_writability(new \Setup_Registry()); $writability_constraints = \setup::check_writability(new \Setup_Registry());
@@ -68,21 +68,19 @@ class Installer implements ControllerProviderInterface
$loader = new \Twig_Loader_Filesystem($ld_path); $loader = new \Twig_Loader_Filesystem($ld_path);
$twig = new \Twig_Environment($loader); $twig = new \Twig_Environment($loader);
$html = $twig->render( return $twig->render(
'/setup/index.html.twig' '/setup/index.html.twig'
, array_merge($constraints_coll, array( , array_merge($constraints_coll, array(
'locale' => \Session_Handler::get_locale() 'locale' => \Session_Handler::get_locale()
, 'available_locales' => $app['phraseanet.core']::getAvailableLanguages() , 'available_locales' => $app['phraseanet.core']::getAvailableLanguages()
, 'version_number' => $app['phraseanet.core']['Version']->getNumber() , 'version_number' => $app['phraseanet.core']['Version']->getNumber()
, 'version_name' => $app['phraseanet.core']['Version']->getName() , 'version_name' => $app['phraseanet.core']['Version']->getName()
, 'current_servername' => $request->getScheme() . '://' . $request->getHttpHost() . '/' , 'current_servername' => $request->getScheme() . '://' . $request->getHttpHost() . '/'
)) ))
); );
return new Response($html);
}); });
$controllers->get('/step2/', function() use ($app) { $controllers->get('/step2/', function(Application $app, Request $request) {
\phrasea::use_i18n(\Session_Handler::get_locale()); \phrasea::use_i18n(\Session_Handler::get_locale());
$ld_path = array(__DIR__ . '/../../../../../templates/web'); $ld_path = array(__DIR__ . '/../../../../../templates/web');
@@ -91,8 +89,6 @@ class Installer implements ControllerProviderInterface
$twig = new \Twig_Environment($loader); $twig = new \Twig_Environment($loader);
$twig->addExtension(new \Twig_Extensions_Extension_I18n()); $twig->addExtension(new \Twig_Extensions_Extension_I18n());
$request = $app['request'];
$warnings = array(); $warnings = array();
$php_constraint = \setup::check_php_version(); $php_constraint = \setup::check_php_version();
@@ -124,35 +120,29 @@ class Installer implements ControllerProviderInterface
$warnings[] = _('It is not recommended to install Phraseanet without HTTPS support'); $warnings[] = _('It is not recommended to install Phraseanet without HTTPS support');
} }
$html = $twig->render( return $twig->render(
'/setup/step2.html.twig' '/setup/step2.html.twig'
, array( , array(
'locale' => \Session_Handler::get_locale() 'locale' => \Session_Handler::get_locale()
, 'available_locales' => $app['phraseanet.core']::getAvailableLanguages() , 'available_locales' => $app['phraseanet.core']::getAvailableLanguages()
, 'available_templates' => \appbox::list_databox_templates() , 'available_templates' => \appbox::list_databox_templates()
, 'version_number' => $app['phraseanet.core']['Version']->getNumber() , 'version_number' => $app['phraseanet.core']['Version']->getNumber()
, 'version_name' => $app['phraseanet.core']['Version']->getName() , 'version_name' => $app['phraseanet.core']['Version']->getName()
, 'warnings' => $warnings , 'warnings' => $warnings
, 'error' => $request->get('error') , 'error' => $request->get('error')
, '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__)))) . '/'
) )
); );
return new Response($html);
}); });
$controllers->post('/install/', function() use ($app) { $controllers->post('/install/', function(Application $app, Request $request) {
set_time_limit(360); set_time_limit(360);
\phrasea::use_i18n(\Session_Handler::get_locale()); \phrasea::use_i18n(\Session_Handler::get_locale());
$request = $app['request'];
$servername = $request->getScheme() . '://' . $request->getHttpHost() . '/'; $servername = $request->getScheme() . '://' . $request->getHttpHost() . '/';
$setupRegistry = new \Setup_Registry();
$setupRegistry->set('GV_ServerName', $servername, \registry::TYPE_STRING);
$conn = $connbas = null; $conn = $connbas = null;
$hostname = $request->get('ab_hostname'); $hostname = $request->get('ab_hostname');
@@ -183,13 +173,13 @@ class Installer implements ControllerProviderInterface
$appbox = \appbox::create($app['phraseanet.core'], $setupRegistry, $conn, $appbox_name, true); $appbox = \appbox::create($app['phraseanet.core'], $setupRegistry, $conn, $appbox_name, true);
$configuration = \Alchemy\Phrasea\Core\Configuration::build(); $configuration = Configuration::build();
if ($configuration->isInstalled()) { if ($configuration->isInstalled()) {
$serviceName = $configuration->getOrm(); $serviceName = $configuration->getOrm();
$confService = $configuration->getService($serviceName); $confService = $configuration->getService($serviceName);
$ormService = \Alchemy\Phrasea\Core\Service\Builder::create( $ormService = ServiceBuilder::create(
$app['phraseanet.core'] $app['phraseanet.core']
, $confService , $confService
); );
@@ -203,7 +193,7 @@ class Installer implements ControllerProviderInterface
if ( ! empty($metadatas)) { if ( ! empty($metadatas)) {
// Create SchemaTool // Create SchemaTool
$tool = new \Doctrine\ORM\Tools\SchemaTool($em); $tool = new SchemaTool($em);
// Create schema // Create schema
$tool->dropSchema($metadatas); $tool->dropSchema($metadatas);
$tool->createSchema($metadatas); $tool->createSchema($metadatas);

View File

@@ -11,10 +11,8 @@
namespace Alchemy\Phrasea\Controller\Setup; namespace Alchemy\Phrasea\Controller\Setup;
use Symfony\Component\HttpFoundation\Response;
use Silex\Application; use Silex\Application;
use Silex\ControllerProviderInterface; use Silex\ControllerProviderInterface;
use Silex\ControllerCollection;
/** /**
* *
@@ -32,23 +30,17 @@ class Upgrader implements ControllerProviderInterface
require_once __DIR__ . '/../../../../bootstrap.php'; require_once __DIR__ . '/../../../../bootstrap.php';
$upgrade_status = \Setup_Upgrade::get_status(); $upgrade_status = \Setup_Upgrade::get_status();
/* @var $twig \Twig_Environment */ return $app['phraseanet.core']->getTwig()->render(
$twig = $app['phraseanet.core']->getTwig(); '/setup/upgrader.html.twig'
, array(
$html = $twig->render( 'locale' => \Session_Handler::get_locale()
'/setup/upgrader.html.twig' , 'upgrade_status' => $upgrade_status
, array( , 'available_locales' => $app['phraseanet.core']::getAvailableLanguages()
'locale' => \Session_Handler::get_locale() , 'bad_users' => \User_Adapter::get_wrong_email_users($app['phraseanet.appbox'])
, 'upgrade_status' => $upgrade_status , 'version_number' => $app['phraseanet.core']['Version']->getNumber()
, 'available_locales' => $app['phraseanet.core']::getAvailableLanguages() , 'version_name' => $app['phraseanet.core']['Version']->getName()
, 'bad_users' => \User_Adapter::get_wrong_email_users($app['phraseanet.appbox']) )
, 'version_number' => $app['phraseanet.core']['Version']->getNumber()
, 'version_name' => $app['phraseanet.core']['Version']->getName()
)
); );
ini_set('display_errors', 'on');
return new Response($html);
}); });
$controllers->get('/status/', function() use ($app) { $controllers->get('/status/', function() use ($app) {
@@ -56,13 +48,7 @@ class Upgrader implements ControllerProviderInterface
$datas = \Setup_Upgrade::get_status(); $datas = \Setup_Upgrade::get_status();
$Serializer = $app['phraseanet.core']['Serializer']; return $app->json($app['phraseanet.core']['Serializer']->serialize($datas, 'json'));
return new Response(
$Serializer->serialize($datas, 'json')
, 200
, array('Content-Type: application/json')
);
}); });
$controllers->post('/execute/', function() use ($app) { $controllers->post('/execute/', function() use ($app) {
@@ -78,8 +64,7 @@ class Upgrader implements ControllerProviderInterface
/** /**
* @todo Show recomandation instead of redirect * @todo Show recomandation instead of redirect
*/ */
return new $app->redirect('/');
return new \Symfony\Component\HttpFoundation\RedirectResponse('/');
}); });
return $controllers; return $controllers;

View File

@@ -11,11 +11,8 @@
namespace Alchemy\Phrasea\Controller\Utils; namespace Alchemy\Phrasea\Controller\Utils;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Silex\Application; use Silex\Application;
use Silex\ControllerProviderInterface; use Silex\ControllerProviderInterface;
use Silex\ControllerCollection;
/** /**
* *
@@ -29,7 +26,7 @@ class ConnectionTest implements ControllerProviderInterface
{ {
$controllers = $app['controllers_factory']; $controllers = $app['controllers_factory'];
$controllers->get('/mysql/', function() use ($app) { $controllers->get('/mysql/', function(Application $app) {
require_once __DIR__ . '/../../../../classes/connection/pdo.class.php'; require_once __DIR__ . '/../../../../classes/connection/pdo.class.php';
$request = $app['request']; $request = $app['request'];
@@ -75,8 +72,6 @@ class ConnectionTest implements ControllerProviderInterface
} }
} }
$Serializer = $app['phraseanet.core']['Serializer'];
$datas = array( $datas = array(
'connection' => $connection_ok 'connection' => $connection_ok
, 'database' => $db_ok , 'database' => $db_ok
@@ -85,14 +80,9 @@ class ConnectionTest implements ControllerProviderInterface
, 'is_databox' => $is_databox , 'is_databox' => $is_databox
); );
return new Response( return $app->json($app['phraseanet.core']['Serializer']->serialize($datas, 'json'));
$Serializer->serialize($datas, 'json')
, 200
, array('content-type' => 'application/json')
);
}); });
return $controllers; return $controllers;
} }
} }

View File

@@ -12,10 +12,8 @@
namespace Alchemy\Phrasea\Controller\Utils; namespace Alchemy\Phrasea\Controller\Utils;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Silex\Application; use Silex\Application;
use Silex\ControllerProviderInterface; use Silex\ControllerProviderInterface;
use Silex\ControllerCollection;
/** /**
* *
@@ -29,13 +27,11 @@ class PathFileTest implements ControllerProviderInterface
{ {
$controllers = $app['controllers_factory']; $controllers = $app['controllers_factory'];
$controllers->get('/path/', function() use ($app) { $controllers->get('/path/', function( Request $request) {
$path = $app['request']->get('path'); $path = $request->get('path');
$Serializer = $app['phraseanet.core']['Serializer']; return $app->json(
$app['phraseanet.core']['Serializer']->serialize(
return new Response(
$Serializer->serialize(
array( array(
'exists' => file_exists($path) 'exists' => file_exists($path)
, 'file' => is_file($path) , 'file' => is_file($path)
@@ -46,25 +42,17 @@ class PathFileTest implements ControllerProviderInterface
) )
, 'json' , 'json'
) )
, 200
, array('content-type' => 'application/json')
); );
}); });
$controllers->get('/url/', function() use ($app) { $controllers->get('/url/', function( Request $request) {
$url = $app['request']->get('url'); $url = $request->get('url');
$Serializer = $app['phraseanet.core']['Serializer']; return $app->json(
$app['phraseanet.core']['Serializer']->serialize(
return new Response( array('code' => \http_query::getHttpCodeFromUrl($url))
$Serializer->serialize(
array(
'code' => \http_query::getHttpCodeFromUrl($url)
)
, 'json' , 'json'
) )
, 200
, array('content-type' => 'application/json')
); );
}); });