Path: blob/master/src/applications/people/controller/PhabricatorPeopleInviteSendController.php
12262 views
<?php12final class PhabricatorPeopleInviteSendController3extends PhabricatorPeopleInviteController {45public function handleRequest(AphrontRequest $request) {6$viewer = $this->getViewer();78$this->requireApplicationCapability(9PeopleCreateUsersCapability::CAPABILITY);1011$is_confirm = false;12$errors = array();13$confirm_errors = array();14$e_emails = true;1516$message = $request->getStr('message');17$emails = $request->getStr('emails');18$severity = PHUIInfoView::SEVERITY_ERROR;19if ($request->isFormPost()) {20// NOTE: We aren't using spaces as a delimiter here because email21// addresses with names often include spaces.22$email_list = preg_split('/[,;\n]+/', $emails);23foreach ($email_list as $key => $email) {24if (!strlen(trim($email))) {25unset($email_list[$key]);26}27}2829if ($email_list) {30$e_emails = null;31} else {32$e_emails = pht('Required');33$errors[] = pht(34'To send invites, you must enter at least one email address.');35}3637if (!$errors) {38$is_confirm = true;3940$actions = PhabricatorAuthInviteAction::newActionListFromAddresses(41$viewer,42$email_list);4344$any_valid = false;45$all_valid = true;46foreach ($actions as $action) {47if ($action->willSend()) {48$any_valid = true;49} else {50$all_valid = false;51}52}5354if (!$any_valid) {55$confirm_errors[] = pht(56'None of the provided addresses are valid invite recipients. '.57'Review the table below for details. Revise the address list '.58'to continue.');59} else if ($all_valid) {60$confirm_errors[] = pht(61'All of the addresses appear to be valid invite recipients. '.62'Confirm the actions below to continue.');63$severity = PHUIInfoView::SEVERITY_NOTICE;64} else {65$confirm_errors[] = pht(66'Some of the addresses you entered do not appear to be '.67'valid recipients. Review the table below. You can revise '.68'the address list, or ignore these errors and continue.');69$severity = PHUIInfoView::SEVERITY_WARNING;70}7172if ($any_valid && $request->getBool('confirm')) {7374// TODO: The copywriting on this mail could probably be more75// engaging and we could have a fancy HTML version.7677$template = array();78$template[] = pht(79'%s has invited you to join %s.',80$viewer->getFullName(),81PlatformSymbols::getPlatformServerName());8283if (strlen(trim($message))) {84$template[] = $message;85}8687$template[] = pht(88'To register an account and get started, follow this link:');8990// This isn't a variable; it will be replaced later on in the91// daemons once they generate the URI.92$template[] = '{$INVITE_URI}';9394$template[] = pht(95'If you already have an account, you can follow the link to '.96'quickly verify this email address.');9798$template = implode("\n\n", $template);99100foreach ($actions as $action) {101if ($action->willSend()) {102$action->sendInvite($viewer, $template);103}104}105106// TODO: This is a bit anticlimactic. We don't really have anything107// to show the user because the action is happening in the background108// and the invites won't exist yet. After T5166 we can show a109// better progress bar.110return id(new AphrontRedirectResponse())111->setURI($this->getApplicationURI());112}113}114}115116if ($is_confirm) {117$title = pht('Confirm Invites');118} else {119$title = pht('Invite Users');120}121122$crumbs = $this->buildApplicationCrumbs();123if ($is_confirm) {124$crumbs->addTextCrumb(pht('Confirm'));125} else {126$crumbs->addTextCrumb(pht('Invite Users'));127}128$crumbs->setBorder(true);129130$confirm_box = null;131$info_view = null;132if ($is_confirm) {133134$handles = array();135if ($actions) {136$handles = $this->loadViewerHandles(mpull($actions, 'getUserPHID'));137}138139$invite_table = id(new PhabricatorAuthInviteActionTableView())140->setUser($viewer)141->setInviteActions($actions)142->setHandles($handles);143144$confirm_form = null;145if ($any_valid) {146$confirm_form = id(new AphrontFormView())147->setUser($viewer)148->addHiddenInput('message', $message)149->addHiddenInput('emails', $emails)150->addHiddenInput('confirm', true)151->appendRemarkupInstructions(152pht(153'If everything looks good, click **Send Invitations** to '.154'deliver email invitations these users. Otherwise, edit the '.155'email list or personal message at the bottom of the page to '.156'revise the invitations.'))157->appendChild(158id(new AphrontFormSubmitControl())159->setValue(pht('Send Invitations')));160}161162$info_view = id(new PHUIInfoView())163->setErrors($confirm_errors)164->setSeverity($severity);165166$confirm_box = id(new PHUIObjectBoxView())167->setHeaderText(pht('Confirm Invites'))168->setTable($invite_table)169->appendChild($confirm_form)170->setBackground(PHUIObjectBoxView::BLUE_PROPERTY);171}172173$form = id(new AphrontFormView())174->setUser($viewer)175->appendRemarkupInstructions(176pht(177'To invite users, enter their email addresses below. '.178'Separate addresses with commas or newlines.'))179->appendChild(180id(new AphrontFormTextAreaControl())181->setLabel(pht('Email Addresses'))182->setName(pht('emails'))183->setValue($emails)184->setError($e_emails)185->setHeight(AphrontFormTextAreaControl::HEIGHT_VERY_TALL))186->appendRemarkupInstructions(187pht(188'You can optionally include a heartfelt personal message in '.189'the email.'))190->appendChild(191id(new AphrontFormTextAreaControl())192->setLabel(pht('Message'))193->setName(pht('message'))194->setValue($message))195->appendChild(196id(new AphrontFormSubmitControl())197->setValue(198$is_confirm199? pht('Update Preview')200: pht('Continue'))201->addCancelButton($this->getApplicationURI('invite/')));202203$header = id(new PHUIHeaderView())204->setHeader($title)205->setHeaderIcon('fa-group');206207$box = id(new PHUIObjectBoxView())208->setHeaderText(209$is_confirm210? pht('Revise Invites')211: pht('Invite Users'))212->setFormErrors($errors)213->setForm($form)214->setBackground(PHUIObjectBoxView::BLUE_PROPERTY);215216$view = id(new PHUITwoColumnView())217->setHeader($header)218->setFooter(array(219$info_view,220$confirm_box,221$box,222));223224return $this->newPage()225->setTitle($title)226->setCrumbs($crumbs)227->appendChild($view);228229}230231}232233234