ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
class.ilAccountRegistrationMail.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2019 ILIAS open source, Extended GPL, see docs/LICENSE */
3
9{
12
14 private $settings;
15
17 private $lng;
18
20 private $logger;
21
24
32 {
33 $this->settings = $settings;
34 $this->lng = $lng;
35 $this->logger = $logger;
36
37 parent::__construct(false);
38 }
39
43 public function getMode()
44 {
45 return $this->mode;
46 }
47
52 {
53 $clone = clone $this;
54 $clone->mode = self::MODE_DIRECT_REGISTRATION;
55
56 return $clone;
57 }
58
63 {
64 $clone = clone $this;
66
67 return $clone;
68 }
69
74 private function isEmptyMailConfigurationData($mailData)
75 {
76 return !(
77 isset($mailData['body']) &&
78 is_string($mailData['body']) &&
79 $mailData['body'] !== '' &&
80 isset($mailData['subject']) &&
81 is_string($mailData['subject']) &&
82 $mailData['subject'] !== ''
83 );
84 }
85
91 private function trySendingUserDefinedAccountMail(ilObjUser $user, $rawPassword)
92 {
93 $trimStrings = function ($value) {
94 if (is_string($value)) {
95 $value = trim($value);
96 }
97
98 return $value;
99 };
100
101 $this->logger->debug(sprintf(
102 "Trying to send configurable email dependent welcome email to user %s (id: %s|language: %s) ...",
103 $user->getLogin(),
104 $user->getId(),
105 $user->getLanguage()
106 ));
107
109 if (!is_array($mailData)) {
110 $this->logger->debug(sprintf(
111 "Did not find any email configuration for language '%s' at all, skipping attempt ...",
112 $user->getLanguage()
113 ));
114 return false;
115 }
116
117 $mailData = array_map($trimStrings, $mailData);
118
119 if ($this->isEmptyMailConfigurationData($mailData)) {
120 $this->logger->debug(sprintf(
121 "Either subject or email missing, trying to determine email configuration via default language: %s",
122 $this->language->getDefaultLanguage()
123 ));
124
125 $mailData = ilObjUserFolder::_lookupNewAccountMail($this->language->getDefaultLanguage());
126 if (!is_array($mailData)) {
127 $this->logger->debug(sprintf(
128 "Did not find any email configuration for language '%s' at all, skipping attempt ...",
129 $this->language->getDefaultLanguage()
130 ));
131 return false;
132 }
133
134 $mailData = array_map($trimStrings, $mailData);
135 if ($this->isEmptyMailConfigurationData($mailData)) {
136 $this->logger->debug(sprintf(
137 "Did not find any valid email configuration, skipping attempt ..."
138 ));
139 return false;
140 }
141 }
142
143 $accountMail = new ilAccountMail();
144 $accountMail->setUser($user);
145
146 if ($this->settings->passwordGenerationEnabled()) {
147 $accountMail->setUserPassword($rawPassword);
148 }
149
150 if (isset($mailData['att_file'])) {
152 $fs->create();
153
154 $pathToFile = '/' . implode('/', array_map(function ($pathPart) {
155 return trim($pathPart, '/');
156 }, [
157 $fs->getAbsolutePath(),
158 $mailData['lang'],
159 ]));
160
161 $accountMail->addAttachment($pathToFile, $mailData['att_file']);
162
163 $this->logger->debug(sprintf(
164 "Attaching '%s' as '%s' ...",
165 $pathToFile,
166 $mailData['att_file']
167 ));
168 } else {
169 $this->logger->debug(sprintf(
170 "Not attachments configured for this email configuration ..."
171 ));
172 }
173
174 $accountMail->send();
175
176 $this->logger->debug(sprintf(
177 "Welcome email sent"
178 ));
179
180 return true;
181 }
182
188 private function sendLanguageVariableBasedAccountMail(ilObjUser $user, $rawPassword, $usedRegistrationCode)
189 {
190 $this->logger->debug(sprintf(
191 "Sending language variable dependent welcome email to user %s (id: %s|language: %s) as fallback ...",
192 $user->getLogin(),
193 $user->getId(),
194 $user->getLanguage()
195 ));
196
197 $this->initMimeMail();
198
199 $this->initLanguageByIso2Code($user->getLanguage());
200
201 $this->setSubject($this->language->txt('reg_mail_subject'));
202
203 $this->setBody($this->language->txt('reg_mail_body_salutation') . ' ' . $user->getFullname() . ',');
204 $this->appendBody("\n\n");
205 $this->appendBody($this->language->txt('reg_mail_body_text1'));
206 $this->appendBody("\n\n");
207 $this->appendBody($this->language->txt('reg_mail_body_text2'));
208 $this->appendBody("\n");
209 $this->appendBody(ILIAS_HTTP_PATH . '/login.php?client_id=' . CLIENT_ID);
210 $this->appendBody("\n");
211 $this->appendBody($this->language->txt('login') . ': ' . $user->getLogin());
212 $this->appendBody("\n");
213
214 if ($this->settings->passwordGenerationEnabled()) {
215 $this->appendBody($this->language->txt('passwd') . ': ' . $rawPassword);
216 $this->appendBody("\n");
217 }
218
219 if ($this->getMode() === self::MODE_DIRECT_REGISTRATION) {
220 if ($this->settings->getRegistrationType() == IL_REG_APPROVE && !$usedRegistrationCode) {
221 $this->appendBody("\n");
222 $this->appendBody($this->language->txt('reg_mail_body_pwd_generation'));
223 $this->appendBody("\n\n");
224 }
225 } elseif ($this->getMode() === self::MODE_REGISTRATION_WITH_EMAIL_CONFIRMATION) {
226 $this->appendBody("\n");
227 $this->appendBody($this->language->txt('reg_mail_body_forgot_password_info'));
228 $this->appendBody("\n\n");
229 }
230
231 $this->appendBody($this->language->txt('reg_mail_body_text3'));
232 $this->appendBody("\n");
233 $this->appendBody($user->getProfileAsString($this->language));
235
236 $this->sendMimeMail($user->getEmail());
237
238 $this->logger->debug(sprintf(
239 "Welcome email sent"
240 ));
241 }
242
248 public function send(ilObjUser $user, $rawPassword = '', $usedRegistrationCode = false)
249 {
250 if (!$this->trySendingUserDefinedAccountMail($user, $rawPassword)) {
251 $this->sendLanguageVariableBasedAccountMail($user, $rawPassword, $usedRegistrationCode);
252 }
253 }
254}
sprintf('%.4f', $callTime)
An exception for terminatinating execution or to throw for unit testing.
const USER_FOLDER_ID
Class ilObjUserFolder.
Class ilAccountMail.
Class ilAccountRegistrationMail.
sendLanguageVariableBasedAccountMail(ilObjUser $user, $rawPassword, $usedRegistrationCode)
send(ilObjUser $user, $rawPassword='', $usedRegistrationCode=false)
__construct(ilRegistrationSettings $settings, ilLanguage $lng, ilLogger $logger)
ilAccountRegistrationMail constructor.
trySendingUserDefinedAccountMail(ilObjUser $user, $rawPassword)
language handling
Component logger with individual log levels by component id.
appendBody($a_body)
Append body text.
static _getInstallationSignature()
Base class for mime mail notifications.
static _lookupNewAccountMail($a_lang)
getEmail()
get email address @access public
getLogin()
get login / username @access public
getFullname($a_max_strlen=0)
get fullname @access public
getLanguage()
returns a 2char-language-string @access public
getId()
get object id @access public
Class ilObjAuthSettingsGUI.
settings()
Definition: settings.php:2