3 final class PhabricatorPeopleEmailLoginMailEngine
4 extends PhabricatorPeopleMailEngine
{
6 public function validateMail() {
7 $recipient = $this->getRecipient();
9 if ($recipient->getIsDisabled()) {
10 $this->throwValidationException(
11 pht('User is Disabled'),
13 'You can not send an email login link to this email address '.
14 'because the associated user account is disabled.'));
17 if (!$recipient->canEstablishWebSessions()) {
18 $this->throwValidationException(
19 pht('Not a Normal User'),
21 'You can not send an email login link to this email address '.
22 'because the associated user account is not a normal user account '.
23 'and can not log in to the web interface.'));
27 protected function newMail() {
28 $is_set_password = $this->isSetPasswordWorkflow();
30 if ($is_set_password) {
31 $subject = pht('[Phabricator] Account Password Link');
33 $subject = pht('[Phabricator] Account Login Link');
36 $recipient = $this->getRecipient();
38 PhabricatorSystemActionEngine
::willTakeAction(
39 array($recipient->getPHID()),
40 new PhabricatorAuthEmailLoginAction(),
43 $engine = new PhabricatorAuthSessionEngine();
44 $login_uri = $engine->getOneTimeLoginURI(
47 PhabricatorAuthSessionEngine
::ONETIME_RESET
);
49 $is_serious = PhabricatorEnv
::getEnvConfig('phabricator.serious-business');
50 $have_passwords = $this->isPasswordAuthEnabled();
54 if ($is_set_password) {
55 $message_key = PhabricatorAuthEmailSetPasswordMessageType
::MESSAGEKEY
;
57 $message_key = PhabricatorAuthEmailLoginMessageType
::MESSAGEKEY
;
60 $message_body = PhabricatorAuthMessage
::loadMessageText(
63 if (strlen($message_body)) {
64 $body[] = $this->newRemarkupText($message_body);
67 if ($have_passwords) {
68 if ($is_set_password) {
70 'You can use this link to set a password on your account:'.
73 } else if ($is_serious) {
75 "You can use this link to reset your Phabricator password:".
80 "Condolences on forgetting your password. You can use this ".
81 "link to reset it:\n\n".
83 "After you set a new password, consider writing it down on a ".
84 "sticky note and attaching it to your monitor so you don't ".
85 "forget again! Choosing a very short, easy-to-remember password ".
86 "like \"cat\" or \"1234\" might also help.\n\n".
87 "Best Wishes,\nPhabricator\n",
93 "You can use this login link to regain access to your Phabricator ".
100 $body = implode("\n\n", $body);
102 return id(new PhabricatorMetaMTAMail())
103 ->setSubject($subject)
107 private function isPasswordAuthEnabled() {
108 return (bool)PhabricatorPasswordAuthProvider
::getPasswordProvider();
111 private function isSetPasswordWorkflow() {
112 $sender = $this->getSender();
113 $recipient = $this->getRecipient();
115 // Users can hit the "login with an email link" workflow while trying to
116 // set a password on an account which does not yet have a password. We
117 // require they verify that they own the email address and send them
118 // through the email login flow. In this case, the messaging is slightly
121 if ($sender->getPHID()) {
122 if ($sender->getPHID() === $recipient->getPHID()) {