[ Index ] |
PHP Cross Reference of Phabricator |
[Summary view] [Print] [Text view]
1 <?php 2 3 final class PhabricatorAuthLinkController 4 extends PhabricatorAuthController { 5 6 private $action; 7 private $providerKey; 8 9 public function willProcessRequest(array $data) { 10 $this->providerKey = $data['pkey']; 11 $this->action = $data['action']; 12 } 13 14 public function processRequest() { 15 $request = $this->getRequest(); 16 $viewer = $request->getUser(); 17 18 $provider = PhabricatorAuthProvider::getEnabledProviderByKey( 19 $this->providerKey); 20 if (!$provider) { 21 return new Aphront404Response(); 22 } 23 24 switch ($this->action) { 25 case 'link': 26 if (!$provider->shouldAllowAccountLink()) { 27 return $this->renderErrorPage( 28 pht('Account Not Linkable'), 29 array( 30 pht('This provider is not configured to allow linking.'), 31 )); 32 } 33 break; 34 case 'refresh': 35 if (!$provider->shouldAllowAccountRefresh()) { 36 return $this->renderErrorPage( 37 pht('Account Not Refreshable'), 38 array( 39 pht('This provider does not allow refreshing.'), 40 )); 41 } 42 break; 43 default: 44 return new Aphront400Response(); 45 } 46 47 $account = id(new PhabricatorExternalAccount())->loadOneWhere( 48 'accountType = %s AND accountDomain = %s AND userPHID = %s', 49 $provider->getProviderType(), 50 $provider->getProviderDomain(), 51 $viewer->getPHID()); 52 53 switch ($this->action) { 54 case 'link': 55 if ($account) { 56 return $this->renderErrorPage( 57 pht('Account Already Linked'), 58 array( 59 pht( 60 'Your Phabricator account is already linked to an external '. 61 'account for this provider.'), 62 )); 63 } 64 break; 65 case 'refresh': 66 if (!$account) { 67 return $this->renderErrorPage( 68 pht('No Account Linked'), 69 array( 70 pht( 71 'You do not have a linked account on this provider, and thus '. 72 'can not refresh it.'), 73 )); 74 } 75 break; 76 default: 77 return new Aphront400Response(); 78 } 79 80 $panel_uri = '/settings/panel/external/'; 81 82 PhabricatorCookies::setClientIDCookie($request); 83 84 switch ($this->action) { 85 case 'link': 86 id(new PhabricatorAuthSessionEngine())->requireHighSecuritySession( 87 $viewer, 88 $request, 89 $panel_uri); 90 91 $form = $provider->buildLinkForm($this); 92 break; 93 case 'refresh': 94 $form = $provider->buildRefreshForm($this); 95 break; 96 default: 97 return new Aphront400Response(); 98 } 99 100 if ($provider->isLoginFormAButton()) { 101 require_celerity_resource('auth-css'); 102 $form = phutil_tag( 103 'div', 104 array( 105 'class' => 'phabricator-link-button pl', 106 ), 107 $form); 108 } 109 110 switch ($this->action) { 111 case 'link': 112 $name = pht('Link Account'); 113 $title = pht('Link %s Account', $provider->getProviderName()); 114 break; 115 case 'refresh': 116 $name = pht('Refresh Account'); 117 $title = pht('Refresh %s Account', $provider->getProviderName()); 118 break; 119 default: 120 return new Aphront400Response(); 121 } 122 123 $crumbs = $this->buildApplicationCrumbs(); 124 $crumbs->addTextCrumb(pht('Link Account'), $panel_uri); 125 $crumbs->addTextCrumb($provider->getProviderName($name)); 126 127 return $this->buildApplicationPage( 128 array( 129 $crumbs, 130 $form, 131 ), 132 array( 133 'title' => $title, 134 )); 135 } 136 137 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Sun Nov 30 09:20:46 2014 | Cross-referenced by PHPXref 0.7.1 |