From ced84470a976c166cc0ae9ee17030c70234ac47a Mon Sep 17 00:00:00 2001 From: vrana Date: Fri, 13 Apr 2012 22:29:32 -0700 Subject: [PATCH] Move invalid session error to login page Summary: With invalid session (which happens for me when I change production and dev db but can of course happen in other cases), Phabricator displays an ugly unhandled exception dialog suggesting to logging in again. But there's no login dialog on that page. This also changes how users with invalid session are treated on pages not requiring logging. Previously, an exception was thrown on them. Now they are treated as unlogged users. Test Plan: Corrupt session, go to /, login. Reviewers: epriestley Reviewed By: epriestley CC: aran Differential Revision: https://secure.phabricator.com/D2236 --- .../login/PhabricatorLoginController.php | 16 ++++++++++++++-- .../controller/base/PhabricatorController.php | 7 ------- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/src/applications/auth/controller/login/PhabricatorLoginController.php b/src/applications/auth/controller/login/PhabricatorLoginController.php index 95e4dbdb45..3a328f8fac 100644 --- a/src/applications/auth/controller/login/PhabricatorLoginController.php +++ b/src/applications/auth/controller/login/PhabricatorLoginController.php @@ -50,6 +50,20 @@ final class PhabricatorLoginController return id(new AphrontPlainTextResponse())->setContent($message); } + $error_view = null; + if ($request->getCookie('phusr') && $request->getCookie('phsid')) { + // The session cookie is invalid, so clear it. + $request->clearCookie('phusr'); + $request->clearCookie('phsid'); + + $error_view = new AphrontErrorView(); + $error_view->setTitle('Invalid Session'); + $error_view->setErrors(array( + "Your login session is invalid. Try logging in again. If that ". + "doesn't work, clear your browser cookies." + )); + } + $next_uri = $this->getRequest()->getPath(); if ($next_uri == '/login/') { $next_uri = '/'; @@ -140,8 +154,6 @@ final class PhabricatorLoginController $error_view = new AphrontErrorView(); $error_view->setTitle('Login Failed'); $error_view->setErrors($errors); - } else { - $error_view = null; } $form = new AphrontFormView(); diff --git a/src/applications/base/controller/base/PhabricatorController.php b/src/applications/base/controller/base/PhabricatorController.php index 27f08fa3f8..debece1bf8 100644 --- a/src/applications/base/controller/base/PhabricatorController.php +++ b/src/applications/base/controller/base/PhabricatorController.php @@ -50,13 +50,6 @@ abstract class PhabricatorController extends AphrontController { $phsid); if ($info) { $user->loadFromArray($info); - } else { - // The session cookie is invalid, so clear it. - $request->clearCookie('phusr'); - $request->clearCookie('phsid'); - throw new Exception( - "Your login session is invalid. Try logging in again. If that ". - "doesn't work, clear your browser cookies."); } }