Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/applications/people/controller/PhabricatorPeopleWelcomeController.php
12262 views
1
<?php
2
3
final class PhabricatorPeopleWelcomeController
4
extends PhabricatorPeopleController {
5
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;
11
}
12
13
public function handleRequest(AphrontRequest $request) {
14
$admin = $this->getViewer();
15
16
$user = id(new PhabricatorPeopleQuery())
17
->setViewer($admin)
18
->withIDs(array($request->getURIData('id')))
19
->executeOne();
20
if (!$user) {
21
return new Aphront404Response();
22
}
23
24
$id = $user->getID();
25
$profile_uri = "/people/manage/{$id}/";
26
27
$welcome_engine = id(new PhabricatorPeopleWelcomeMailEngine())
28
->setSender($admin)
29
->setRecipient($user);
30
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'));
38
}
39
40
$v_message = $request->getStr('message');
41
42
if ($request->isFormPost()) {
43
if (strlen($v_message)) {
44
$welcome_engine->setWelcomeMessage($v_message);
45
}
46
47
$welcome_engine->sendMail();
48
return id(new AphrontRedirectResponse())->setURI($profile_uri);
49
}
50
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.');
64
}
65
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));
87
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);
94
}
95
96
}
97
98