[ Index ] |
PHP Cross Reference of Phabricator |
[Summary view] [Print] [Text view]
1 <?php 2 3 final class PhabricatorAuthEditController 4 extends PhabricatorAuthProviderConfigController { 5 6 private $providerClass; 7 private $configID; 8 9 public function willProcessRequest(array $data) { 10 $this->providerClass = idx($data, 'className'); 11 $this->configID = idx($data, 'id'); 12 } 13 14 public function processRequest() { 15 $request = $this->getRequest(); 16 $viewer = $request->getUser(); 17 18 if ($this->configID) { 19 $config = id(new PhabricatorAuthProviderConfigQuery()) 20 ->setViewer($viewer) 21 ->requireCapabilities( 22 array( 23 PhabricatorPolicyCapability::CAN_VIEW, 24 PhabricatorPolicyCapability::CAN_EDIT, 25 )) 26 ->withIDs(array($this->configID)) 27 ->executeOne(); 28 if (!$config) { 29 return new Aphront404Response(); 30 } 31 32 $provider = $config->getProvider(); 33 if (!$provider) { 34 return new Aphront404Response(); 35 } 36 37 $is_new = false; 38 } else { 39 $providers = PhabricatorAuthProvider::getAllBaseProviders(); 40 foreach ($providers as $candidate_provider) { 41 if (get_class($candidate_provider) === $this->providerClass) { 42 $provider = $candidate_provider; 43 break; 44 } 45 } 46 47 if (!$provider) { 48 return new Aphront404Response(); 49 } 50 51 // TODO: When we have multi-auth providers, support them here. 52 53 $configs = id(new PhabricatorAuthProviderConfigQuery()) 54 ->setViewer($viewer) 55 ->withProviderClasses(array(get_class($provider))) 56 ->execute(); 57 58 if ($configs) { 59 $id = head($configs)->getID(); 60 $dialog = id(new AphrontDialogView()) 61 ->setUser($viewer) 62 ->setMethod('GET') 63 ->setSubmitURI($this->getApplicationURI('config/edit/'.$id.'/')) 64 ->setTitle(pht('Provider Already Configured')) 65 ->appendChild( 66 pht( 67 'This provider ("%s") already exists, and you can not add more '. 68 'than one instance of it. You can edit the existing provider, '. 69 'or you can choose a different provider.', 70 $provider->getProviderName())) 71 ->addCancelButton($this->getApplicationURI('config/new/')) 72 ->addSubmitButton(pht('Edit Existing Provider')); 73 74 return id(new AphrontDialogResponse())->setDialog($dialog); 75 } 76 77 $config = $provider->getDefaultProviderConfig(); 78 $provider->attachProviderConfig($config); 79 80 $is_new = true; 81 } 82 83 $errors = array(); 84 85 $v_registration = $config->getShouldAllowRegistration(); 86 $v_link = $config->getShouldAllowLink(); 87 $v_unlink = $config->getShouldAllowUnlink(); 88 $v_trust_email = $config->getShouldTrustEmails(); 89 90 if ($request->isFormPost()) { 91 92 $properties = $provider->readFormValuesFromRequest($request); 93 list($errors, $issues, $properties) = $provider->processEditForm( 94 $request, 95 $properties); 96 97 $xactions = array(); 98 99 if (!$errors) { 100 if ($is_new) { 101 if (!strlen($config->getProviderType())) { 102 $config->setProviderType($provider->getProviderType()); 103 } 104 if (!strlen($config->getProviderDomain())) { 105 $config->setProviderDomain($provider->getProviderDomain()); 106 } 107 } 108 109 $xactions[] = id(new PhabricatorAuthProviderConfigTransaction()) 110 ->setTransactionType( 111 PhabricatorAuthProviderConfigTransaction::TYPE_REGISTRATION) 112 ->setNewValue($request->getInt('allowRegistration', 0)); 113 114 $xactions[] = id(new PhabricatorAuthProviderConfigTransaction()) 115 ->setTransactionType( 116 PhabricatorAuthProviderConfigTransaction::TYPE_LINK) 117 ->setNewValue($request->getInt('allowLink', 0)); 118 119 $xactions[] = id(new PhabricatorAuthProviderConfigTransaction()) 120 ->setTransactionType( 121 PhabricatorAuthProviderConfigTransaction::TYPE_UNLINK) 122 ->setNewValue($request->getInt('allowUnlink', 0)); 123 124 $xactions[] = id(new PhabricatorAuthProviderConfigTransaction()) 125 ->setTransactionType( 126 PhabricatorAuthProviderConfigTransaction::TYPE_TRUST_EMAILS) 127 ->setNewValue($request->getInt('trustEmails', 0)); 128 129 foreach ($properties as $key => $value) { 130 $xactions[] = id(new PhabricatorAuthProviderConfigTransaction()) 131 ->setTransactionType( 132 PhabricatorAuthProviderConfigTransaction::TYPE_PROPERTY) 133 ->setMetadataValue('auth:property', $key) 134 ->setNewValue($value); 135 } 136 137 if ($is_new) { 138 $config->save(); 139 } 140 141 $editor = id(new PhabricatorAuthProviderConfigEditor()) 142 ->setActor($viewer) 143 ->setContentSourceFromRequest($request) 144 ->setContinueOnNoEffect(true) 145 ->applyTransactions($config, $xactions); 146 147 148 if ($provider->hasSetupStep() && $is_new) { 149 $id = $config->getID(); 150 $next_uri = $this->getApplicationURI('config/edit/'.$id.'/'); 151 } else { 152 $next_uri = $this->getApplicationURI(); 153 } 154 155 return id(new AphrontRedirectResponse())->setURI($next_uri); 156 } 157 } else { 158 $properties = $provider->readFormValuesFromProvider(); 159 $issues = array(); 160 } 161 162 if ($is_new) { 163 $button = pht('Add Provider'); 164 $crumb = pht('Add Provider'); 165 $title = pht('Add Authentication Provider'); 166 $cancel_uri = $this->getApplicationURI('/config/new/'); 167 } else { 168 $button = pht('Save'); 169 $crumb = pht('Edit Provider'); 170 $title = pht('Edit Authentication Provider'); 171 $cancel_uri = $this->getApplicationURI(); 172 } 173 174 $config_name = 'auth.email-domains'; 175 $config_href = '/config/edit/'.$config_name.'/'; 176 177 $email_domains = PhabricatorEnv::getEnvConfig($config_name); 178 if ($email_domains) { 179 $registration_warning = pht( 180 'Users will only be able to register with a verified email address '. 181 'at one of the configured [[ %s | %s ]] domains: **%s**', 182 $config_href, 183 $config_name, 184 implode(', ', $email_domains)); 185 } else { 186 $registration_warning = pht( 187 "NOTE: Any user who can browse to this install's login page will be ". 188 "able to register a Phabricator account. To restrict who can register ". 189 "an account, configure [[ %s | %s ]].", 190 $config_href, 191 $config_name); 192 } 193 194 $str_registration = array( 195 phutil_tag('strong', array(), pht('Allow Registration:')), 196 ' ', 197 pht( 198 'Allow users to register new Phabricator accounts using this '. 199 'provider. If you disable registration, users can still use this '. 200 'provider to log in to existing accounts, but will not be able to '. 201 'create new accounts.'), 202 ); 203 204 $str_link = hsprintf( 205 '<strong>%s:</strong> %s', 206 pht('Allow Linking Accounts'), 207 pht( 208 'Allow users to link account credentials for this provider to '. 209 'existing Phabricator accounts. There is normally no reason to '. 210 'disable this unless you are trying to move away from a provider '. 211 'and want to stop users from creating new account links.')); 212 213 $str_unlink = hsprintf( 214 '<strong>%s:</strong> %s', 215 pht('Allow Unlinking Accounts'), 216 pht( 217 'Allow users to unlink account credentials for this provider from '. 218 'existing Phabricator accounts. If you disable this, Phabricator '. 219 'accounts will be permanently bound to provider accounts.')); 220 221 $str_trusted_email = hsprintf( 222 '<strong>%s:</strong> %s', 223 pht('Trust Email Addresses'), 224 pht( 225 'Phabricator will skip email verification for accounts registered '. 226 'through this provider.')); 227 228 $status_tag = id(new PHUITagView()) 229 ->setType(PHUITagView::TYPE_STATE); 230 if ($is_new) { 231 $status_tag 232 ->setName(pht('New Provider')) 233 ->setBackgroundColor('blue'); 234 } else if ($config->getIsEnabled()) { 235 $status_tag 236 ->setName(pht('Enabled')) 237 ->setBackgroundColor('green'); 238 } else { 239 $status_tag 240 ->setName(pht('Disabled')) 241 ->setBackgroundColor('red'); 242 } 243 244 $form = id(new AphrontFormView()) 245 ->setUser($viewer) 246 ->appendChild( 247 id(new AphrontFormStaticControl()) 248 ->setLabel(pht('Provider')) 249 ->setValue($provider->getProviderName())) 250 ->appendChild( 251 id(new AphrontFormStaticControl()) 252 ->setLabel(pht('Status')) 253 ->setValue($status_tag)) 254 ->appendChild( 255 id(new AphrontFormCheckboxControl()) 256 ->setLabel(pht('Allow')) 257 ->addCheckbox( 258 'allowRegistration', 259 1, 260 $str_registration, 261 $v_registration)) 262 ->appendRemarkupInstructions($registration_warning) 263 ->appendChild( 264 id(new AphrontFormCheckboxControl()) 265 ->addCheckbox( 266 'allowLink', 267 1, 268 $str_link, 269 $v_link)) 270 ->appendChild( 271 id(new AphrontFormCheckboxControl()) 272 ->addCheckbox( 273 'allowUnlink', 274 1, 275 $str_unlink, 276 $v_unlink)); 277 278 if ($provider->shouldAllowEmailTrustConfiguration()) { 279 $form->appendChild( 280 id(new AphrontFormCheckboxControl()) 281 ->addCheckbox( 282 'trustEmails', 283 1, 284 $str_trusted_email, 285 $v_trust_email)); 286 } 287 288 $provider->extendEditForm($request, $form, $properties, $issues); 289 290 $form 291 ->appendChild( 292 id(new AphrontFormSubmitControl()) 293 ->addCancelButton($cancel_uri) 294 ->setValue($button)); 295 296 $help = $provider->getConfigurationHelp(); 297 if ($help) { 298 $form->appendChild(id(new PHUIFormDividerControl())); 299 $form->appendRemarkupInstructions($help); 300 } 301 302 $footer = $provider->renderConfigurationFooter(); 303 304 $crumbs = $this->buildApplicationCrumbs(); 305 $crumbs->addTextCrumb($crumb); 306 307 $xaction_view = null; 308 if (!$is_new) { 309 $xactions = id(new PhabricatorAuthProviderConfigTransactionQuery()) 310 ->withObjectPHIDs(array($config->getPHID())) 311 ->setViewer($viewer) 312 ->execute(); 313 314 foreach ($xactions as $xaction) { 315 $xaction->setProvider($provider); 316 } 317 318 $xaction_view = id(new PhabricatorApplicationTransactionView()) 319 ->setUser($viewer) 320 ->setObjectPHID($config->getPHID()) 321 ->setTransactions($xactions); 322 } 323 324 $form_box = id(new PHUIObjectBoxView()) 325 ->setHeaderText($title) 326 ->setFormErrors($errors) 327 ->setForm($form); 328 329 return $this->buildApplicationPage( 330 array( 331 $crumbs, 332 $form_box, 333 $footer, 334 $xaction_view, 335 ), 336 array( 337 'title' => $title, 338 )); 339 } 340 341 }
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 |