Correct a parameter order swap in "diffusion.historyquery" for Mercurial
[phabricator.git] / src / applications / people / controller / PhabricatorPeopleWelcomeController.php
blob94d5e0bb03f35fb10df14a074ab3e9164bd5a5c1
1 <?php
3 final class PhabricatorPeopleWelcomeController
4 extends PhabricatorPeopleController {
6 public function shouldRequireAdmin() {
7 // You need to be an administrator to actually send welcome email, but
8 // we let anyone hit this page so they can get a nice error dialog
9 // explaining the issue.
10 return false;
13 public function handleRequest(AphrontRequest $request) {
14 $admin = $this->getViewer();
16 $user = id(new PhabricatorPeopleQuery())
17 ->setViewer($admin)
18 ->withIDs(array($request->getURIData('id')))
19 ->executeOne();
20 if (!$user) {
21 return new Aphront404Response();
24 $id = $user->getID();
25 $profile_uri = "/people/manage/{$id}/";
27 $welcome_engine = id(new PhabricatorPeopleWelcomeMailEngine())
28 ->setSender($admin)
29 ->setRecipient($user);
31 try {
32 $welcome_engine->validateMail();
33 } catch (PhabricatorPeopleMailEngineException $ex) {
34 return $this->newDialog()
35 ->setTitle($ex->getTitle())
36 ->appendParagraph($ex->getBody())
37 ->addCancelButton($profile_uri, pht('Done'));
40 $v_message = $request->getStr('message');
42 if ($request->isFormPost()) {
43 if (strlen($v_message)) {
44 $welcome_engine->setWelcomeMessage($v_message);
47 $welcome_engine->sendMail();
48 return id(new AphrontRedirectResponse())->setURI($profile_uri);
51 $default_message = PhabricatorAuthMessage::loadMessage(
52 $admin,
53 PhabricatorAuthWelcomeMailMessageType::MESSAGEKEY);
54 if ($default_message && strlen($default_message->getMessageText())) {
55 $message_instructions = pht(
56 'The email will identify you as the sender. You may optionally '.
57 'replace the [[ %s | default custom mail body ]] with different text '.
58 'by providing a message below.',
59 $default_message->getURI());
60 } else {
61 $message_instructions = pht(
62 'The email will identify you as the sender. You may optionally '.
63 'include additional text in the mail body by specifying it below.');
66 $form = id(new AphrontFormView())
67 ->setViewer($admin)
68 ->appendRemarkupInstructions(
69 pht(
70 'This workflow will send this user ("%s") a copy of the "Welcome to '.
71 'Phabricator" email that users normally receive when their '.
72 'accounts are created by an administrator.',
73 $user->getUsername()))
74 ->appendRemarkupInstructions(
75 pht(
76 'The email will contain a link that the user may use to log in '.
77 'to their account. This link bypasses authentication requirements '.
78 'and allows them to log in without credentials. Sending a copy of '.
79 'this email can be useful if the original was lost or never sent.'))
80 ->appendRemarkupInstructions($message_instructions)
81 ->appendControl(
82 id(new PhabricatorRemarkupControl())
83 ->setName('message')
84 ->setLabel(pht('Custom Message'))
85 ->setValue($v_message));
87 return $this->newDialog()
88 ->setTitle(pht('Send Welcome Email'))
89 ->setWidth(AphrontDialogView::WIDTH_FORM)
90 ->appendForm($form)
91 ->addSubmitButton(pht('Send Email'))
92 ->addCancelButton($profile_uri);