2013-06-17 15:12:45 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
final class PhabricatorAuthLinkController
|
|
|
|
extends PhabricatorAuthController {
|
|
|
|
|
2013-06-25 00:58:27 +02:00
|
|
|
private $action;
|
2013-06-17 15:12:45 +02:00
|
|
|
private $providerKey;
|
|
|
|
|
|
|
|
public function willProcessRequest(array $data) {
|
|
|
|
$this->providerKey = $data['pkey'];
|
2013-06-25 00:58:27 +02:00
|
|
|
$this->action = $data['action'];
|
2013-06-17 15:12:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function processRequest() {
|
|
|
|
$request = $this->getRequest();
|
|
|
|
$viewer = $request->getUser();
|
|
|
|
|
|
|
|
$provider = PhabricatorAuthProvider::getEnabledProviderByKey(
|
|
|
|
$this->providerKey);
|
|
|
|
if (!$provider) {
|
|
|
|
return new Aphront404Response();
|
|
|
|
}
|
|
|
|
|
2013-06-25 00:58:27 +02:00
|
|
|
switch ($this->action) {
|
|
|
|
case 'link':
|
|
|
|
if (!$provider->shouldAllowAccountLink()) {
|
|
|
|
return $this->renderErrorPage(
|
|
|
|
pht('Account Not Linkable'),
|
|
|
|
array(
|
|
|
|
pht('This provider is not configured to allow linking.'),
|
|
|
|
));
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'refresh':
|
|
|
|
if (!$provider->shouldAllowAccountRefresh()) {
|
|
|
|
return $this->renderErrorPage(
|
|
|
|
pht('Account Not Refreshable'),
|
|
|
|
array(
|
|
|
|
pht('This provider does not allow refreshing.'),
|
|
|
|
));
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return new Aphront400Response();
|
2013-06-17 15:12:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
$account = id(new PhabricatorExternalAccount())->loadOneWhere(
|
|
|
|
'accountType = %s AND accountDomain = %s AND userPHID = %s',
|
|
|
|
$provider->getProviderType(),
|
|
|
|
$provider->getProviderDomain(),
|
|
|
|
$viewer->getPHID());
|
2013-06-25 00:58:27 +02:00
|
|
|
|
|
|
|
switch ($this->action) {
|
|
|
|
case 'link':
|
|
|
|
if ($account) {
|
|
|
|
return $this->renderErrorPage(
|
|
|
|
pht('Account Already Linked'),
|
|
|
|
array(
|
|
|
|
pht(
|
|
|
|
'Your Phabricator account is already linked to an external '.
|
|
|
|
'account for this provider.'),
|
|
|
|
));
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'refresh':
|
|
|
|
if (!$account) {
|
|
|
|
return $this->renderErrorPage(
|
|
|
|
pht('No Account Linked'),
|
|
|
|
array(
|
|
|
|
pht(
|
|
|
|
'You do not have a linked account on this provider, and thus '.
|
|
|
|
'can not refresh it.'),
|
|
|
|
));
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return new Aphront400Response();
|
2013-06-17 15:12:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
$panel_uri = '/settings/panel/external/';
|
|
|
|
|
2014-03-14 22:33:31 +01:00
|
|
|
PhabricatorCookies::setClientIDCookie($request);
|
2014-01-23 23:01:35 +01:00
|
|
|
|
2013-06-25 00:58:27 +02:00
|
|
|
switch ($this->action) {
|
|
|
|
case 'link':
|
|
|
|
$form = $provider->buildLinkForm($this);
|
|
|
|
break;
|
|
|
|
case 'refresh':
|
|
|
|
$form = $provider->buildRefreshForm($this);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return new Aphront400Response();
|
|
|
|
}
|
2013-06-17 15:12:45 +02:00
|
|
|
|
|
|
|
if ($provider->isLoginFormAButton()) {
|
|
|
|
require_celerity_resource('auth-css');
|
|
|
|
$form = phutil_tag(
|
|
|
|
'div',
|
|
|
|
array(
|
|
|
|
'class' => 'phabricator-link-button pl',
|
|
|
|
),
|
|
|
|
$form);
|
|
|
|
}
|
|
|
|
|
2013-06-25 00:58:27 +02:00
|
|
|
switch ($this->action) {
|
|
|
|
case 'link':
|
|
|
|
$name = pht('Link Account');
|
|
|
|
$title = pht('Link %s Account', $provider->getProviderName());
|
|
|
|
break;
|
|
|
|
case 'refresh':
|
|
|
|
$name = pht('Refresh Account');
|
|
|
|
$title = pht('Refresh %s Account', $provider->getProviderName());
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return new Aphront400Response();
|
|
|
|
}
|
|
|
|
|
2013-06-17 15:12:45 +02:00
|
|
|
$crumbs = $this->buildApplicationCrumbs();
|
2013-12-19 02:47:34 +01:00
|
|
|
$crumbs->addTextCrumb(pht('Link Account'), $panel_uri);
|
|
|
|
$crumbs->addTextCrumb($provider->getProviderName($name));
|
2013-06-17 15:12:45 +02:00
|
|
|
|
|
|
|
return $this->buildApplicationPage(
|
|
|
|
array(
|
|
|
|
$crumbs,
|
|
|
|
$form,
|
|
|
|
),
|
|
|
|
array(
|
2013-06-25 00:58:27 +02:00
|
|
|
'title' => $title,
|
2013-06-17 15:12:45 +02:00
|
|
|
'device' => true,
|
|
|
|
));
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|