2013-06-17 15:12:45 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
final class PhabricatorAuthConfirmLinkController
|
|
|
|
extends PhabricatorAuthController {
|
|
|
|
|
|
|
|
private $accountKey;
|
|
|
|
|
|
|
|
public function willProcessRequest(array $data) {
|
|
|
|
$this->accountKey = idx($data, 'akey');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function processRequest() {
|
|
|
|
$request = $this->getRequest();
|
|
|
|
$viewer = $request->getUser();
|
|
|
|
|
|
|
|
$result = $this->loadAccountForRegistrationOrLinking($this->accountKey);
|
|
|
|
list($account, $provider, $response) = $result;
|
|
|
|
|
|
|
|
if ($response) {
|
|
|
|
return $response;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!$provider->shouldAllowAccountLink()) {
|
|
|
|
return $this->renderError(pht('This account is not linkable.'));
|
|
|
|
}
|
|
|
|
|
|
|
|
$panel_uri = '/settings/panel/external/';
|
|
|
|
|
|
|
|
if ($request->isFormPost()) {
|
|
|
|
$account->setUserPHID($viewer->getPHID());
|
|
|
|
$account->save();
|
|
|
|
|
|
|
|
$this->clearRegistrationCookies();
|
|
|
|
|
|
|
|
// TODO: Send the user email about the new account link.
|
|
|
|
|
|
|
|
return id(new AphrontRedirectResponse())->setURI($panel_uri);
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: Provide more information about the external account. Clicking
|
|
|
|
// through this form blindly is dangerous.
|
|
|
|
|
|
|
|
// TODO: If the user has password authentication, require them to retype
|
|
|
|
// their password here.
|
|
|
|
|
|
|
|
$dialog = id(new AphrontDialogView())
|
|
|
|
->setUser($viewer)
|
|
|
|
->setTitle(pht('Confirm %s Account Link', $provider->getProviderName()))
|
|
|
|
->addCancelButton($panel_uri)
|
|
|
|
->addSubmitButton(pht('Confirm Account Link'));
|
|
|
|
|
2013-08-26 20:53:11 +02:00
|
|
|
$form = id(new PHUIFormLayoutView())
|
2013-06-17 15:12:45 +02:00
|
|
|
->setFullWidth(true)
|
|
|
|
->appendChild(
|
|
|
|
phutil_tag(
|
|
|
|
'div',
|
|
|
|
array(
|
|
|
|
'class' => 'aphront-form-instructions',
|
|
|
|
),
|
|
|
|
pht(
|
|
|
|
"Confirm the link with this %s account. This account will be ".
|
|
|
|
"able to log in to your Phabricator account.",
|
2013-06-17 16:08:50 +02:00
|
|
|
$provider->getProviderName())))
|
|
|
|
->appendChild(
|
|
|
|
id(new PhabricatorAuthAccountView())
|
|
|
|
->setUser($viewer)
|
|
|
|
->setExternalAccount($account)
|
|
|
|
->setAuthProvider($provider));
|
2013-06-17 15:12:45 +02:00
|
|
|
|
|
|
|
$dialog->appendChild($form);
|
|
|
|
|
|
|
|
$crumbs = $this->buildApplicationCrumbs();
|
|
|
|
$crumbs->addCrumb(
|
|
|
|
id(new PhabricatorCrumbView())
|
|
|
|
->setName(pht('Confirm Link'))
|
|
|
|
->setHref($panel_uri));
|
|
|
|
$crumbs->addCrumb(
|
|
|
|
id(new PhabricatorCrumbView())
|
|
|
|
->setName($provider->getProviderName()));
|
|
|
|
|
|
|
|
return $this->buildApplicationPage(
|
|
|
|
array(
|
|
|
|
$crumbs,
|
|
|
|
$dialog,
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'title' => pht('Confirm External Account Link'),
|
|
|
|
'device' => true,
|
|
|
|
));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|