Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/applications/people/mail/PhabricatorPeopleWelcomeMailEngine.php
12256 views
1
<?php
2
3
final class PhabricatorPeopleWelcomeMailEngine
4
extends PhabricatorPeopleMailEngine {
5
6
private $welcomeMessage;
7
8
public function setWelcomeMessage($welcome_message) {
9
$this->welcomeMessage = $welcome_message;
10
return $this;
11
}
12
13
public function getWelcomeMessage() {
14
return $this->welcomeMessage;
15
}
16
17
public function validateMail() {
18
$sender = $this->getSender();
19
$recipient = $this->getRecipient();
20
21
if (!$sender->getIsAdmin()) {
22
$this->throwValidationException(
23
pht('Not an Administrator'),
24
pht(
25
'You can not send welcome mail because you are not an '.
26
'administrator. Only administrators may send welcome mail.'));
27
}
28
29
if ($recipient->getIsDisabled()) {
30
$this->throwValidationException(
31
pht('User is Disabled'),
32
pht(
33
'You can not send welcome mail to this user because their account '.
34
'is disabled.'));
35
}
36
37
if (!$recipient->canEstablishWebSessions()) {
38
$this->throwValidationException(
39
pht('Not a Normal User'),
40
pht(
41
'You can not send this user welcome mail because they are not '.
42
'a normal user and can not log in to the web interface. Special '.
43
'users (like bots and mailing lists) are unable to establish '.
44
'web sessions.'));
45
}
46
}
47
48
protected function newMail() {
49
$sender = $this->getSender();
50
$recipient = $this->getRecipient();
51
52
$base_uri = PhabricatorEnv::getProductionURI('/');
53
54
$engine = new PhabricatorAuthSessionEngine();
55
56
$uri = $engine->getOneTimeLoginURI(
57
$recipient,
58
$recipient->loadPrimaryEmail(),
59
PhabricatorAuthSessionEngine::ONETIME_WELCOME);
60
61
$message = array();
62
63
$message[] = pht(
64
'Welcome to %s!',
65
PlatformSymbols::getPlatformServerName());
66
67
$message[] = pht(
68
'%s (%s) has created an account for you.',
69
$sender->getUsername(),
70
$sender->getRealName());
71
72
$message[] = pht(
73
' Username: %s',
74
$recipient->getUsername());
75
76
// If password auth is enabled, give the user specific instructions about
77
// how to add a credential to their account.
78
79
// If we aren't sure what they're supposed to be doing and passwords are
80
// not enabled, just give them generic instructions.
81
82
$use_passwords = PhabricatorPasswordAuthProvider::getPasswordProvider();
83
if ($use_passwords) {
84
$message[] = pht(
85
'To log in, follow this link and set a password:');
86
$message[] = pht(' %s', $uri);
87
$message[] = pht(
88
'After you have set a password, you can log in again in '.
89
'the future by going here:');
90
$message[] = pht(' %s', $base_uri);
91
} else {
92
$message[] = pht(
93
'To log in to your account for the first time, follow this link:');
94
$message[] = pht(' %s', $uri);
95
$message[] = pht(
96
'After you set up your account, you can log in again in '.
97
'the future by going here:');
98
$message[] = pht(' %s', $base_uri);
99
}
100
101
$message_body = $this->newBody();
102
if ($message_body !== null) {
103
$message[] = $message_body;
104
}
105
106
$message = implode("\n\n", $message);
107
108
return id(new PhabricatorMetaMTAMail())
109
->setSubject(
110
pht(
111
'[%s] Welcome to %s',
112
PlatformSymbols::getPlatformServerName(),
113
PlatformSymbols::getPlatformServerName()))
114
->setBody($message);
115
}
116
117
private function newBody() {
118
$recipient = $this->getRecipient();
119
120
$custom_body = $this->getWelcomeMessage();
121
if ($custom_body !== null && strlen($custom_body)) {
122
return $this->newRemarkupText($custom_body);
123
}
124
125
$default_body = PhabricatorAuthMessage::loadMessageText(
126
$recipient,
127
PhabricatorAuthWelcomeMailMessageType::MESSAGEKEY);
128
if ($default_body !== null && strlen($default_body)) {
129
return $this->newRemarkupText($default_body);
130
}
131
132
$is_serious = PhabricatorEnv::getEnvConfig('phabricator.serious-business');
133
if (!$is_serious) {
134
return pht(
135
"Love,\n%s",
136
PlatformSymbols::getPlatformServerName());
137
}
138
139
return null;
140
}
141
142
}
143
144