Differential D20014 Diff 47778 src/applications/people/controller/PhabricatorPeopleNewController.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/people/controller/PhabricatorPeopleNewController.php
Show All 29 Lines | public function handleRequest(AphrontRequest $request) { | ||||
} | } | ||||
$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; | ||||
$e_realname = $require_real_name ? true : null; | $e_realname = $require_real_name ? true : null; | ||||
$e_email = true; | $e_email = true; | ||||
$validation_exception = null; | |||||
$errors = array(); | $errors = array(); | ||||
$welcome_checked = true; | $welcome_checked = true; | ||||
$new_email = null; | $new_email = null; | ||||
if ($request->isFormPost()) { | if ($request->isFormPost()) { | ||||
$welcome_checked = $request->getInt('welcome'); | $welcome_checked = $request->getInt('welcome'); | ||||
Show All 27 Lines | if ($request->isFormPost()) { | ||||
$errors[] = pht('Real name is required.'); | $errors[] = pht('Real name is required.'); | ||||
$e_realname = pht('Required'); | $e_realname = pht('Required'); | ||||
} else { | } else { | ||||
$e_realname = null; | $e_realname = null; | ||||
} | } | ||||
if (!$errors) { | if (!$errors) { | ||||
try { | try { | ||||
$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 or list, approve their email too. | // If the user is a bot or list, approve their email too. | ||||
if ($is_bot || $is_list) { | 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) { | |||||
id(new PhabricatorUserEditor()) | |||||
->setActor($admin) | |||||
->makeSystemAgentUser($user, true); | |||||
} | |||||
if ($is_list) { | |||||
id(new PhabricatorUserEditor()) | |||||
->setActor($admin) | |||||
->makeMailingListUser($user, true); | |||||
} | |||||
if ($welcome_checked) { | if ($welcome_checked) { | ||||
$welcome_engine = id(new PhabricatorPeopleWelcomeMailEngine()) | $welcome_engine = id(new PhabricatorPeopleWelcomeMailEngine()) | ||||
->setSender($admin) | ->setSender($admin) | ||||
->setRecipient($user); | ->setRecipient($user); | ||||
if ($welcome_engine->canSendMail()) { | if ($welcome_engine->canSendMail()) { | ||||
$welcome_engine->sendMail(); | $welcome_engine->sendMail(); | ||||
} | } | ||||
} | } | ||||
$response = id(new AphrontRedirectResponse()) | $xactions = array(); | ||||
$xactions[] = id(new PhabricatorUserTransaction()) | |||||
->setTransactionType( | |||||
PhabricatorUserSystemAgentTransaction::TRANSACTIONTYPE) | |||||
->setNewValue($is_bot); | |||||
$xactions[] = id(new PhabricatorUserTransaction()) | |||||
->setTransactionType( | |||||
PhabricatorUserMailingListTransaction::TRANSACTIONTYPE) | |||||
->setNewValue($is_list); | |||||
$editor = id(new PhabricatorUserTransactionEditor()) | |||||
->setActor($admin) | |||||
->setContentSourceFromRequest($request) | |||||
->setContinueOnNoEffect(true) | |||||
->setContinueOnMissingFields(true); | |||||
try { | |||||
$editor->applyTransactions($user, $xactions); | |||||
return id(new AphrontRedirectResponse()) | |||||
->setURI('/p/'.$user->getUsername().'/'); | ->setURI('/p/'.$user->getUsername().'/'); | ||||
return $response; | } catch (PhabricatorApplicationTransactionValidationException $ex) { | ||||
$validation_exception = $ex; | |||||
} | |||||
} catch (AphrontDuplicateKeyQueryException $ex) { | } catch (AphrontDuplicateKeyQueryException $ex) { | ||||
$errors[] = pht('Username and email must be unique.'); | $errors[] = pht('Username and email must be unique.'); | ||||
$same_username = id(new PhabricatorUser()) | $same_username = id(new PhabricatorUser()) | ||||
->loadOneWhere('username = %s', $user->getUsername()); | ->loadOneWhere('username = %s', $user->getUsername()); | ||||
$same_email = id(new PhabricatorUserEmail()) | $same_email = id(new PhabricatorUserEmail()) | ||||
->loadOneWhere('address = %s', $new_email); | ->loadOneWhere('address = %s', $new_email); | ||||
▲ Show 20 Lines • Show All 85 Lines • ▼ Show 20 Lines | if ($is_bot) { | ||||
"The address will automatically be verified, so you do not need ". | "The address will automatically be verified, so you do not need ". | ||||
"to be able to receive mail at this address, and can enter some ". | "to be able to receive mail at this address, and can enter some ". | ||||
"invalid or nonexistent (but correctly formatted) address like ". | "invalid or nonexistent (but correctly formatted) address like ". | ||||
"`bot@yourcompany.com` if you prefer.")); | "`bot@yourcompany.com` if you prefer.")); | ||||
} | } | ||||
$box = id(new PHUIObjectBoxView()) | $box = id(new PHUIObjectBoxView()) | ||||
->setHeaderText($title) | ->setHeaderText($title) | ||||
->setFormErrors($errors) | ->setValidationException($validation_exception) | ||||
->setBackground(PHUIObjectBoxView::WHITE_CONFIG) | ->setBackground(PHUIObjectBoxView::WHITE_CONFIG) | ||||
->setForm($form); | ->setForm($form); | ||||
$crumbs = $this->buildApplicationCrumbs(); | $crumbs = $this->buildApplicationCrumbs(); | ||||
$crumbs->addTextCrumb($title); | $crumbs->addTextCrumb($title); | ||||
$crumbs->setBorder(true); | $crumbs->setBorder(true); | ||||
$view = id(new PHUITwoColumnView()) | $view = id(new PHUITwoColumnView()) | ||||
Show All 9 Lines |