@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
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Reduce the amount of OAuth1/OAuth2 code duplication for rendering login buttons

Summary: Ref T3687. These buttons don't work quite the same way, but are similar enough that the code seems worth consolidating.

Test Plan: Viewed and clicked both OAuth1 (Twitter, JIRA) and OAuth2 (Facebook) login buttons. Got logins.

Reviewers: btrahan

Reviewed By: btrahan

CC: aran

Maniphest Tasks: T3687

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

+87 -93
+76
src/applications/auth/provider/PhabricatorAuthProvider.php
··· 360 360 return false; 361 361 } 362 362 363 + 364 + /** 365 + * Render a standard login/register button element. 366 + * 367 + * The `$attributes` parameter takes these keys: 368 + * 369 + * - `uri`: URI the button should take the user to when clicked. 370 + * - `method`: Optional HTTP method the button should use, defaults to GET. 371 + * 372 + * @param AphrontRequest HTTP request. 373 + * @param string Request mode string. 374 + * @param map Additional parameters, see above. 375 + * @return wild Login button. 376 + */ 377 + protected function renderStandardLoginButton( 378 + AphrontRequest $request, 379 + $mode, 380 + array $attributes = array()) { 381 + 382 + PhutilTypeSpec::checkMap( 383 + $attributes, 384 + array( 385 + 'method' => 'optional string', 386 + 'uri' => 'string', 387 + )); 388 + 389 + $viewer = $request->getUser(); 390 + $adapter = $this->getAdapter(); 391 + 392 + if ($mode == 'link') { 393 + $button_text = pht('Link External Account'); 394 + } else if ($mode == 'refresh') { 395 + $button_text = pht('Refresh Account Link'); 396 + } else if ($this->shouldAllowRegistration()) { 397 + $button_text = pht('Login or Register'); 398 + } else { 399 + $button_text = pht('Login'); 400 + } 401 + 402 + $icon = id(new PHUIIconView()) 403 + ->setSpriteSheet(PHUIIconView::SPRITE_LOGIN) 404 + ->setSpriteIcon($this->getLoginIcon()); 405 + 406 + $button = id(new PHUIButtonView()) 407 + ->setSize(PHUIButtonView::BIG) 408 + ->setColor(PHUIButtonView::GREY) 409 + ->setIcon($icon) 410 + ->setText($button_text) 411 + ->setSubtext($this->getProviderName()); 412 + 413 + $uri = $attributes['uri']; 414 + $uri = new PhutilURI($uri); 415 + $params = $uri->getQueryParams(); 416 + $uri->setQueryParams(array()); 417 + 418 + $content = array($button); 419 + 420 + foreach ($params as $key => $value) { 421 + $content[] = phutil_tag( 422 + 'input', 423 + array( 424 + 'type' => 'hidden', 425 + 'name' => $key, 426 + 'value' => $value, 427 + )); 428 + } 429 + 430 + return phabricator_form( 431 + $viewer, 432 + array( 433 + 'method' => idx($attributes, 'method', 'GET'), 434 + 'action' => (string)$uri, 435 + ), 436 + $content); 437 + } 438 + 363 439 }
+6 -45
src/applications/auth/provider/PhabricatorAuthProviderOAuth.php
··· 34 34 } 35 35 36 36 protected function renderLoginForm(AphrontRequest $request, $mode) { 37 - $viewer = $request->getUser(); 38 - 39 - if ($mode == 'link') { 40 - $button_text = pht('Link External Account'); 41 - } else if ($mode == 'refresh') { 42 - $button_text = pht('Refresh Account Link'); 43 - } else if ($this->shouldAllowRegistration()) { 44 - $button_text = pht('Login or Register'); 45 - } else { 46 - $button_text = pht('Login'); 47 - } 48 - 49 - $icon = id(new PHUIIconView()) 50 - ->setSpriteSheet(PHUIIconView::SPRITE_LOGIN) 51 - ->setSpriteIcon($this->getLoginIcon()); 52 - 53 - $button = id(new PHUIButtonView()) 54 - ->setSize(PHUIButtonView::BIG) 55 - ->setColor(PHUIButtonView::GREY) 56 - ->setIcon($icon) 57 - ->setText($button_text) 58 - ->setSubtext($this->getProviderName()); 59 - 60 37 $adapter = $this->getAdapter(); 61 38 $adapter->setState(PhabricatorHash::digest($request->getCookie('phcid'))); 62 39 63 - $uri = new PhutilURI($adapter->getAuthenticateURI()); 64 - $params = $uri->getQueryParams(); 65 - $uri->setQueryParams(array()); 40 + $attributes = array( 41 + 'method' => 'GET', 42 + 'uri' => $adapter->getAuthenticateURI(), 43 + ); 66 44 67 - $content = array($button); 45 + return $this->renderStandardLoginButton($request, $mode, $attributes); 46 + } 68 47 69 - foreach ($params as $key => $value) { 70 - $content[] = phutil_tag( 71 - 'input', 72 - array( 73 - 'type' => 'hidden', 74 - 'name' => $key, 75 - 'value' => $value, 76 - )); 77 - } 78 - 79 - return phabricator_form( 80 - $viewer, 81 - array( 82 - 'method' => 'GET', 83 - 'action' => (string)$uri, 84 - ), 85 - $content); 86 - } 87 48 public function processLoginRequest( 88 49 PhabricatorAuthLoginController $controller) { 89 50
+5 -48
src/applications/auth/provider/PhabricatorAuthProviderOAuth1.php
··· 39 39 } 40 40 41 41 protected function renderLoginForm(AphrontRequest $request, $mode) { 42 - $viewer = $request->getUser(); 43 - 44 - if ($mode == 'link') { 45 - $button_text = pht('Link External Account'); 46 - } else if ($mode == 'refresh') { 47 - $button_text = pht('Refresh Account Link'); 48 - } else if ($this->shouldAllowRegistration()) { 49 - $button_text = pht('Login or Register'); 50 - } else { 51 - $button_text = pht('Login'); 52 - } 53 - 54 - $icon = id(new PHUIIconView()) 55 - ->setSpriteSheet(PHUIIconView::SPRITE_LOGIN) 56 - ->setSpriteIcon($this->getLoginIcon()); 57 - 58 - $button = id(new PHUIButtonView()) 59 - ->setSize(PHUIButtonView::BIG) 60 - ->setColor(PHUIButtonView::GREY) 61 - ->setIcon($icon) 62 - ->setText($button_text) 63 - ->setSubtext($this->getProviderName()); 64 - 65 - $adapter = $this->getAdapter(); 66 - 67 - $uri = new PhutilURI($this->getLoginURI()); 68 - $params = $uri->getQueryParams(); 69 - $uri->setQueryParams(array()); 70 - 71 - $content = array($button); 72 - 73 - foreach ($params as $key => $value) { 74 - $content[] = phutil_tag( 75 - 'input', 76 - array( 77 - 'type' => 'hidden', 78 - 'name' => $key, 79 - 'value' => $value, 80 - )); 81 - } 82 - 83 - return phabricator_form( 84 - $viewer, 85 - array( 86 - 'method' => 'POST', 87 - 'action' => (string)$uri, 88 - ), 89 - $content); 42 + $attributes = array( 43 + 'method' => 'POST', 44 + 'uri' => $this->getLoginURI(), 45 + ); 46 + return $this->renderStandardLoginButton($request, $mode, $attributes); 90 47 } 91 48 92 49 public function processLoginRequest(