Path: blob/master/src/applications/people/mail/PhabricatorPeopleWelcomeMailEngine.php
12256 views
<?php12final class PhabricatorPeopleWelcomeMailEngine3extends PhabricatorPeopleMailEngine {45private $welcomeMessage;67public function setWelcomeMessage($welcome_message) {8$this->welcomeMessage = $welcome_message;9return $this;10}1112public function getWelcomeMessage() {13return $this->welcomeMessage;14}1516public function validateMail() {17$sender = $this->getSender();18$recipient = $this->getRecipient();1920if (!$sender->getIsAdmin()) {21$this->throwValidationException(22pht('Not an Administrator'),23pht(24'You can not send welcome mail because you are not an '.25'administrator. Only administrators may send welcome mail.'));26}2728if ($recipient->getIsDisabled()) {29$this->throwValidationException(30pht('User is Disabled'),31pht(32'You can not send welcome mail to this user because their account '.33'is disabled.'));34}3536if (!$recipient->canEstablishWebSessions()) {37$this->throwValidationException(38pht('Not a Normal User'),39pht(40'You can not send this user welcome mail because they are not '.41'a normal user and can not log in to the web interface. Special '.42'users (like bots and mailing lists) are unable to establish '.43'web sessions.'));44}45}4647protected function newMail() {48$sender = $this->getSender();49$recipient = $this->getRecipient();5051$base_uri = PhabricatorEnv::getProductionURI('/');5253$engine = new PhabricatorAuthSessionEngine();5455$uri = $engine->getOneTimeLoginURI(56$recipient,57$recipient->loadPrimaryEmail(),58PhabricatorAuthSessionEngine::ONETIME_WELCOME);5960$message = array();6162$message[] = pht(63'Welcome to %s!',64PlatformSymbols::getPlatformServerName());6566$message[] = pht(67'%s (%s) has created an account for you.',68$sender->getUsername(),69$sender->getRealName());7071$message[] = pht(72' Username: %s',73$recipient->getUsername());7475// If password auth is enabled, give the user specific instructions about76// how to add a credential to their account.7778// If we aren't sure what they're supposed to be doing and passwords are79// not enabled, just give them generic instructions.8081$use_passwords = PhabricatorPasswordAuthProvider::getPasswordProvider();82if ($use_passwords) {83$message[] = pht(84'To log in, follow this link and set a password:');85$message[] = pht(' %s', $uri);86$message[] = pht(87'After you have set a password, you can log in again in '.88'the future by going here:');89$message[] = pht(' %s', $base_uri);90} else {91$message[] = pht(92'To log in to your account for the first time, follow this link:');93$message[] = pht(' %s', $uri);94$message[] = pht(95'After you set up your account, you can log in again in '.96'the future by going here:');97$message[] = pht(' %s', $base_uri);98}99100$message_body = $this->newBody();101if ($message_body !== null) {102$message[] = $message_body;103}104105$message = implode("\n\n", $message);106107return id(new PhabricatorMetaMTAMail())108->setSubject(109pht(110'[%s] Welcome to %s',111PlatformSymbols::getPlatformServerName(),112PlatformSymbols::getPlatformServerName()))113->setBody($message);114}115116private function newBody() {117$recipient = $this->getRecipient();118119$custom_body = $this->getWelcomeMessage();120if ($custom_body !== null && strlen($custom_body)) {121return $this->newRemarkupText($custom_body);122}123124$default_body = PhabricatorAuthMessage::loadMessageText(125$recipient,126PhabricatorAuthWelcomeMailMessageType::MESSAGEKEY);127if ($default_body !== null && strlen($default_body)) {128return $this->newRemarkupText($default_body);129}130131$is_serious = PhabricatorEnv::getEnvConfig('phabricator.serious-business');132if (!$is_serious) {133return pht(134"Love,\n%s",135PlatformSymbols::getPlatformServerName());136}137138return null;139}140141}142143144