Differential D13123 Diff 31761 src/applications/people/controller/PhabricatorPeopleNewController.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/people/controller/PhabricatorPeopleNewController.php
| <?php | <?php | ||||
| final class PhabricatorPeopleNewController | final class PhabricatorPeopleNewController | ||||
| extends PhabricatorPeopleController { | extends PhabricatorPeopleController { | ||||
| public function handleRequest(AphrontRequest $request) { | public function handleRequest(AphrontRequest $request) { | ||||
| $type = $request->getURIData('type'); | $type = $request->getURIData('type'); | ||||
| $admin = $request->getUser(); | $admin = $request->getUser(); | ||||
| $is_bot = false; | |||||
| $is_list = false; | |||||
| switch ($type) { | switch ($type) { | ||||
| case 'standard': | case 'standard': | ||||
| $this->requireApplicationCapability( | $this->requireApplicationCapability( | ||||
| PeopleCreateUsersCapability::CAPABILITY); | PeopleCreateUsersCapability::CAPABILITY); | ||||
| $is_bot = false; | |||||
| break; | break; | ||||
| case 'bot': | case 'bot': | ||||
| $is_bot = true; | $is_bot = true; | ||||
| break; | break; | ||||
| case 'list': | |||||
| $is_list = true; | |||||
| break; | |||||
| default: | default: | ||||
| return new Aphront404Response(); | return new Aphront404Response(); | ||||
| } | } | ||||
| $user = new PhabricatorUser(); | $user = new PhabricatorUser(); | ||||
| $require_real_name = PhabricatorEnv::getEnvConfig('user.require-real-name'); | $require_real_name = PhabricatorEnv::getEnvConfig('user.require-real-name'); | ||||
| $e_username = true; | $e_username = true; | ||||
| ▲ Show 20 Lines • Show All 45 Lines • ▼ Show 20 Lines | if ($request->isFormPost()) { | ||||
| $email = id(new PhabricatorUserEmail()) | $email = id(new PhabricatorUserEmail()) | ||||
| ->setAddress($new_email) | ->setAddress($new_email) | ||||
| ->setIsVerified(0); | ->setIsVerified(0); | ||||
| // Automatically approve the user, since an admin is creating them. | // Automatically approve the user, since an admin is creating them. | ||||
| $user->setIsApproved(1); | $user->setIsApproved(1); | ||||
| // If the user is a bot, approve their email too. | // If the user is a bot or list, approve their email too. | ||||
| if ($is_bot) { | if ($is_bot || $is_list) { | ||||
| $email->setIsVerified(1); | $email->setIsVerified(1); | ||||
| } | } | ||||
| id(new PhabricatorUserEditor()) | id(new PhabricatorUserEditor()) | ||||
| ->setActor($admin) | ->setActor($admin) | ||||
| ->createNewUser($user, $email); | ->createNewUser($user, $email); | ||||
| if ($is_bot) { | if ($is_bot) { | ||||
| id(new PhabricatorUserEditor()) | id(new PhabricatorUserEditor()) | ||||
| ->setActor($admin) | ->setActor($admin) | ||||
| ->makeSystemAgentUser($user, true); | ->makeSystemAgentUser($user, true); | ||||
| } | } | ||||
| if ($welcome_checked && !$is_bot) { | if ($is_list) { | ||||
| id(new PhabricatorUserEditor()) | |||||
| ->setActor($admin) | |||||
| ->makeMailingListUser($user, true); | |||||
| } | |||||
| if ($welcome_checked && !$is_bot && !$is_list) { | |||||
| $user->sendWelcomeEmail($admin); | $user->sendWelcomeEmail($admin); | ||||
| } | } | ||||
| $response = id(new AphrontRedirectResponse()) | $response = id(new AphrontRedirectResponse()) | ||||
| ->setURI('/p/'.$user->getUsername().'/'); | ->setURI('/p/'.$user->getUsername().'/'); | ||||
| return $response; | return $response; | ||||
| } catch (AphrontDuplicateKeyQueryException $ex) { | } catch (AphrontDuplicateKeyQueryException $ex) { | ||||
| $errors[] = pht('Username and email must be unique.'); | $errors[] = pht('Username and email must be unique.'); | ||||
| Show All 14 Lines | if ($request->isFormPost()) { | ||||
| } | } | ||||
| } | } | ||||
| $form = id(new AphrontFormView()) | $form = id(new AphrontFormView()) | ||||
| ->setUser($admin); | ->setUser($admin); | ||||
| if ($is_bot) { | if ($is_bot) { | ||||
| $form->appendRemarkupInstructions( | $form->appendRemarkupInstructions( | ||||
| pht('You are creating a new **bot/script** user account.')); | pht('You are creating a new **bot** user account.')); | ||||
| } else if ($is_list) { | |||||
| $form->appendRemarkupInstructions( | |||||
| pht('You are creating a new **mailing list** user account.')); | |||||
| } else { | } else { | ||||
| $form->appendRemarkupInstructions( | $form->appendRemarkupInstructions( | ||||
| pht('You are creating a new **standard** user account.')); | pht('You are creating a new **standard** user account.')); | ||||
| } | } | ||||
| $form | $form | ||||
| ->appendChild( | ->appendChild( | ||||
| id(new AphrontFormTextControl()) | id(new AphrontFormTextControl()) | ||||
| Show All 10 Lines | $form | ||||
| ->appendChild( | ->appendChild( | ||||
| id(new AphrontFormTextControl()) | id(new AphrontFormTextControl()) | ||||
| ->setLabel(pht('Email')) | ->setLabel(pht('Email')) | ||||
| ->setName('email') | ->setName('email') | ||||
| ->setValue($new_email) | ->setValue($new_email) | ||||
| ->setCaption(PhabricatorUserEmail::describeAllowedAddresses()) | ->setCaption(PhabricatorUserEmail::describeAllowedAddresses()) | ||||
| ->setError($e_email)); | ->setError($e_email)); | ||||
| if (!$is_bot) { | if (!$is_bot && !$is_list) { | ||||
| $form->appendChild( | $form->appendChild( | ||||
| id(new AphrontFormCheckboxControl()) | id(new AphrontFormCheckboxControl()) | ||||
| ->addCheckbox( | ->addCheckbox( | ||||
| 'welcome', | 'welcome', | ||||
| 1, | 1, | ||||
| pht('Send "Welcome to Phabricator" email with login instructions.'), | pht('Send "Welcome to Phabricator" email with login instructions.'), | ||||
| $welcome_checked)); | $welcome_checked)); | ||||
| } | } | ||||
| $form | $form | ||||
| ->appendChild( | ->appendChild( | ||||
| id(new AphrontFormSubmitControl()) | id(new AphrontFormSubmitControl()) | ||||
| ->addCancelButton($this->getApplicationURI()) | ->addCancelButton($this->getApplicationURI()) | ||||
| ->setValue(pht('Create User'))); | ->setValue(pht('Create User'))); | ||||
| if ($is_bot) { | if ($is_bot) { | ||||
| $form | $form | ||||
| ->appendChild(id(new AphrontFormDividerControl())) | ->appendChild(id(new AphrontFormDividerControl())) | ||||
| ->appendRemarkupInstructions( | ->appendRemarkupInstructions( | ||||
| pht( | pht( | ||||
| '**Why do bot/script accounts need an email address?**'. | '**Why do bot accounts need an email address?**'. | ||||
| "\n\n". | "\n\n". | ||||
| 'Although bots do not normally receive email from Phabricator, '. | 'Although bots do not normally receive email from Phabricator, '. | ||||
| 'they can interact with other systems which require an email '. | 'they can interact with other systems which require an email '. | ||||
| 'address. Examples include:'. | 'address. Examples include:'. | ||||
| "\n\n". | "\n\n". | ||||
| " - If the account takes actions which //send// email, we need ". | " - If the account takes actions which //send// email, we need ". | ||||
| " an address to use in the //From// header.\n". | " an address to use in the //From// header.\n". | ||||
| " - If the account creates commits, Git and Mercurial require ". | " - If the account creates commits, Git and Mercurial require ". | ||||
| Show All 34 Lines | |||||