Correct Aphlict websocket URI construction after PHP8 compatibility changes
[phabricator.git] / src / applications / people / controller / PhabricatorPeopleWelcomeController.php
blob924eb97b5d9be9ad1b2f4716b329e88a13bef0a8
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 '%s" email that users normally receive when their '.
72 'accounts are created by an administrator.',
73 $user->getUsername(),
74 PlatformSymbols::getPlatformServerName()))
75 ->appendRemarkupInstructions(
76 pht(
77 'The email will contain a link that the user may use to log in '.
78 'to their account. This link bypasses authentication requirements '.
79 'and allows them to log in without credentials. Sending a copy of '.
80 'this email can be useful if the original was lost or never sent.'))
81 ->appendRemarkupInstructions($message_instructions)
82 ->appendControl(
83 id(new PhabricatorRemarkupControl())
84 ->setName('message')
85 ->setLabel(pht('Custom Message'))
86 ->setValue($v_message));
88 return $this->newDialog()
89 ->setTitle(pht('Send Welcome Email'))
90 ->setWidth(AphrontDialogView::WIDTH_FORM)
91 ->appendForm($form)
92 ->addSubmitButton(pht('Send Email'))
93 ->addCancelButton($profile_uri);