diff --git a/src/applications/auth/provider/PhabricatorAuthProvider.php b/src/applications/auth/provider/PhabricatorAuthProvider.php index b02594f068..32fb052b4b 100644 --- a/src/applications/auth/provider/PhabricatorAuthProvider.php +++ b/src/applications/auth/provider/PhabricatorAuthProvider.php @@ -360,4 +360,80 @@ abstract class PhabricatorAuthProvider { return false; } + + /** + * Render a standard login/register button element. + * + * The `$attributes` parameter takes these keys: + * + * - `uri`: URI the button should take the user to when clicked. + * - `method`: Optional HTTP method the button should use, defaults to GET. + * + * @param AphrontRequest HTTP request. + * @param string Request mode string. + * @param map Additional parameters, see above. + * @return wild Login button. + */ + protected function renderStandardLoginButton( + AphrontRequest $request, + $mode, + array $attributes = array()) { + + PhutilTypeSpec::checkMap( + $attributes, + array( + 'method' => 'optional string', + 'uri' => 'string', + )); + + $viewer = $request->getUser(); + $adapter = $this->getAdapter(); + + if ($mode == 'link') { + $button_text = pht('Link External Account'); + } else if ($mode == 'refresh') { + $button_text = pht('Refresh Account Link'); + } else if ($this->shouldAllowRegistration()) { + $button_text = pht('Login or Register'); + } else { + $button_text = pht('Login'); + } + + $icon = id(new PHUIIconView()) + ->setSpriteSheet(PHUIIconView::SPRITE_LOGIN) + ->setSpriteIcon($this->getLoginIcon()); + + $button = id(new PHUIButtonView()) + ->setSize(PHUIButtonView::BIG) + ->setColor(PHUIButtonView::GREY) + ->setIcon($icon) + ->setText($button_text) + ->setSubtext($this->getProviderName()); + + $uri = $attributes['uri']; + $uri = new PhutilURI($uri); + $params = $uri->getQueryParams(); + $uri->setQueryParams(array()); + + $content = array($button); + + foreach ($params as $key => $value) { + $content[] = phutil_tag( + 'input', + array( + 'type' => 'hidden', + 'name' => $key, + 'value' => $value, + )); + } + + return phabricator_form( + $viewer, + array( + 'method' => idx($attributes, 'method', 'GET'), + 'action' => (string)$uri, + ), + $content); + } + } diff --git a/src/applications/auth/provider/PhabricatorAuthProviderOAuth.php b/src/applications/auth/provider/PhabricatorAuthProviderOAuth.php index 88d1b60369..9578e3e2f4 100644 --- a/src/applications/auth/provider/PhabricatorAuthProviderOAuth.php +++ b/src/applications/auth/provider/PhabricatorAuthProviderOAuth.php @@ -34,56 +34,17 @@ abstract class PhabricatorAuthProviderOAuth extends PhabricatorAuthProvider { } protected function renderLoginForm(AphrontRequest $request, $mode) { - $viewer = $request->getUser(); - - if ($mode == 'link') { - $button_text = pht('Link External Account'); - } else if ($mode == 'refresh') { - $button_text = pht('Refresh Account Link'); - } else if ($this->shouldAllowRegistration()) { - $button_text = pht('Login or Register'); - } else { - $button_text = pht('Login'); - } - - $icon = id(new PHUIIconView()) - ->setSpriteSheet(PHUIIconView::SPRITE_LOGIN) - ->setSpriteIcon($this->getLoginIcon()); - - $button = id(new PHUIButtonView()) - ->setSize(PHUIButtonView::BIG) - ->setColor(PHUIButtonView::GREY) - ->setIcon($icon) - ->setText($button_text) - ->setSubtext($this->getProviderName()); - $adapter = $this->getAdapter(); $adapter->setState(PhabricatorHash::digest($request->getCookie('phcid'))); - $uri = new PhutilURI($adapter->getAuthenticateURI()); - $params = $uri->getQueryParams(); - $uri->setQueryParams(array()); + $attributes = array( + 'method' => 'GET', + 'uri' => $adapter->getAuthenticateURI(), + ); - $content = array($button); - - foreach ($params as $key => $value) { - $content[] = phutil_tag( - 'input', - array( - 'type' => 'hidden', - 'name' => $key, - 'value' => $value, - )); - } - - return phabricator_form( - $viewer, - array( - 'method' => 'GET', - 'action' => (string)$uri, - ), - $content); + return $this->renderStandardLoginButton($request, $mode, $attributes); } + public function processLoginRequest( PhabricatorAuthLoginController $controller) { diff --git a/src/applications/auth/provider/PhabricatorAuthProviderOAuth1.php b/src/applications/auth/provider/PhabricatorAuthProviderOAuth1.php index c5931cacd0..96cc5d7c1e 100644 --- a/src/applications/auth/provider/PhabricatorAuthProviderOAuth1.php +++ b/src/applications/auth/provider/PhabricatorAuthProviderOAuth1.php @@ -39,54 +39,11 @@ abstract class PhabricatorAuthProviderOAuth1 extends PhabricatorAuthProvider { } protected function renderLoginForm(AphrontRequest $request, $mode) { - $viewer = $request->getUser(); - - if ($mode == 'link') { - $button_text = pht('Link External Account'); - } else if ($mode == 'refresh') { - $button_text = pht('Refresh Account Link'); - } else if ($this->shouldAllowRegistration()) { - $button_text = pht('Login or Register'); - } else { - $button_text = pht('Login'); - } - - $icon = id(new PHUIIconView()) - ->setSpriteSheet(PHUIIconView::SPRITE_LOGIN) - ->setSpriteIcon($this->getLoginIcon()); - - $button = id(new PHUIButtonView()) - ->setSize(PHUIButtonView::BIG) - ->setColor(PHUIButtonView::GREY) - ->setIcon($icon) - ->setText($button_text) - ->setSubtext($this->getProviderName()); - - $adapter = $this->getAdapter(); - - $uri = new PhutilURI($this->getLoginURI()); - $params = $uri->getQueryParams(); - $uri->setQueryParams(array()); - - $content = array($button); - - foreach ($params as $key => $value) { - $content[] = phutil_tag( - 'input', - array( - 'type' => 'hidden', - 'name' => $key, - 'value' => $value, - )); - } - - return phabricator_form( - $viewer, - array( - 'method' => 'POST', - 'action' => (string)$uri, - ), - $content); + $attributes = array( + 'method' => 'POST', + 'uri' => $this->getLoginURI(), + ); + return $this->renderStandardLoginButton($request, $mode, $attributes); } public function processLoginRequest(