@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator

Update Auth for handleRequest

Summary: Updates Auth app for handleRequest

Test Plan: Tested what I could, Log in, Log out, Change Password, New account, Verify account... but extra eyes very helpful here.

Reviewers: epriestley

Reviewed By: epriestley

Subscribers: epriestley, Korvin

Maniphest Tasks: T8628

Differential Revision: https://secure.phabricator.com/D13748

+95 -159
+4 -10
src/applications/auth/controller/PhabricatorAuthConfirmLinkController.php
··· 3 3 final class PhabricatorAuthConfirmLinkController 4 4 extends PhabricatorAuthController { 5 5 6 - private $accountKey; 7 - 8 - public function willProcessRequest(array $data) { 9 - $this->accountKey = idx($data, 'akey'); 10 - } 11 - 12 - public function processRequest() { 13 - $request = $this->getRequest(); 14 - $viewer = $request->getUser(); 6 + public function handleRequest(AphrontRequest $request) { 7 + $viewer = $this->getViewer(); 8 + $accountkey = $request->getURIData('akey'); 15 9 16 - $result = $this->loadAccountForRegistrationOrLinking($this->accountKey); 10 + $result = $this->loadAccountForRegistrationOrLinking($accountkey); 17 11 list($account, $provider, $response) = $result; 18 12 19 13 if ($response) {
+2 -3
src/applications/auth/controller/PhabricatorAuthDowngradeSessionController.php
··· 3 3 final class PhabricatorAuthDowngradeSessionController 4 4 extends PhabricatorAuthController { 5 5 6 - public function processRequest() { 7 - $request = $this->getRequest(); 8 - $viewer = $request->getUser(); 6 + public function handleRequest(AphrontRequest $request) { 7 + $viewer = $this->getViewer(); 9 8 10 9 $panel_uri = '/settings/panel/sessions/'; 11 10
+2 -3
src/applications/auth/controller/PhabricatorAuthFinishController.php
··· 15 15 return true; 16 16 } 17 17 18 - public function processRequest() { 19 - $request = $this->getRequest(); 20 - $viewer = $request->getUser(); 18 + public function handleRequest(AphrontRequest $request) { 19 + $viewer = $this->getViewer(); 21 20 22 21 // If the user already has a full session, just kick them out of here. 23 22 $has_partial_session = $viewer->hasSession() &&
+9 -16
src/applications/auth/controller/PhabricatorAuthLinkController.php
··· 3 3 final class PhabricatorAuthLinkController 4 4 extends PhabricatorAuthController { 5 5 6 - private $action; 7 - private $providerKey; 8 - 9 - public function willProcessRequest(array $data) { 10 - $this->providerKey = $data['pkey']; 11 - $this->action = $data['action']; 12 - } 13 - 14 - public function processRequest() { 15 - $request = $this->getRequest(); 16 - $viewer = $request->getUser(); 6 + public function handleRequest(AphrontRequest $request) { 7 + $viewer = $this->getViewer(); 8 + $action = $request->getURIData('action'); 9 + $provider_key = $request->getURIData('pkey'); 17 10 18 11 $provider = PhabricatorAuthProvider::getEnabledProviderByKey( 19 - $this->providerKey); 12 + $provider_key); 20 13 if (!$provider) { 21 14 return new Aphront404Response(); 22 15 } 23 16 24 - switch ($this->action) { 17 + switch ($action) { 25 18 case 'link': 26 19 if (!$provider->shouldAllowAccountLink()) { 27 20 return $this->renderErrorPage( ··· 50 43 $provider->getProviderDomain(), 51 44 $viewer->getPHID()); 52 45 53 - switch ($this->action) { 46 + switch ($action) { 54 47 case 'link': 55 48 if ($account) { 56 49 return $this->renderErrorPage( ··· 81 74 82 75 PhabricatorCookies::setClientIDCookie($request); 83 76 84 - switch ($this->action) { 77 + switch ($action) { 85 78 case 'link': 86 79 id(new PhabricatorAuthSessionEngine())->requireHighSecuritySession( 87 80 $viewer, ··· 107 100 $form); 108 101 } 109 102 110 - switch ($this->action) { 103 + switch ($action) { 111 104 case 'link': 112 105 $name = pht('Link Account'); 113 106 $title = pht('Link %s Account', $provider->getProviderName());
+4 -8
src/applications/auth/controller/PhabricatorAuthLoginController.php
··· 20 20 return parent::shouldAllowRestrictedParameter($parameter_name); 21 21 } 22 22 23 - public function willProcessRequest(array $data) { 24 - $this->providerKey = $data['pkey']; 25 - $this->extraURIData = idx($data, 'extra'); 26 - } 27 - 28 23 public function getExtraURIData() { 29 24 return $this->extraURIData; 30 25 } 31 26 32 - public function processRequest() { 33 - $request = $this->getRequest(); 34 - $viewer = $request->getUser(); 27 + public function handleRequest(AphrontRequest $request) { 28 + $viewer = $this->getViewer(); 29 + $this->providerKey = $request->getURIData('pkey'); 30 + $this->extraURIData = $request->getURIData('extra'); 35 31 36 32 $response = $this->loadProvider(); 37 33 if ($response) {
+3 -4
src/applications/auth/controller/PhabricatorAuthNeedsApprovalController.php
··· 15 15 return false; 16 16 } 17 17 18 - public function processRequest() { 19 - $request = $this->getRequest(); 20 - $user = $request->getUser(); 18 + public function handleRequest(AphrontRequest $request) { 19 + $viewer = $this->getViewer(); 21 20 22 21 $wait_for_approval = pht( 23 22 "Your account has been created, but needs to be approved by an ". 24 23 "administrator. You'll receive an email once your account is approved."); 25 24 26 25 $dialog = id(new AphrontDialogView()) 27 - ->setUser($user) 26 + ->setUser($viewer) 28 27 ->setTitle(pht('Wait for Approval')) 29 28 ->appendChild($wait_for_approval) 30 29 ->addCancelButton('/', pht('Wait Patiently'));
+2 -3
src/applications/auth/controller/PhabricatorAuthNeedsMultiFactorController.php
··· 9 9 return false; 10 10 } 11 11 12 - public function processRequest() { 13 - $request = $this->getRequest(); 14 - $viewer = $request->getUser(); 12 + public function handleRequest(AphrontRequest $request) { 13 + $viewer = $this->getViewer(); 15 14 16 15 $panel = id(new PhabricatorMultiFactorSettingsPanel()) 17 16 ->setUser($viewer)
+5 -9
src/applications/auth/controller/PhabricatorAuthOldOAuthRedirectController.php
··· 3 3 final class PhabricatorAuthOldOAuthRedirectController 4 4 extends PhabricatorAuthController { 5 5 6 - private $provider; 7 - 8 6 public function shouldRequireLogin() { 9 7 return false; 10 8 } ··· 16 14 return parent::shouldAllowRestrictedParameter($parameter_name); 17 15 } 18 16 19 - public function willProcessRequest(array $data) { 20 - $this->provider = $data['provider']; 21 - } 22 - 23 - public function processRequest() { 17 + public function handleRequest(AphrontRequest $request) { 18 + $viewer = $this->getViewer(); 19 + $provider = $request->getURIData('provider'); 24 20 // TODO: Most OAuth providers are OK with changing the redirect URI, but 25 21 // Google and GitHub are strict. We need to respect the old OAuth URI until 26 22 // we can get installs to migrate. This just keeps the old OAuth URI working ··· 31 27 'github' => 'github:github.com', 32 28 ); 33 29 34 - if (!isset($provider_map[$this->provider])) { 30 + if (!isset($provider_map[$provider])) { 35 31 return new Aphront404Response(); 36 32 } 37 33 38 - $provider_key = $provider_map[$this->provider]; 34 + $provider_key = $provider_map[$provider]; 39 35 40 36 $uri = $this->getRequest()->getRequestURI(); 41 37 $uri->setPath($this->getApplicationURI('login/'.$provider_key.'/'));
+11 -19
src/applications/auth/controller/PhabricatorAuthOneTimeLoginController.php
··· 3 3 final class PhabricatorAuthOneTimeLoginController 4 4 extends PhabricatorAuthController { 5 5 6 - private $id; 7 - private $key; 8 - private $emailID; 9 - private $linkType; 10 - 11 6 public function shouldRequireLogin() { 12 7 return false; 13 8 } 14 9 15 - public function willProcessRequest(array $data) { 16 - $this->linkType = $data['type']; 17 - $this->id = $data['id']; 18 - $this->key = $data['key']; 19 - $this->emailID = idx($data, 'emailID'); 20 - } 21 - 22 - public function processRequest() { 23 - $request = $this->getRequest(); 10 + public function handleRequest(AphrontRequest $request) { 11 + $viewer = $this->getViewer(); 12 + $id = $request->getURIData('id'); 13 + $link_type = $request->getURIData('key'); 14 + $key = $request->getURIData('type'); 15 + $email_id = $request->getURIData('emailID'); 24 16 25 17 if ($request->getUser()->isLoggedIn()) { 26 18 return $this->renderError( ··· 29 21 30 22 $target_user = id(new PhabricatorPeopleQuery()) 31 23 ->setViewer(PhabricatorUser::getOmnipotentUser()) 32 - ->withIDs(array($this->id)) 24 + ->withIDs(array($id)) 33 25 ->executeOne(); 34 26 if (!$target_user) { 35 27 return new Aphront404Response(); ··· 58 50 // - get a "verified" address you don't control. 59 51 60 52 $target_email = null; 61 - if ($this->emailID) { 53 + if ($email_id) { 62 54 $target_email = id(new PhabricatorUserEmail())->loadOneWhere( 63 55 'userPHID = %s AND id = %d', 64 56 $target_user->getPHID(), 65 - $this->emailID); 57 + $email_id); 66 58 if (!$target_email) { 67 59 return new Aphront404Response(); 68 60 } ··· 72 64 $token = $engine->loadOneTimeLoginKey( 73 65 $target_user, 74 66 $target_email, 75 - $this->key); 67 + $key); 76 68 77 69 if (!$token) { 78 70 return $this->newDialog() ··· 154 146 // then log a user in to an account they control via sneaky invisible 155 147 // form submissions. 156 148 157 - switch ($this->linkType) { 149 + switch ($link_type) { 158 150 case PhabricatorAuthSessionEngine::ONETIME_WELCOME: 159 151 $title = pht('Welcome to Phabricator'); 160 152 break;
+5 -10
src/applications/auth/controller/PhabricatorAuthRegisterController.php
··· 3 3 final class PhabricatorAuthRegisterController 4 4 extends PhabricatorAuthController { 5 5 6 - private $accountKey; 7 - 8 6 public function shouldRequireLogin() { 9 7 return false; 10 8 } 11 9 12 - public function willProcessRequest(array $data) { 13 - $this->accountKey = idx($data, 'akey'); 14 - } 15 - 16 - public function processRequest() { 17 - $request = $this->getRequest(); 10 + public function handleRequest(AphrontRequest $request) { 11 + $viewer = $this->getViewer(); 12 + $account_key = $request->getURIData('akey'); 18 13 19 14 if ($request->getUser()->isLoggedIn()) { 20 15 return $this->renderError(pht('You are already logged in.')); 21 16 } 22 17 23 18 $is_setup = false; 24 - if (strlen($this->accountKey)) { 25 - $result = $this->loadAccountForRegistrationOrLinking($this->accountKey); 19 + if (strlen($account_key)) { 20 + $result = $this->loadAccountForRegistrationOrLinking($account_key); 26 21 list($account, $provider, $response) = $result; 27 22 $is_default = false; 28 23 } else if ($this->isFirstTimeSetup()) {
+5 -11
src/applications/auth/controller/PhabricatorAuthRevokeTokenController.php
··· 3 3 final class PhabricatorAuthRevokeTokenController 4 4 extends PhabricatorAuthController { 5 5 6 - private $id; 7 - 8 - public function willProcessRequest(array $data) { 9 - $this->id = $data['id']; 10 - } 11 - 12 - public function processRequest() { 13 - $request = $this->getRequest(); 14 - $viewer = $request->getUser(); 6 + public function handleRequest(AphrontRequest $request) { 7 + $viewer = $this->getViewer(); 8 + $id = $request->getURIData('id'); 15 9 16 - $is_all = ($this->id === 'all'); 10 + $is_all = ($id === 'all'); 17 11 18 12 $query = id(new PhabricatorAuthTemporaryTokenQuery()) 19 13 ->setViewer($viewer) 20 14 ->withObjectPHIDs(array($viewer->getPHID())); 21 15 if (!$is_all) { 22 - $query->withIDs(array($this->id)); 16 + $query->withIDs(array($id)); 23 17 } 24 18 25 19 $tokens = $query->execute();
+1 -1
src/applications/auth/controller/PhabricatorAuthSSHKeyEditController.php
··· 5 5 6 6 public function handleRequest(AphrontRequest $request) { 7 7 $viewer = $this->getViewer(); 8 - 9 8 $id = $request->getURIData('id'); 9 + 10 10 if ($id) { 11 11 $key = id(new PhabricatorAuthSSHKeyQuery()) 12 12 ->setViewer($viewer)
+5 -11
src/applications/auth/controller/PhabricatorAuthTerminateSessionController.php
··· 3 3 final class PhabricatorAuthTerminateSessionController 4 4 extends PhabricatorAuthController { 5 5 6 - private $id; 7 - 8 - public function willProcessRequest(array $data) { 9 - $this->id = $data['id']; 10 - } 11 - 12 - public function processRequest() { 13 - $request = $this->getRequest(); 14 - $viewer = $request->getUser(); 6 + public function handleRequest(AphrontRequest $request) { 7 + $viewer = $this->getViewer(); 8 + $id = $request->getURIData('id'); 15 9 16 - $is_all = ($this->id === 'all'); 10 + $is_all = ($id === 'all'); 17 11 18 12 $query = id(new PhabricatorAuthSessionQuery()) 19 13 ->setViewer($viewer) 20 14 ->withIdentityPHIDs(array($viewer->getPHID())); 21 15 if (!$is_all) { 22 - $query->withIDs(array($this->id)); 16 + $query->withIDs(array($id)); 23 17 } 24 18 25 19 $current_key = PhabricatorHash::digest(
+3 -7
src/applications/auth/controller/PhabricatorAuthUnlinkController.php
··· 5 5 6 6 private $providerKey; 7 7 8 - public function willProcessRequest(array $data) { 9 - $this->providerKey = $data['pkey']; 10 - } 11 - 12 - public function processRequest() { 13 - $request = $this->getRequest(); 14 - $viewer = $request->getUser(); 8 + public function handleRequest(AphrontRequest $request) { 9 + $viewer = $this->getViewer(); 10 + $this->providerKey = $request->getURIData('pkey'); 15 11 16 12 list($type, $domain) = explode(':', $this->providerKey, 2); 17 13
+2 -3
src/applications/auth/controller/PhabricatorAuthValidateController.php
··· 15 15 return true; 16 16 } 17 17 18 - public function processRequest() { 19 - $request = $this->getRequest(); 20 - $viewer = $request->getUser(); 18 + public function handleRequest(AphrontRequest $request) { 19 + $viewer = $this->getViewer(); 21 20 22 21 $failures = array(); 23 22
+6 -5
src/applications/auth/controller/PhabricatorDisabledUserController.php
··· 7 7 return false; 8 8 } 9 9 10 - public function processRequest() { 11 - $request = $this->getRequest(); 12 - $user = $request->getUser(); 13 - if (!$user->getIsDisabled()) { 10 + public function handleRequest(AphrontRequest $request) { 11 + $viewer = $this->getViewer(); 12 + $id = $request->getURIData('id'); 13 + 14 + if (!$viewer->getIsDisabled()) { 14 15 return new Aphront404Response(); 15 16 } 16 17 17 18 return id(new AphrontDialogView()) 18 - ->setUser($user) 19 + ->setUser($viewer) 19 20 ->setTitle(pht('Account Disabled')) 20 21 ->addCancelButton('/logout/', pht('Okay')) 21 22 ->appendParagraph(pht('Your account has been disabled.'));
+1 -2
src/applications/auth/controller/PhabricatorEmailLoginController.php
··· 7 7 return false; 8 8 } 9 9 10 - public function processRequest() { 11 - $request = $this->getRequest(); 10 + public function handleRequest(AphrontRequest $request) { 12 11 13 12 if (!PhabricatorPasswordAuthProvider::getPasswordProvider()) { 14 13 return new Aphront400Response();
+10 -16
src/applications/auth/controller/PhabricatorEmailVerificationController.php
··· 3 3 final class PhabricatorEmailVerificationController 4 4 extends PhabricatorAuthController { 5 5 6 - private $code; 7 - 8 - public function willProcessRequest(array $data) { 9 - $this->code = $data['code']; 10 - } 11 - 12 6 public function shouldRequireEmailVerification() { 13 7 // Since users need to be able to hit this endpoint in order to verify 14 8 // email, we can't ever require email verification here. ··· 21 15 return false; 22 16 } 23 17 24 - public function processRequest() { 25 - $request = $this->getRequest(); 26 - $user = $request->getUser(); 18 + public function handleRequest(AphrontRequest $request) { 19 + $viewer = $this->getViewer(); 20 + $code = $request->getURIData('code'); 27 21 28 - if ($user->getIsDisabled()) { 22 + if ($viewer->getIsDisabled()) { 29 23 // We allowed unapproved and disabled users to hit this controller, but 30 24 // want to kick out disabled users now. 31 25 return new Aphront400Response(); ··· 33 27 34 28 $email = id(new PhabricatorUserEmail())->loadOneWhere( 35 29 'userPHID = %s AND verificationCode = %s', 36 - $user->getPHID(), 37 - $this->code); 30 + $viewer->getPHID(), 31 + $code); 38 32 39 33 $submit = null; 40 34 ··· 46 40 'user. Make sure you followed the link in the email correctly and are '. 47 41 'logged in with the user account associated with the email address.'); 48 42 $continue = pht('Rats!'); 49 - } else if ($email->getIsVerified() && $user->getIsEmailVerified()) { 43 + } else if ($email->getIsVerified() && $viewer->getIsEmailVerified()) { 50 44 $title = pht('Address Already Verified'); 51 45 $content = pht( 52 46 'This email address has already been verified.'); ··· 54 48 } else if ($request->isFormPost()) { 55 49 56 50 id(new PhabricatorUserEditor()) 57 - ->setActor($user) 58 - ->verifyEmail($user, $email); 51 + ->setActor($viewer) 52 + ->verifyEmail($viewer, $email); 59 53 60 54 $title = pht('Address Verified'); 61 55 $content = pht( ··· 72 66 } 73 67 74 68 $dialog = id(new AphrontDialogView()) 75 - ->setUser($user) 69 + ->setUser($viewer) 76 70 ->setTitle($title) 77 71 ->addCancelButton('/', $continue) 78 72 ->appendChild($content);
+6 -7
src/applications/auth/controller/PhabricatorLogoutController.php
··· 26 26 } 27 27 28 28 public function handleRequest(AphrontRequest $request) { 29 - $request = $this->getRequest(); 30 - $user = $request->getUser(); 29 + $viewer = $this->getViewer(); 31 30 32 31 if ($request->isFormPost()) { 33 32 34 33 $log = PhabricatorUserLog::initializeNewLog( 35 - $user, 36 - $user->getPHID(), 34 + $viewer, 35 + $viewer->getPHID(), 37 36 PhabricatorUserLog::ACTION_LOGOUT); 38 37 $log->save(); 39 38 ··· 43 42 $phsid = $request->getCookie(PhabricatorCookies::COOKIE_SESSION); 44 43 if (strlen($phsid)) { 45 44 $session = id(new PhabricatorAuthSessionQuery()) 46 - ->setViewer($user) 45 + ->setViewer($viewer) 47 46 ->withSessionKeys(array($phsid)) 48 47 ->executeOne(); 49 48 if ($session) { ··· 56 55 ->setURI('/auth/loggedout/'); 57 56 } 58 57 59 - if ($user->getPHID()) { 58 + if ($viewer->getPHID()) { 60 59 $dialog = id(new AphrontDialogView()) 61 - ->setUser($user) 60 + ->setUser($viewer) 62 61 ->setTitle(pht('Log out of Phabricator?')) 63 62 ->appendChild(pht('Are you sure you want to log out?')) 64 63 ->addSubmitButton(pht('Logout'))
+6 -7
src/applications/auth/controller/PhabricatorMustVerifyEmailController.php
··· 13 13 return false; 14 14 } 15 15 16 - public function processRequest() { 17 - $request = $this->getRequest(); 18 - $user = $request->getUser(); 16 + public function handleRequest(AphrontRequest $request) { 17 + $viewer = $this->getViewer(); 19 18 20 - $email = $user->loadPrimaryEmail(); 19 + $email = $viewer->loadPrimaryEmail(); 21 20 22 - if ($user->getIsEmailVerified()) { 21 + if ($viewer->getIsEmailVerified()) { 23 22 return id(new AphrontRedirectResponse())->setURI('/'); 24 23 } 25 24 ··· 27 26 28 27 $sent = null; 29 28 if ($request->isFormPost()) { 30 - $email->sendVerificationEmail($user); 29 + $email->sendVerificationEmail($viewer); 31 30 $sent = new PHUIInfoView(); 32 31 $sent->setSeverity(PHUIInfoView::SEVERITY_NOTICE); 33 32 $sent->setTitle(pht('Email Sent')); ··· 48 47 'to try sending another one.'); 49 48 50 49 $dialog = id(new AphrontDialogView()) 51 - ->setUser($user) 50 + ->setUser($viewer) 52 51 ->setTitle(pht('Check Your Email')) 53 52 ->appendParagraph($must_verify) 54 53 ->appendParagraph($send_again)
+3 -4
src/applications/auth/controller/PhabricatorRefreshCSRFController.php
··· 2 2 3 3 final class PhabricatorRefreshCSRFController extends PhabricatorAuthController { 4 4 5 - public function processRequest() { 6 - $request = $this->getRequest(); 7 - $user = $request->getUser(); 5 + public function handleRequest(AphrontRequest $request) { 6 + $viewer = $this->getViewer(); 8 7 9 8 return id(new AphrontAjaxResponse()) 10 9 ->setContent( 11 10 array( 12 - 'token' => $user->getCSRFToken(), 11 + 'token' => $viewer->getCSRFToken(), 13 12 )); 14 13 } 15 14