Utilize hsprintf() in OAuth

Test Plan: /oauth/facebook/login/?error=<a>

Reviewers: epriestley

Reviewed By: epriestley

CC: aran, epriestley

Differential Revision: https://secure.phabricator.com/D1577
This commit is contained in:
vrana 2012-02-04 20:48:19 -08:00
parent 7a0337054b
commit be424bf381
2 changed files with 62 additions and 51 deletions

View file

@ -41,7 +41,7 @@ class PhabricatorOAuthLoginController extends PhabricatorAuthController {
return new Aphront400Response(); return new Aphront400Response();
} }
$provider_name = phutil_escape_html($provider->getProviderName()); $provider_name = $provider->getProviderName();
$provider_key = $provider->getProviderKey(); $provider_key = $provider->getProviderKey();
$request = $this->getRequest(); $request = $this->getRequest();
@ -79,11 +79,13 @@ class PhabricatorOAuthLoginController extends PhabricatorAuthController {
$dialog->setUser($current_user); $dialog->setUser($current_user);
$dialog->setTitle('Already Linked to Another Account'); $dialog->setTitle('Already Linked to Another Account');
$dialog->appendChild( $dialog->appendChild(
'<p>The '.$provider_name.' account you just authorized '. hsprintf(
'is already linked to another Phabricator account. Before you can '. '<p>The %s account you just authorized is already linked to '.
'associate your '.$provider_name.' account with this Phabriactor '. 'another Phabricator account. Before you can associate your %s '.
'account, you must unlink it from the Phabricator account it is '. 'account with this Phabriactor account, you must unlink it from '.
'currently linked to.</p>'); 'the Phabricator account it is currently linked to.</p>',
$provider_name,
$provider_name));
$dialog->addCancelButton('/settings/page/'.$provider_key.'/'); $dialog->addCancelButton('/settings/page/'.$provider_key.'/');
return id(new AphrontDialogResponse())->setDialog($dialog); return id(new AphrontDialogResponse())->setDialog($dialog);
@ -103,9 +105,12 @@ class PhabricatorOAuthLoginController extends PhabricatorAuthController {
$dialog->setUser($current_user); $dialog->setUser($current_user);
$dialog->setTitle('Already Linked to an Account From This Provider'); $dialog->setTitle('Already Linked to an Account From This Provider');
$dialog->appendChild( $dialog->appendChild(
'<p>The account you are logged in with is already linked to a '. hsprintf(
$provider_name.' account. Before you can link it to a different '. '<p>The account you are logged in with is already linked to a %s '.
$provider_name.' account, you must unlink the old account.</p>'); 'account. Before you can link it to a different %s account, you '.
'must unlink the old account.</p>',
$provider_name,
$provider_name));
$dialog->addCancelButton('/settings/page/'.$provider_key.'/'); $dialog->addCancelButton('/settings/page/'.$provider_key.'/');
return id(new AphrontDialogResponse())->setDialog($dialog); return id(new AphrontDialogResponse())->setDialog($dialog);
} }
@ -113,10 +118,11 @@ class PhabricatorOAuthLoginController extends PhabricatorAuthController {
if (!$request->isDialogFormPost()) { if (!$request->isDialogFormPost()) {
$dialog = new AphrontDialogView(); $dialog = new AphrontDialogView();
$dialog->setUser($current_user); $dialog->setUser($current_user);
$dialog->setTitle('Link '.$provider->getProviderName().' Account'); $dialog->setTitle('Link '.$provider_name.' Account');
$dialog->appendChild( $dialog->appendChild(
'<p>Link your '.$provider_name.' account to your Phabricator '. hsprintf(
'account?</p>'); '<p>Link your %s account to your Phabricator account?</p>',
$provider_name));
$dialog->addHiddenInput('token', $provider->getAccessToken()); $dialog->addHiddenInput('token', $provider->getAccessToken());
$dialog->addHiddenInput('expires', $oauth_info->getTokenExpires()); $dialog->addHiddenInput('expires', $oauth_info->getTokenExpires());
$dialog->addHiddenInput('state', $this->oauthState); $dialog->addHiddenInput('state', $this->oauthState);
@ -171,10 +177,12 @@ class PhabricatorOAuthLoginController extends PhabricatorAuthController {
$dialog->setUser($current_user); $dialog->setUser($current_user);
$dialog->setTitle('Already Linked to Another Account'); $dialog->setTitle('Already Linked to Another Account');
$dialog->appendChild( $dialog->appendChild(
'<p>The '.$provider_name.' account you just authorized has an '. hsprintf(
'email address which is already in use by another Phabricator '. '<p>The %s account you just authorized has an email address which '.
'account. To link the accounts, log in to your Phabricator '. 'is already in use by another Phabricator account. To link the '.
'account and then go to Settings.</p>'); 'accounts, log in to your Phabricator account and then go to '.
'Settings.</p>',
$provider_name));
$dialog->addCancelButton('/login/'); $dialog->addCancelButton('/login/');
return id(new AphrontDialogResponse())->setDialog($dialog); return id(new AphrontDialogResponse())->setDialog($dialog);
@ -184,13 +192,14 @@ class PhabricatorOAuthLoginController extends PhabricatorAuthController {
if (!$provider->isProviderRegistrationEnabled()) { if (!$provider->isProviderRegistrationEnabled()) {
$dialog = new AphrontDialogView(); $dialog = new AphrontDialogView();
$dialog->setUser($current_user); $dialog->setUser($current_user);
$dialog->setTitle('No Account Registration With '. $dialog->setTitle('No Account Registration With '.$provider_name);
$provider->getProviderName());
$dialog->appendChild( $dialog->appendChild(
'<p>You can not register a new account using '.$provider_name.'; '. hsprintf(
'you can only use your '.$provider_name.' account to log into an '. '<p>You can not register a new account using %s; you can only use '.
'existing Phabricator account which you have registered through '. 'your %s account to log into an existing Phabricator account which '.
'other means.</p>'); 'you have registered through other means.</p>',
$provider_name,
$provider_name));
$dialog->addCancelButton('/login/'); $dialog->addCancelButton('/login/');
return id(new AphrontDialogResponse())->setDialog($dialog); return id(new AphrontDialogResponse())->setDialog($dialog);

View file

@ -34,49 +34,51 @@ class PhabricatorOAuthFailureView extends AphrontView {
public function render() { public function render() {
$request = $this->request; $request = $this->request;
$provider = $this->provider; $provider = $this->provider;
$provider_name = phutil_escape_html($provider->getProviderName()); $provider_name = $provider->getProviderName();
$diagnose = null; $diagnose = null;
$view = new AphrontRequestFailureView(); $view = new AphrontRequestFailureView();
$view->setHeader($provider->getProviderName().' Auth Failed'); $view->setHeader($provider_name.' Auth Failed');
if ($this->request) { if ($this->request) {
$view->appendChild( $view->appendChild(
'<p>'. hsprintf(
'<strong>Description:</strong> '. '<p><strong>Description:</strong> %s</p>',
phutil_escape_html($request->getStr('error_description')). $request->getStr('error_description')));
'</p>');
$view->appendChild( $view->appendChild(
'<p>'. hsprintf(
'<strong>Error:</strong> '. '<p><strong>Error:</strong> %s</p>',
phutil_escape_html($request->getStr('error')). $request->getStr('error')));
'</p>');
$view->appendChild( $view->appendChild(
'<p>'. hsprintf(
'<strong>Error Reason:</strong> '. '<p><strong>Error Reason:</strong> %s</p>',
phutil_escape_html($request->getStr('error_reason')). $request->getStr('error_reason')));
'</p>');
} else { } else {
// TODO: We can probably refine this. // TODO: We can probably refine this.
$view->appendChild( $view->appendChild(
'<p>Unable to authenticate with '.$provider_name.'. '. hsprintf(
'There are several reasons this might happen:</p>'. '<p>Unable to authenticate with %s. '.
'<ul>'. 'There are several reasons this might happen:</p>'.
'<li>Phabricator may be configured with the wrong Application '. '<ul>'.
'Secret; or</li>'. '<li>Phabricator may be configured with the wrong Application '.
'<li>the '.$provider_name.' OAuth access token may have expired; '. 'Secret; or</li>'.
'or</li>'. '<li>the %s OAuth access token may have expired; or</li>'.
'<li>'.$provider_name.' may have revoked authorization for the '. '<li>%s may have revoked authorization for the Application; '.
'Application; or</li>'. 'or</li>'.
'<li>'.$provider_name.' may be having technical problems.</li>'. '<li>%s may be having technical problems.</li>'.
'</ul>'. '</ul>'.
'<p>You can try again, or login using another method.</p>'); '<p>You can try again, or login using another method.</p>',
$provider_name,
$provider_name,
$provider_name,
$provider_name));
$provider_key = $provider->getProviderKey(); $provider_key = $provider->getProviderKey();
$diagnose = $diagnose = hsprintf(
'<a href="/oauth/'.$provider_key.'/diagnose/" class="button green">'. '<a href="/oauth/'.$provider_key.'/diagnose/" class="button green">'.
'Diagnose '.$provider_name.' OAuth Problems'. 'Diagnose %s OAuth Problems'.
'</a>'; '</a>',
$provider_name);
} }
$view->appendChild( $view->appendChild(