Changeset View
Changeset View
Standalone View
Standalone View
src/applications/auth/controller/PhabricatorAuthUnlinkController.php
| Show All 26 Lines | public function handleRequest(AphrontRequest $request) { | ||||
| $provider_key = $this->providerKey; | $provider_key = $this->providerKey; | ||||
| $provider = PhabricatorAuthProvider::getEnabledProviderByKey($provider_key); | $provider = PhabricatorAuthProvider::getEnabledProviderByKey($provider_key); | ||||
| if ($provider) { | if ($provider) { | ||||
| if (!$provider->shouldAllowAccountUnlink()) { | if (!$provider->shouldAllowAccountUnlink()) { | ||||
| return $this->renderNotUnlinkableErrorDialog($provider); | return $this->renderNotUnlinkableErrorDialog($provider); | ||||
| } | } | ||||
| } | } | ||||
| // Check that this account isn't the last account which can be used to | $confirmations = $request->getStrList('confirmations'); | ||||
| // login. We prevent you from removing the last account. | $confirmations = array_fuse($confirmations); | ||||
| if (!$request->isFormPost() || !isset($confirmations['unlink'])) { | |||||
| return $this->renderConfirmDialog($confirmations); | |||||
| } | |||||
| // Check that this account isn't the only account which can be used to | |||||
| // login. We warn you when you remove your only login account. | |||||
| if ($account->isUsableForLogin()) { | if ($account->isUsableForLogin()) { | ||||
| $other_accounts = id(new PhabricatorExternalAccount())->loadAllWhere( | $other_accounts = id(new PhabricatorExternalAccount())->loadAllWhere( | ||||
| 'userPHID = %s', | 'userPHID = %s', | ||||
| $viewer->getPHID()); | $viewer->getPHID()); | ||||
| $valid_accounts = 0; | $valid_accounts = 0; | ||||
| foreach ($other_accounts as $other_account) { | foreach ($other_accounts as $other_account) { | ||||
| if ($other_account->isUsableForLogin()) { | if ($other_account->isUsableForLogin()) { | ||||
| $valid_accounts++; | $valid_accounts++; | ||||
| } | } | ||||
| } | } | ||||
| if ($valid_accounts < 2) { | if ($valid_accounts < 2) { | ||||
| return $this->renderLastUsableAccountErrorDialog(); | if (!isset($confirmations['only'])) { | ||||
| return $this->renderOnlyUsableAccountConfirmDialog($confirmations); | |||||
| } | |||||
| } | } | ||||
| } | } | ||||
| if ($request->isDialogFormPost()) { | |||||
| $account->delete(); | $account->delete(); | ||||
| id(new PhabricatorAuthSessionEngine())->terminateLoginSessions( | id(new PhabricatorAuthSessionEngine())->terminateLoginSessions( | ||||
| $viewer, | $viewer, | ||||
| new PhutilOpaqueEnvelope( | new PhutilOpaqueEnvelope( | ||||
| $request->getCookie(PhabricatorCookies::COOKIE_SESSION))); | $request->getCookie(PhabricatorCookies::COOKIE_SESSION))); | ||||
| return id(new AphrontRedirectResponse())->setURI($this->getDoneURI()); | return id(new AphrontRedirectResponse())->setURI($this->getDoneURI()); | ||||
| } | } | ||||
| return $this->renderConfirmDialog(); | |||||
| } | |||||
| private function getDoneURI() { | private function getDoneURI() { | ||||
| return '/settings/panel/external/'; | return '/settings/panel/external/'; | ||||
| } | } | ||||
| private function renderNoAccountErrorDialog() { | private function renderNoAccountErrorDialog() { | ||||
| $dialog = id(new AphrontDialogView()) | $dialog = id(new AphrontDialogView()) | ||||
| ->setUser($this->getRequest()->getUser()) | ->setUser($this->getRequest()->getUser()) | ||||
| ->setTitle(pht('No Such Account')) | ->setTitle(pht('No Such Account')) | ||||
| Show All 16 Lines | $dialog = id(new AphrontDialogView()) | ||||
| 'You can not unlink this account because the administrator has '. | 'You can not unlink this account because the administrator has '. | ||||
| 'configured Phabricator to make links to %s accounts permanent.', | 'configured Phabricator to make links to %s accounts permanent.', | ||||
| $provider->getProviderName())) | $provider->getProviderName())) | ||||
| ->addCancelButton($this->getDoneURI()); | ->addCancelButton($this->getDoneURI()); | ||||
| return id(new AphrontDialogResponse())->setDialog($dialog); | return id(new AphrontDialogResponse())->setDialog($dialog); | ||||
| } | } | ||||
| private function renderLastUsableAccountErrorDialog() { | private function renderOnlyUsableAccountConfirmDialog(array $confirmations) { | ||||
| $dialog = id(new AphrontDialogView()) | $confirmations[] = 'only'; | ||||
| ->setUser($this->getRequest()->getUser()) | |||||
| ->setTitle(pht('Last Valid Account')) | |||||
| ->appendChild( | |||||
| pht( | |||||
| 'You can not unlink this account because you have no other '. | |||||
| 'valid login accounts. If you removed it, you would be unable '. | |||||
| 'to log in. Add another authentication method before removing '. | |||||
| 'this one.')) | |||||
| ->addCancelButton($this->getDoneURI()); | |||||
| return id(new AphrontDialogResponse())->setDialog($dialog); | return $this->newDialog() | ||||
| ->setTitle(pht('Unlink Your Only Login Account?')) | |||||
| ->addHiddenInput('confirmations', implode(',', $confirmations)) | |||||
| ->appendParagraph( | |||||
| pht( | |||||
| 'This is the only external login account linked to your Phabicator '. | |||||
| 'account. If you remove it, you may no longer be able to log in.')) | |||||
| ->appendParagraph( | |||||
| pht( | |||||
| 'If you lose access to your account, you can recover access by '. | |||||
| 'sending yourself an email login link from the login screen.')) | |||||
| ->addCancelButton($this->getDoneURI()) | |||||
| ->addSubmitButton(pht('Unlink External Account')); | |||||
| } | } | ||||
| private function renderConfirmDialog() { | private function renderConfirmDialog(array $confirmations) { | ||||
| $confirmations[] = 'unlink'; | |||||
| $provider_key = $this->providerKey; | $provider_key = $this->providerKey; | ||||
| $provider = PhabricatorAuthProvider::getEnabledProviderByKey($provider_key); | $provider = PhabricatorAuthProvider::getEnabledProviderByKey($provider_key); | ||||
| if ($provider) { | if ($provider) { | ||||
| $title = pht('Unlink "%s" Account?', $provider->getProviderName()); | $title = pht('Unlink "%s" Account?', $provider->getProviderName()); | ||||
| $body = pht( | $body = pht( | ||||
| 'You will no longer be able to use your %s account to '. | 'You will no longer be able to use your %s account to '. | ||||
| 'log in to Phabricator.', | 'log in to Phabricator.', | ||||
| $provider->getProviderName()); | $provider->getProviderName()); | ||||
| } else { | } else { | ||||
| $title = pht('Unlink Account?'); | $title = pht('Unlink Account?'); | ||||
| $body = pht( | $body = pht( | ||||
| 'You will no longer be able to use this account to log in '. | 'You will no longer be able to use this account to log in '. | ||||
| 'to Phabricator.'); | 'to Phabricator.'); | ||||
| } | } | ||||
| $dialog = id(new AphrontDialogView()) | return $this->newDialog() | ||||
| ->setUser($this->getRequest()->getUser()) | |||||
| ->setTitle($title) | ->setTitle($title) | ||||
| ->addHiddenInput('confirmations', implode(',', $confirmations)) | |||||
| ->appendParagraph($body) | ->appendParagraph($body) | ||||
| ->appendParagraph( | ->appendParagraph( | ||||
| pht( | pht( | ||||
| 'Note: Unlinking an authentication provider will terminate any '. | 'Note: Unlinking an authentication provider will terminate any '. | ||||
| 'other active login sessions.')) | 'other active login sessions.')) | ||||
| ->addSubmitButton(pht('Unlink Account')) | ->addSubmitButton(pht('Unlink Account')) | ||||
| ->addCancelButton($this->getDoneURI()); | ->addCancelButton($this->getDoneURI()); | ||||
| return id(new AphrontDialogResponse())->setDialog($dialog); | |||||
| } | } | ||||
| } | } | ||||