Path: blob/master/src/applications/people/mail/PhabricatorPeopleEmailLoginMailEngine.php
13459 views
<?php12final class PhabricatorPeopleEmailLoginMailEngine3extends PhabricatorPeopleMailEngine {45public function validateMail() {6$recipient = $this->getRecipient();78if ($recipient->getIsDisabled()) {9$this->throwValidationException(10pht('User is Disabled'),11pht(12'You can not send an email login link to this email address '.13'because the associated user account is disabled.'));14}1516if (!$recipient->canEstablishWebSessions()) {17$this->throwValidationException(18pht('Not a Normal User'),19pht(20'You can not send an email login link to this email address '.21'because the associated user account is not a normal user account '.22'and can not log in to the web interface.'));23}24}2526protected function newMail() {27$is_set_password = $this->isSetPasswordWorkflow();2829if ($is_set_password) {30$subject = pht(31'[%s] Account Password Link',32PlatformSymbols::getPlatformServerName());33} else {34$subject = pht(35'[%s] Account Login Link',36PlatformSymbols::getPlatformServerName());37}3839$recipient = $this->getRecipient();4041PhabricatorSystemActionEngine::willTakeAction(42array($recipient->getPHID()),43new PhabricatorAuthEmailLoginAction(),441);4546$engine = new PhabricatorAuthSessionEngine();47$login_uri = $engine->getOneTimeLoginURI(48$recipient,49null,50PhabricatorAuthSessionEngine::ONETIME_RESET);5152$is_serious = PhabricatorEnv::getEnvConfig('phabricator.serious-business');53$have_passwords = $this->isPasswordAuthEnabled();5455$body = array();5657if ($is_set_password) {58$message_key = PhabricatorAuthEmailSetPasswordMessageType::MESSAGEKEY;59} else {60$message_key = PhabricatorAuthEmailLoginMessageType::MESSAGEKEY;61}6263$message_body = PhabricatorAuthMessage::loadMessageText(64$recipient,65$message_key);66if ($message_body !== null && strlen($message_body)) {67$body[] = $this->newRemarkupText($message_body);68}6970if ($have_passwords) {71if ($is_set_password) {72$body[] = pht(73'You can use this link to set a password on your account:'.74"\n\n %s\n",75$login_uri);76} else if ($is_serious) {77$body[] = pht(78"You can use this link to reset your password:".79"\n\n %s\n",80$login_uri);81} else {82$body[] = pht(83"Condolences on forgetting your password. You can use this ".84"link to reset it:\n\n".85" %s\n\n".86"After you set a new password, consider writing it down on a ".87"sticky note and attaching it to your monitor so you don't ".88"forget again! Choosing a very short, easy-to-remember password ".89"like \"cat\" or \"1234\" might also help.\n\n".90"Best Wishes,\nPhabricator\n",91$login_uri);9293}94} else {95$body[] = pht(96"You can use this login link to regain access to your account:".97"\n\n".98" %s\n",99$login_uri);100}101102$body = implode("\n\n", $body);103104return id(new PhabricatorMetaMTAMail())105->setSubject($subject)106->setBody($body);107}108109private function isPasswordAuthEnabled() {110return (bool)PhabricatorPasswordAuthProvider::getPasswordProvider();111}112113private function isSetPasswordWorkflow() {114$sender = $this->getSender();115$recipient = $this->getRecipient();116117// Users can hit the "login with an email link" workflow while trying to118// set a password on an account which does not yet have a password. We119// require they verify that they own the email address and send them120// through the email login flow. In this case, the messaging is slightly121// different.122123if ($sender->getPHID()) {124if ($sender->getPHID() === $recipient->getPHID()) {125return true;126}127}128129return false;130}131132}133134135