diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index 1bc84b4569..50d884bcf2 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -1049,7 +1049,7 @@ phutil_register_library_map(array( 'PhabricatorEditor' => 'infrastructure/PhabricatorEditor.php', 'PhabricatorEmailLoginController' => 'applications/auth/controller/PhabricatorEmailLoginController.php', 'PhabricatorEmailTokenController' => 'applications/auth/controller/PhabricatorEmailTokenController.php', - 'PhabricatorEmailVerificationController' => 'applications/people/controller/PhabricatorEmailVerificationController.php', + 'PhabricatorEmailVerificationController' => 'applications/auth/controller/PhabricatorEmailVerificationController.php', 'PhabricatorEmptyQueryException' => 'infrastructure/query/PhabricatorEmptyQueryException.php', 'PhabricatorEnglishTranslation' => 'infrastructure/internationalization/PhabricatorEnglishTranslation.php', 'PhabricatorEnv' => 'infrastructure/env/PhabricatorEnv.php', @@ -3004,7 +3004,7 @@ phutil_register_library_map(array( 'PhabricatorEditor' => 'Phobject', 'PhabricatorEmailLoginController' => 'PhabricatorAuthController', 'PhabricatorEmailTokenController' => 'PhabricatorAuthController', - 'PhabricatorEmailVerificationController' => 'PhabricatorPeopleController', + 'PhabricatorEmailVerificationController' => 'PhabricatorAuthController', 'PhabricatorEmptyQueryException' => 'Exception', 'PhabricatorEnglishTranslation' => 'PhabricatorBaseEnglishTranslation', 'PhabricatorEnvTestCase' => 'PhabricatorTestCase', diff --git a/src/applications/auth/application/PhabricatorApplicationAuth.php b/src/applications/auth/application/PhabricatorApplicationAuth.php index b47da354a4..76c95323fd 100644 --- a/src/applications/auth/application/PhabricatorApplicationAuth.php +++ b/src/applications/auth/application/PhabricatorApplicationAuth.php @@ -83,6 +83,9 @@ final class PhabricatorApplicationAuth extends PhabricatorApplication { 'mustverify/' => 'PhabricatorMustVerifyEmailController', ), + '/emailverify/(?P[^/]+)/' => + 'PhabricatorEmailVerificationController', + '/logout/' => 'PhabricatorLogoutController', ); } diff --git a/src/applications/auth/controller/PhabricatorEmailVerificationController.php b/src/applications/auth/controller/PhabricatorEmailVerificationController.php new file mode 100644 index 0000000000..ac43cf7055 --- /dev/null +++ b/src/applications/auth/controller/PhabricatorEmailVerificationController.php @@ -0,0 +1,81 @@ +code = $data['code']; + } + + public function shouldRequireEmailVerification() { + // Since users need to be able to hit this endpoint in order to verify + // email, we can't ever require email verification here. + return false; + } + + public function processRequest() { + $request = $this->getRequest(); + $user = $request->getUser(); + + $email = id(new PhabricatorUserEmail())->loadOneWhere( + 'userPHID = %s AND verificationCode = %s', + $user->getPHID(), + $this->code); + + $color = PhabricatorActionHeaderView::HEADER_DARK_GREY; + + if (!$email) { + $title = pht('Unable to Verify Email'); + $content = pht( + 'The verification code you provided is incorrect, or the email '. + 'address has been removed, or the email address is owned by another '. + 'user. Make sure you followed the link in the email correctly and are '. + 'logged in with the user account associated with the email address.'); + $color = PhabricatorActionHeaderView::HEADER_RED; + $continue = pht('Rats!'); + } else if ($email->getIsVerified()) { + $title = pht('Address Already Verified'); + $content = pht( + 'This email address has already been verified.'); + $continue = pht('Continue to Phabricator'); + } else { + $guard = AphrontWriteGuard::beginScopedUnguardedWrites(); + $email->setIsVerified(1); + $email->save(); + unset($guard); + + $title = pht('Address Verified'); + $content = pht( + 'The email address %s is now verified.', + phutil_tag('strong', array(), $email->getAddress())); + $continue = pht('Continue to Phabricator'); + } + + $dialog = id(new AphrontDialogView()) + ->setUser($user) + ->setTitle($title) + ->setHeaderColor($color) + ->setMethod('GET') + ->addCancelButton('/', $continue) + ->appendChild($content); + + $crumbs = $this->buildApplicationCrumbs(); + $crumbs->addCrumb( + id(new PhabricatorCrumbView()) + ->setName(pht('Verify Email'))); + + return $this->buildApplicationPage( + array( + $crumbs, + $dialog, + ), + array( + 'title' => pht('Verify Email'), + 'device' => true, + 'dust' => true, + )); + } + +} diff --git a/src/applications/people/application/PhabricatorApplicationPeople.php b/src/applications/people/application/PhabricatorApplicationPeople.php index 560f75751d..cdbd347a11 100644 --- a/src/applications/people/application/PhabricatorApplicationPeople.php +++ b/src/applications/people/application/PhabricatorApplicationPeople.php @@ -51,8 +51,6 @@ final class PhabricatorApplicationPeople extends PhabricatorApplication { ), '/p/(?P[\w._-]+)/' => 'PhabricatorPeopleProfileController', - '/emailverify/(?P[^/]+)/' => - 'PhabricatorEmailVerificationController', ); } diff --git a/src/applications/people/controller/PhabricatorEmailVerificationController.php b/src/applications/people/controller/PhabricatorEmailVerificationController.php deleted file mode 100644 index ccc2fca281..0000000000 --- a/src/applications/people/controller/PhabricatorEmailVerificationController.php +++ /dev/null @@ -1,95 +0,0 @@ -code = $data['code']; - } - - public function shouldRequireAdmin() { - return false; - } - - public function shouldRequireEmailVerification() { - // Since users need to be able to hit this endpoint in order to verify - // email, we can't ever require email verification here. - return false; - } - - public function processRequest() { - $request = $this->getRequest(); - $user = $request->getUser(); - - $email = id(new PhabricatorUserEmail())->loadOneWhere( - 'userPHID = %s AND verificationCode = %s', - $user->getPHID(), - $this->code); - - $home_link = phutil_tag( - 'a', - array( - 'href' => '/', - ), - pht('Continue to Phabricator')); - $home_link = hsprintf( - '

%s

', - $home_link); - - $settings_link = phutil_tag( - 'a', - array( - 'href' => '/settings/panel/email/', - ), - pht('Return to Email Settings')); - $settings_link = hsprintf( - '

%s

', - $settings_link); - - if (!$email) { - $content = id(new AphrontErrorView()) - ->setTitle(pht('Unable To Verify')) - ->appendChild(phutil_tag( - 'p', - array(), - pht('The verification code is incorrect, the email address has been '. - 'removed, or the email address is owned by another user. Make '. - 'sure you followed the link in the email correctly.'))); - } else if ($email->getIsVerified()) { - $inst = pht('This email address has already been verified.'); - $content = id(new AphrontErrorView()) - ->setSeverity(AphrontErrorView::SEVERITY_NOTICE) - ->setTitle(pht('Address Already Verified')) - ->appendChild(hsprintf( - '

%s

%s', - $inst, - $settings_link)); - } else { - - $guard = AphrontWriteGuard::beginScopedUnguardedWrites(); - $email->setIsVerified(1); - $email->save(); - unset($guard); - - $inst = pht('This email address has now been verified. Thanks!'); - $content = id(new AphrontErrorView()) - ->setSeverity(AphrontErrorView::SEVERITY_NOTICE) - ->setTitle(pht('Address Verified')) - ->appendChild(hsprintf( - '

%s

%s%s', - $inst, - $home_link, - $settings_link)); - } - - return $this->buildApplicationPage( - $content, - array( - 'title' => pht('Verify Email'), - 'device' => true, - )); - } - -}