diff --git a/lib/Alchemy/Phrasea/Application/Root.php b/lib/Alchemy/Phrasea/Application/Root.php index 88a89b201f..8169b598cb 100644 --- a/lib/Alchemy/Phrasea/Application/Root.php +++ b/lib/Alchemy/Phrasea/Application/Root.php @@ -57,7 +57,6 @@ return call_user_func(function() { $app->mount('/feeds/', new RSSFeeds()); $app->mount('/account/', new Account()); - $app->mount('/login/authenticate/', new AuthenticateController()); $app->mount('/login/', new Login()); $app->mount('/developers/', new Developers()); diff --git a/lib/Alchemy/Phrasea/Controller/Login/Authenticate.php b/lib/Alchemy/Phrasea/Controller/Login/Authenticate.php deleted file mode 100644 index af8cb7a7b8..0000000000 --- a/lib/Alchemy/Phrasea/Controller/Login/Authenticate.php +++ /dev/null @@ -1,113 +0,0 @@ -post('/', __CLASS__ . '::authenticate') - ->before(function() use ($app) { - return $app['phraseanet.core']['Firewall']->requireNotAuthenticated($app); - }); - - 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=mail-not-confirmed&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')); - } - - if ($app['browser']->isMobile()) { - return $app->redirect("/lightbox/"); - } elseif ($request->get('redirect')) { - return $app->redirect($request->get('redirect')); - } elseif (true !== $app['browser']->isNewGeneration()) { - return $app->redirect('/client/'); - } else { - return $app->redirect('/prod/'); - } - } else { - return $app->redirect("/login/"); - } - } -} diff --git a/lib/Alchemy/Phrasea/Controller/Root/Account.php b/lib/Alchemy/Phrasea/Controller/Root/Account.php index ded8cf54b8..dc280a89b1 100644 --- a/lib/Alchemy/Phrasea/Controller/Root/Account.php +++ b/lib/Alchemy/Phrasea/Controller/Root/Account.php @@ -13,7 +13,9 @@ namespace Alchemy\Phrasea\Controller\Root; use Silex\Application; use Silex\ControllerProviderInterface; +use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\HttpFoundation\Request; +use Symfony\Component\HttpFoundation\RedirectResponse; use Symfony\Component\HttpFoundation\Response; /** @@ -45,7 +47,8 @@ class Account implements ControllerProviderInterface * * return : HTML Response */ - $controllers->get('/', $this->call('displayAccount'))->bind('account'); + $controllers->get('/', $this->call('displayAccount')) + ->bind('account'); /** * Update account route @@ -152,22 +155,8 @@ class Account implements ControllerProviderInterface * * return : HTML Response */ - $controllers->get('/access/', $this->call('accountAccess'))->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'); + $controllers->get('/access/', $this->call('accountAccess')) + ->bind('account_access'); /** * Give authorized applications that can access user informations @@ -182,7 +171,8 @@ class Account implements ControllerProviderInterface * * return : HTML Response */ - $controllers->get('/reset-email/', $this->call('resetEmail'))->bind('reset_email'); + $controllers->post('/reset-email/', $this->call('resetEmail')) + ->bind('reset_email'); /** * Grant access to an authorized app @@ -197,7 +187,8 @@ class Account implements ControllerProviderInterface * * return : HTML Response */ - $controllers->get('/reset-password/', $this->call('resetPassword'))->bind('reset_password'); + $controllers->get('/reset-password/', $this->call('resetPassword')) + ->bind('reset_password'); /** * Give account open sessions @@ -251,11 +242,13 @@ class Account implements ControllerProviderInterface return $controllers; } - public function registerAccount(Application $app, Request $request) - { - return new Response($app['twig']->render('account/register.html.twig')); - } - + /** + * Reset Password + * + * @param Application $app + * @param Request $request + * @return Response + */ public function resetPassword(Application $app, Request $request) { if (null !== $passwordMsg = $request->get('pass-error')) { @@ -278,11 +271,11 @@ class Account implements ControllerProviderInterface } /** - * Reset email + * Reset Email * - * @param \Silex\Application $app - * @param \Symfony\Component\HttpFoundation\Request $request - * @return \Symfony\Component\HttpFoundation\JsonResponse + * @param Application $app + * @param Request $request + * @return RedirectResponse */ public function resetEmail(Application $app, Request $request) { @@ -339,9 +332,9 @@ class Account implements ControllerProviderInterface /** * Display reset email form * - * @param \Silex\Application $app - * @param \Symfony\Component\HttpFoundation\Request $request - * @return \Symfony\Component\HttpFoundation\JsonResponse + * @param Application $app + * @param Request $request + * @return Response */ public function displayResetEmailForm(Application $app, Request $request) { @@ -385,9 +378,9 @@ class Account implements ControllerProviderInterface /** * Submit the new password * - * @param Application $app A Silex application where the controller is mounted on - * @param Request $request The current request - * @return Response + * @param Application $app A Silex application where the controller is mounted on + * @param Request $request The current request + * @return RedirectResponse */ public function renewPassword(Application $app, Request $request) { @@ -423,10 +416,9 @@ class Account implements ControllerProviderInterface /** * Display authorized applications that can access user informations * - * @param Application $app A Silex application where the controller is mounted on - * @param Request $request The current request - * - * @return Response + * @param Application $app A Silex application where the controller is mounted on + * @param Request $request The current request + * @return JsonResponse */ public function grantAccess(Application $app, Request $request, $application_id) { @@ -443,22 +435,21 @@ class Account implements ControllerProviderInterface , new \API_OAuth2_Application($appbox, $application_id) , $app['phraseanet.core']->getAuthenticatedUser() ); + + $account->set_revoked((bool) $request->get('revoke'), false); } catch (\Exception_NotFound $e) { $error = true; } - $account->set_revoked((bool) $request->get('revoke'), false); - return $app->json(array('success' => ! $error)); } /** * Display account base access * - * @param Application $app A Silex application where the controller is mounted on - * @param Request $request The current request - * - * @return Response + * @param Application $app A Silex application where the controller is mounted on + * @param Request $request The current request + * @return Response */ public function accountAccess(Application $app, Request $request) { @@ -472,10 +463,9 @@ class Account implements ControllerProviderInterface /** * Display authorized applications that can access user informations * - * @param Application $app A Silex application where the controller is mounted on - * @param Request $request The current request - * - * @return Response + * @param Application $app A Silex application where the controller is mounted on + * @param Request $request The current request + * @return Response */ public function accountAuthorizedApps(Application $app, Request $request) { @@ -487,10 +477,9 @@ class Account implements ControllerProviderInterface /** * Display account session accesss * - * @param Application $app A Silex application where the controller is mounted on - * @param Request $request The current request - * - * @return Response + * @param Application $app A Silex application where the controller is mounted on + * @param Request $request The current request + * @return Response */ public function accountSessionsAccess(Application $app, Request $request) { @@ -500,10 +489,9 @@ class Account implements ControllerProviderInterface /** * Display account form * - * @param Application $app A Silex application where the controller is mounted on - * @param Request $request The current request - * - * @return Response + * @param Application $app A Silex application where the controller is mounted on + * @param Request $request The current request + * @return Response */ public function displayAccount(Application $app, Request $request) { @@ -543,7 +531,6 @@ class Account implements ControllerProviderInterface * * @param Application $app A Silex application where the controller is mounted on * @param Request $request The current request - * * @return Response */ public function updateAccount(Application $app, Request $request) @@ -555,7 +542,7 @@ class Account implements ControllerProviderInterface $demands = (array) $request->get('demand', array()); - if (0 === count($demands)) { + if (0 !== count($demands)) { $register = new \appbox_register($appbox); foreach ($demands as $baseId) { @@ -640,7 +627,7 @@ class Account implements ControllerProviderInterface foreach ($evtMngr->list_notifications_available($user->get_id()) as $notifications) { foreach ($notifications as $notification) { - $notifId = (int) $notification['id']; + $notifId = $notification['id']; $notifName = sprintf('notification_%d', $notifId); if (isset($requestedNotifications[$notifId])) { diff --git a/lib/Alchemy/Phrasea/Controller/Root/Developers.php b/lib/Alchemy/Phrasea/Controller/Root/Developers.php index 30be4a8ce0..f401005cee 100644 --- a/lib/Alchemy/Phrasea/Controller/Root/Developers.php +++ b/lib/Alchemy/Phrasea/Controller/Root/Developers.php @@ -13,7 +13,9 @@ namespace Alchemy\Phrasea\Controller\Root; use Silex\Application; use Silex\ControllerProviderInterface; +use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\HttpFoundation\Request; +use Symfony\Component\HttpFoundation\RedirectResponse; use Symfony\Component\HttpFoundation\Response; /** @@ -175,11 +177,10 @@ class Developers implements ControllerProviderInterface /** * Delete application * - * @param Application $app A Silex application where the controller is mounted on - * @param Request $request The current request - * @param integer $id The application id - * - * @return Response + * @param Application $app A Silex application where the controller is mounted on + * @param Request $request The current request + * @param integer $id The application id + * @return JsonResponse */ public function deleteApp(Application $app, Request $request, $id) { @@ -202,11 +203,10 @@ class Developers implements ControllerProviderInterface /** * Change application callback * - * @param Application $app A Silex application where the controller is mounted on - * @param Request $request The current request - * @param integer $id The application id - * - * @return Response + * @param Application $app A Silex application where the controller is mounted on + * @param Request $request The current request + * @param integer $id The application id + * @return JsonResponse */ public function renewAppCallback(Application $app, Request $request, $id) { @@ -234,11 +234,10 @@ class Developers implements ControllerProviderInterface /** * Authorize application to use a grant password type * - * @param Application $app A Silex application where the controller is mounted on - * @param Request $request The current request - * @param integer $id The application id - * - * @return Response + * @param Application $app A Silex application where the controller is mounted on + * @param Request $request The current request + * @param integer $id The application id + * @return JsonResponse */ public function renewAccessToken(Application $app, Request $request, $id) { @@ -273,11 +272,10 @@ class Developers implements ControllerProviderInterface /** * Authorize application to use a grant password type * - * @param Application $app A Silex application where the controller is mounted on - * @param Request $request The current request - * @param integer $id The application id - * - * @return Response + * @param Application $app A Silex application where the controller is mounted on + * @param Request $request The current request + * @param integer $id The application id + * @return JsonResponse */ public function authorizeGrantpassword(Application $app, Request $request, $id) { @@ -289,28 +287,24 @@ class Developers implements ControllerProviderInterface try { $clientApp = new \API_OAuth2_Application($app['phraseanet.appbox'], $id); + $clientApp->set_grant_password((bool) $request->get('grant', false)); } catch (\Exception_NotFound $e) { $error = true; } - $clientApp->set_grant_password((bool) $request->get('grant', false)); - return $app->json(array('success' => ! $error)); } /** * Create a new developer applications * - * @param Application $app A Silex application where the controller is mounted on - * @param Request $request The current request - * - * @return Response + * @param Application $app A Silex application where the controller is mounted on + * @param Request $request The current request + * @return Response */ public function newApp(Application $app, Request $request) { - $error = false; - - if ($request->get("type") == "desktop") { + if ($request->get('type') === \API_OAuth2_Application::DESKTOP_TYPE) { $form = new \API_OAuth2_Form_DevAppDesktop($app['request']); } else { $form = new \API_OAuth2_Form_DevAppInternet($app['request']); @@ -318,11 +312,7 @@ class Developers implements ControllerProviderInterface $violations = $app['validator']->validate($form); - if ($violations->count() == 0) { - $error = true; - } - - if ($error) { + if ($violations->count() === 0) { $application = \API_OAuth2_Application::create($app['phraseanet.appbox'], $app['phraseanet.core']->getAuthenticatedUser(), $form->getName()); $application ->set_description($form->getDescription()) @@ -338,16 +328,15 @@ class Developers implements ControllerProviderInterface "form" => $form ); - return $app['twig']->render('/developers/application.html.twig', $var); + return $app['twig']->render('/developers/application_form.html.twig', $var); } /** * List of apps created by the user * - * @param Application $app A Silex application where the controller is mounted on - * @param Request $request The current request - * - * @return Response + * @param Application $app A Silex application where the controller is mounted on + * @param Request $request The current request + * @return Response */ public function listApps(Application $app, Request $request) { @@ -360,10 +349,9 @@ class Developers implements ControllerProviderInterface /** * Display form application * - * @param Application $app A Silex application where the controller is mounted on - * @param Request $request The current request - * - * @return Response + * @param Application $app A Silex application where the controller is mounted on + * @param Request $request The current request + * @return Response */ public function displayFormApp(Application $app, Request $request) { @@ -377,11 +365,10 @@ class Developers implements ControllerProviderInterface /** * Get application information * - * @param Application $app A Silex application where the controller is mounted on - * @param Request $request The current request - * @param integer $id The application id - * - * @return Response + * @param Application $app A Silex application where the controller is mounted on + * @param Request $request The current request + * @param integer $id The application id + * @return Response */ public function getApp(Application $app, Request $request, $id) { diff --git a/lib/Alchemy/Phrasea/Controller/Root/Login.php b/lib/Alchemy/Phrasea/Controller/Root/Login.php index 58193893fc..b0624e5b5e 100644 --- a/lib/Alchemy/Phrasea/Controller/Root/Login.php +++ b/lib/Alchemy/Phrasea/Controller/Root/Login.php @@ -15,6 +15,7 @@ use Alchemy\Phrasea\Core; use Silex\Application; use Silex\ControllerProviderInterface; use Symfony\Component\HttpFoundation\Request; +use Symfony\Component\HttpFoundation\RedirectResponse; use Symfony\Component\HttpFoundation\Response; /** @@ -29,12 +30,62 @@ class Login implements ControllerProviderInterface { $controllers = $app['controllers_factory']; + /** + * Login + * + * name : homepage + * + * description : Login from phraseanet + * + * method : GET + * + * parameters : none + * + * return : HTML Response + */ $controllers->get('/', $this->call('login')) ->before(function() use ($app) { - return $app['phraseanet.core']['Firewall']->requireNotAuthenticated($app); + + if (null !== $app['request']->get('postlog')) { + + // if isset postlog parameter, set cookie and log out current user + // then post login operation like getting baskets from an invit session + // could be done by Session_handler authentication process + + $app['phraseanet.appbox']->get_session()->set_postlog(); + + return $app->redirect("/login/logout/?redirect=" . $app['request']->get('redirect', 'prod')); + } + + + if ($app['phraseanet.core']->isAuthenticated()) { + + return $app->redirect('/' . $app['request']->get('redirect', 'prod') . '/'); + } }) ->bind('homepage'); + /** + * Authenticate + * + * name : login_authenticate + * + * description : authenticate to phraseanet + * + * method : POST + * + * parameters : none + * + * return : HTML Response + */ + $controllers->post('/authenticate/', $this->call('authenticate')) + ->before(function() use ($app) { + if ($app['phraseanet.core']->isAuthenticated()) { + return $app->redirect('/prod/'); + } + }) + ->bind('login_authenticate'); + /** * Logout * @@ -153,9 +204,9 @@ class Login implements ControllerProviderInterface /** * Send a confirmation mail after register * - * @param \Silex\Application $app - * @param \Symfony\Component\HttpFoundation\Request $request - * @return \Symfony\Component\HttpFoundation\Response + * @param Application $app A Silex application where the controller is mounted on + * @param Request $request The current request + * @return RedirectResponse */ public function sendConfirmMail(Application $app, Request $request) { @@ -180,9 +231,9 @@ class Login implements ControllerProviderInterface /** * Validation of email adress * - * @param \Silex\Application $app - * @param \Symfony\Component\HttpFoundation\Request $request - * @return \Symfony\Component\HttpFoundation\Response + * @param Application $app A Silex application where the controller is mounted on + * @param Request $request The current request + * @return RedirectResponse */ public function registerConfirm(Application $app, Request $request) { @@ -208,7 +259,6 @@ class Login implements ControllerProviderInterface return $app->redirect('/login/?redirect=prod¬ice=already'); } - $user->set_mail_locked(false); \random::removeToken($code); if (\PHPMailer::ValidateAddress($user->get_email())) { @@ -242,15 +292,15 @@ class Login implements ControllerProviderInterface /** * Submit the new password * - * @param Application $app A Silex application where the controller is mounted on - * @param Request $request The current request - * @return Response + * @param Application $app A Silex application where the controller is mounted on + * @param Request $request The current request + * @return RedirectResponse */ public function renewPassword(Application $app, Request $request) { $appbox = $app['phraseanet.appbox']; - if (null !== $mail = trim($request->get('mail'))) { + if (null !== $mail = $request->get('mail')) { if ( ! \PHPMailer::ValidateAddress($mail)) { return $app->redirect('/login/forgot-password/?error=invalidmail'); } @@ -272,8 +322,6 @@ class Login implements ControllerProviderInterface return $app->redirect('/login/forgot-password/?error=mailserver'); } } - - return $app->redirect('/login/forgot-password/?error=noaccount'); } if ((null !== $token = $request->get('token')) @@ -301,7 +349,7 @@ class Login implements ControllerProviderInterface return $app->redirect('/login/?notice=password-update-ok'); } catch (\Exception_NotFound $e) { - + return $app->redirect('/login/forgot-password/?error=token'); } } } @@ -309,9 +357,9 @@ class Login implements ControllerProviderInterface /** * Get the fogot password form * - * @param Application $app A Silex application where the controller is mounted on - * @param Request $request The current request - * @return Response + * @param Application $app A Silex application where the controller is mounted on + * @param Request $request The current request + * @return Response */ public function displayForgotPasswordForm(Application $app, Request $request) { @@ -356,15 +404,15 @@ class Login implements ControllerProviderInterface } if (null !== $passwordMsg = $request->get('pass-error')) { - switch ($sentMsg) { + switch ($passwordMsg) { case 'pass-match': - $sentMsg = _('forms::les mots de passe ne correspondent pas'); + $passwordMsg = _('forms::les mots de passe ne correspondent pas'); break; case 'pass-short': - $sentMsg = _('forms::la valeur donnee est trop courte'); + $passwordMsg = _('forms::la valeur donnee est trop courte'); break; case 'pass-invalid': - $sentMsg = _('forms::la valeur donnee contient des caracteres invalides'); + $passwordMsg = _('forms::la valeur donnee contient des caracteres invalides'); break; } } @@ -380,9 +428,9 @@ class Login implements ControllerProviderInterface /** * Get the register form * - * @param \Silex\Application $app - * @param \Symfony\Component\HttpFoundation\Request $request - * @return \Symfony\Component\HttpFoundation\Response + * @param Application $app A Silex application where the controller is mounted on + * @param Request $request The current request + * @return Response */ public function displayRegisterForm(Application $app, Request $request) { @@ -440,9 +488,9 @@ class Login implements ControllerProviderInterface /** * Get the register form * - * @param \Silex\Application $app - * @param \Symfony\Component\HttpFoundation\Request $request - * @return \Symfony\Component\HttpFoundation\Response + * @param Application $app A Silex application where the controller is mounted on + * @param Request $request The current request + * @return RedirectResponse */ public function register(Application $app, Request $request) { @@ -472,7 +520,7 @@ class Login implements ControllerProviderInterface $needed['form_password'] = 'pass-invalid'; } - if (false !== \PHPMailer::ValidateAddress($email = $request->get('form_email'))) { + if (false === \PHPMailer::ValidateAddress($email = $request->get('form_email'))) { $needed['form_email'] = 'mail-invalid'; } @@ -498,7 +546,7 @@ class Login implements ControllerProviderInterface } if (sizeof($needed) > 0) { - $app->redirect(sprintf('/register/?%s', http_build_query(array('needed' => $needed)))); + return $app->redirect(sprintf('/register/?%s', http_build_query(array('needed' => $needed)))); } require_once($app['phraseanet.core']['Registry']->get('GV_RootPath') . 'lib/classes/deprecated/inscript.api.php'); @@ -599,9 +647,9 @@ class Login implements ControllerProviderInterface /** * Logout from Phraseanet * - * @param \Silex\Application $app - * @param \Symfony\Component\HttpFoundation\Request $request - * @return \Symfony\Component\HttpFoundation\Response + * @param Application $app A Silex application where the controller is mounted on + * @param Request $request The current request + * @return RedirectResponse */ public function logout(Application $app, Request $request) { @@ -619,27 +667,23 @@ class Login implements ControllerProviderInterface return $app->redirect("/login/?logged_out=user" . ($appRedirect ? sprintf("&redirect=/%s", $appRedirect) : "")); } + /** + * Login into Phraseanet + * + * @param Application $app A Silex application where the controller is mounted on + * @param Request $request The current request + * @return Response + */ public function login(Application $app, Request $request) { $appbox = $app['phraseanet.appbox']; - $session = $appbox->get_session(); - $registry = $appbox->get_registry(); + $registry = $app['phraseanet.core']['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/?redirect=" . $request->get('redirect')); - } - - if ( ! $session->isset_postlog() && $session->is_authenticated() && $request->get('error') != 'no-connection') { - return $app->redirect($request->get('redirect', '/prod/')); - } - $warning = $request->get('error', ''); try { @@ -737,6 +781,97 @@ class Login implements ControllerProviderInterface )); } + /** + * Authenticate to phraseanet + * + * @param Application $app A Silex application where the controller is mounted on + * @param Request $request The current request + * @return RedirectResponse + */ + public function authenticate(Application $app, Request $request) + { + $appbox = $app['phraseanet.appbox']; + $session = $appbox->get_session(); + $registry = $app['phraseanet.core']['Registry']; + + $is_guest = false; + + if (null !== $request->get('nolog') && \phrasea::guest_allowed()) { + $is_guest = true; + } + + if (((null !== $login = $request->get('login')) && (null !== $pwd = $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') + && '' !== $privateKey = trim($registry->get('GV_captcha_private_key')) + && trim($registry->get('GV_captcha_public_key')) !== '' + && null !== $challenge = $request->get("recaptcha_challenge_field") + && null !== $captachResponse = $request->get("recaptcha_response_field")) { + + include($registry->get('GV_RootPath') . 'lib/vendor/recaptcha/recaptchalib.php'); + + $checkCaptcha = recaptcha_check_answer($privateKey, $_SERVER["REMOTE_ADDR"], $challenge, $captachResponse); + + if ($checkCaptcha->is_valid) { + $captcha = true; + } + } + + $auth = new \Session_Authentication_Native($appbox, $login, $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=mail-not-confirmed&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 = '/account/forgot-password/?token=' . \random::getUrlToken(\random::TYPE_PASSWORD, $usr_id, $date) . '&salt=1'; + + return $app->redirect($url); + } catch (\Exception $e) { + return $app->redirect("/login/?redirect=" . $request->get('redirect') . "&error=" . _('An error occured')); + } + + if ($app['browser']->isMobile()) { + return $app->redirect("/lightbox/"); + } elseif ($request->get('redirect')) { + return $app->redirect($request->get('redirect')); + } elseif (true !== $app['browser']->isNewGeneration()) { + return $app->redirect('/client/'); + } else { + return $app->redirect('/prod/'); + } + } else { + return $app->redirect("/login/"); + } + } + /** * Prefix the method to call with the controller class name * @@ -751,7 +886,7 @@ class Login implements ControllerProviderInterface /** * Get required fields configuration * - * @param \Alchemy\Phrasea\Core $core + * @param Core $core * @return boolean */ private function getRegisterFieldConfiguration(Core $core) @@ -778,14 +913,13 @@ class Login implements ControllerProviderInterface "demand" => true ); - //on va chercher le fichier de configuration $registerFieldConfigurationFile = $core['Registry']->get('GV_RootPath') . 'config/register-fields.php'; if (is_file($registerFieldConfigurationFile)) { include $registerFieldConfigurationFile; } - //on force les champs vraiment obligatoires si le mec a fumé en faisant sa conf + //Override mandatory fields $arrayVerif['form_login'] = true; $arrayVerif['form_password'] = true; $arrayVerif['form_password_confirm'] = true; diff --git a/lib/Alchemy/Phrasea/Helper/User/Manage.php b/lib/Alchemy/Phrasea/Helper/User/Manage.php index 7d0d6f2a4c..2c2c4eac78 100644 --- a/lib/Alchemy/Phrasea/Helper/User/Manage.php +++ b/lib/Alchemy/Phrasea/Helper/User/Manage.php @@ -180,7 +180,7 @@ class Manage extends Helper $registry = \bootstrap::getCore()->getRegistry(); if (false !== $urlToken) { - $url = sprintf('%slogin/forgotpwd.php?token=%s', $registry->get('GV_ServerName'), $urlToken); + $url = sprintf('%slogin/forgot-password/?token=%s', $registry->get('GV_ServerName'), $urlToken); \mail::send_credentials($url, $createdUser->get_login(), $createdUser->get_email()); } } diff --git a/lib/Alchemy/Phrasea/Security/Firewall.php b/lib/Alchemy/Phrasea/Security/Firewall.php index e8d50592ce..f73c23641a 100644 --- a/lib/Alchemy/Phrasea/Security/Firewall.php +++ b/lib/Alchemy/Phrasea/Security/Firewall.php @@ -34,11 +34,4 @@ class Firewall return $app->redirect('/login/logout/'); } } - - public function requireNotAuthenticated(Application $app) - { - if ($app['phraseanet.core']->isAuthenticated()) { - return $app->redirect('/prod/'); - } - } } diff --git a/lib/classes/Exception/ServiceUnavalaible.class.php b/lib/classes/Exception/ServiceUnavailable.class.php similarity index 100% rename from lib/classes/Exception/ServiceUnavalaible.class.php rename to lib/classes/Exception/ServiceUnavailable.class.php diff --git a/lib/classes/eventsmanager/notify/autoregister.class.php b/lib/classes/eventsmanager/notify/autoregister.class.php index 3d21253308..fce6569b85 100644 --- a/lib/classes/eventsmanager/notify/autoregister.class.php +++ b/lib/classes/eventsmanager/notify/autoregister.class.php @@ -246,7 +246,7 @@ class eventsmanager_notify_autoregister extends eventsmanager_notifyAbstract $body .= "\n"; - $body .= "
\n
" + $body .= "
\n
" . _('admin::register: vous pourrez consulter son compte en ligne via l\'interface d\'administration') . "
\n"; diff --git a/lib/classes/eventsmanager/notify/register.class.php b/lib/classes/eventsmanager/notify/register.class.php index da648dd8aa..487bf896fe 100644 --- a/lib/classes/eventsmanager/notify/register.class.php +++ b/lib/classes/eventsmanager/notify/register.class.php @@ -250,7 +250,7 @@ class eventsmanager_notify_register extends eventsmanager_notifyAbstract $body .= "\n"; $body .= "
\n
" + . "login/?redirect=admin' target='_blank'>" . _('admin::register: vous pourrez traiter ses demandes en ligne via l\'interface d\'administration') . "
\n"; diff --git a/templates/web/account/access.html.twig b/templates/web/account/access.html.twig index d1471f0f4d..afa68d7610 100644 --- a/templates/web/account/access.html.twig +++ b/templates/web/account/access.html.twig @@ -18,7 +18,7 @@ {% if baseInsc['CollsRegistered'] is not none %} {% for base in baseInsc['CollsRegistered']%} {% for collId, isTrue in base %} - {{ base_id == sbasId |base_from_coll(collId) }} + {% set base_id = sbasId |base_from_coll(collId) %} {% trans 'login::register: acces authorise sur la collection ' %}{{ sbasId |sbas_names }} @@ -37,7 +37,7 @@ {% if baseInsc['CollsRefuse'] %} {% for collId, isTrue in baseInsc['CollsRefuse'] %} - {{ base_id == sbasId |base_from_coll(collId) }} + {% set base_id = sbasId |base_from_coll(collId) %} {% trans 'login::register: acces refuse sur la collection ' %}{{ sbasId |sbas_names }} @@ -55,7 +55,7 @@ {% if baseInsc['CollsWait'] %} {% for collId, isTrue in baseInsc['CollsWait'] %} - {{ base_id == sbasId |base_from_coll(collId) }} + {% set base_id = sbasId |base_from_coll(collId) %} {% trans 'login::register: en attente d\'acces sur' %} {{ sbasId |sbas_names }} @@ -70,7 +70,7 @@ {% if baseInsc['CollsIntime'] %} {% for collId, isTrue in baseInsc['CollsIntime'] %} - {{ base_id == sbasId |base_from_coll(collId) }} + {% set base_id = sbasId |base_from_coll(collId) %} {% trans 'login::register: acces temporaire sur' %} {{ sbasId |sbas_names }} @@ -85,7 +85,7 @@ {% if baseInsc['CollsOuttime'] %} {% for collId, isTrue in baseInsc['CollsOuttime'] %} - {{ base_id == sbasId |base_from_coll(collId) }} + {% set base_id = sbasId |base_from_coll(collId) %} {% trans 'login::register: acces temporaire termine sur ' %}{{ sbasId |sbas_names }} @@ -100,7 +100,7 @@ {% if baseInsc['CollsNonactif'] %} {% for collId, isTrue in baseInsc['CollsNonactif'] %} - {{ base_id == (sbasId |base_from_coll(collId)) }} + {% set base_id = sbasId |base_from_coll(collId) %} {% trans 'login::register: acces supendu sur' %} {{ sbasId |sbas_names }} @@ -114,7 +114,6 @@ {% endif %} {% if (baseInsc['CollsCGU'] or baseInsc['Colls']) and baseInsc['inscript'] %} - {{ noDemand == false }} {% if baseInsc['Colls'] %} {% if baseInsc['CGU'] %} @@ -125,7 +124,7 @@ {% endif %} {% for collId, collName in baseInsc['Colls'] %} - {{ base_id == sbasId |base_from_coll(collId) }} + {% set base_id = sbasId |base_from_coll(collId) %} {{ collName }} @@ -138,7 +137,7 @@ {% endif %} {% if baseInsc['CollsCGU'] %} {% for collId, collDesc in baseInsc['CollsCGU'] %} - {{ base_id == sbasId |base_from_coll(collId) }} + {% set base_id = sbasId |base_from_coll(collId) %}
diff --git a/templates/web/account/reset-email.html.twig b/templates/web/account/reset-email.html.twig index 3e6f348d4a..4428ebf7b4 100644 --- a/templates/web/account/reset-email.html.twig +++ b/templates/web/account/reset-email.html.twig @@ -48,8 +48,10 @@ $(document).ready(function() { {% block content %} {% if updateMsg is not none %} -
{{ updateMsg }}
- {% trans 'admin::compte-utilisateur retour a mon compte'%} +
+
{{ updateMsg }}
+ {% trans 'admin::compte-utilisateur retour a mon compte'%} +
{% else %} {% if noticeMsg is not none %} diff --git a/templates/web/account/reset-password.html.twig b/templates/web/account/reset-password.html.twig index 036fec84ed..0fadd145ec 100644 --- a/templates/web/account/reset-password.html.twig +++ b/templates/web/account/reset-password.html.twig @@ -56,7 +56,10 @@ {% block content %}
{% if passwordMsg is not none %} -

{{ passwordMsg }}

+
+ × + {{ passwordMsg }} +
{% endif %}
diff --git a/templates/web/developers/application_form.html.twig b/templates/web/developers/application_form.html.twig index ae62a9a555..f6b3db5fd3 100644 --- a/templates/web/developers/application_form.html.twig +++ b/templates/web/developers/application_form.html.twig @@ -95,7 +95,6 @@