b57048a63434c2cec9de4b2bdcc9f66867dbd288
[Packages/TYPO3.CMS.git] / typo3 / sysext / felogin / Classes / Controller / FrontendLoginController.php
1 <?php
2 namespace TYPO3\CMS\Felogin\Controller;
3
4 /*
5 * This file is part of the TYPO3 CMS project.
6 *
7 * It is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License, either version 2
9 * of the License, or any later version.
10 *
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
13 *
14 * The TYPO3 project - inspiring people to share!
15 */
16
17 use Symfony\Component\Mime\Address;
18 use TYPO3\CMS\Core\Authentication\LoginType;
19 use TYPO3\CMS\Core\Context\Context;
20 use TYPO3\CMS\Core\Crypto\PasswordHashing\PasswordHashFactory;
21 use TYPO3\CMS\Core\Crypto\Random;
22 use TYPO3\CMS\Core\Database\Connection;
23 use TYPO3\CMS\Core\Database\ConnectionPool;
24 use TYPO3\CMS\Core\Database\Query\Restriction\FrontendRestrictionContainer;
25 use TYPO3\CMS\Core\Mail\MailMessage;
26 use TYPO3\CMS\Core\Session\SessionManager;
27 use TYPO3\CMS\Core\Site\SiteFinder;
28 use TYPO3\CMS\Core\Utility\GeneralUtility;
29 use TYPO3\CMS\Core\Utility\HttpUtility;
30 use TYPO3\CMS\Core\Utility\MailUtility;
31 use TYPO3\CMS\Frontend\Plugin\AbstractPlugin;
32 use TYPO3\CMS\FrontendLogin\Validation\RedirectUrlValidator;
33
34 /**
35 * Plugin 'Website User Login' for the 'felogin' extension.
36 *
37 * @internal this is a concrete TYPO3 implementation and solely used for EXT:felogin and not part of TYPO3's Core API.
38 */
39 class FrontendLoginController extends AbstractPlugin
40 {
41 /**
42 * Same as class name
43 *
44 * @var string
45 */
46 public $prefixId = 'tx_felogin_pi1';
47
48 /**
49 * The extension key.
50 *
51 * @var string
52 */
53 public $extKey = 'felogin';
54
55 /**
56 * Is user logged in?
57 *
58 * @var bool
59 */
60 protected $userIsLoggedIn;
61
62 /**
63 * Holds the template for FE rendering
64 *
65 * @var string
66 */
67 protected $template;
68
69 /**
70 * URL for the redirect
71 *
72 * @var string
73 */
74 protected $redirectUrl = '';
75
76 /**
77 * Flag for disable the redirect
78 *
79 * @var bool
80 */
81 protected $noRedirect = false;
82
83 /**
84 * Logintype (given as GPvar), possible: login, logout
85 *
86 * @var string
87 */
88 protected $logintype;
89
90 /**
91 * A list of page UIDs, either an integer or a comma-separated list of integers
92 *
93 * @var string
94 */
95 public $spid;
96
97 /**
98 * Referrer
99 *
100 * @var string
101 */
102 public $referer;
103
104 /**
105 * @var RedirectUrlValidator
106 */
107 protected $urlValidator;
108
109 /**
110 * The main method of the plugin
111 *
112 * @param string $content The PlugIn content
113 * @param array $conf The PlugIn configuration
114 * @return string The content that is displayed on the website
115 * @throws \RuntimeException when no storage PID was configured.
116 */
117 public function main($content, $conf)
118 {
119 $this->urlValidator = GeneralUtility::makeInstance(
120 RedirectUrlValidator::class,
121 GeneralUtility::makeInstance(SiteFinder::class),
122 (int)$this->frontendController->id
123 );
124
125 // Loading TypoScript array into object variable:
126 $this->conf = $conf;
127 // Loading default pivars
128 $this->pi_setPiVarDefaults();
129 // Loading language-labels
130 $this->pi_loadLL('EXT:felogin/Resources/Private/Language/locallang.xlf');
131 // Init FlexForm configuration for plugin:
132 $this->pi_initPIflexForm();
133 $this->mergeflexFormValuesIntoConf();
134 // Get storage PIDs:
135 if ((bool)($GLOBALS['TYPO3_CONF_VARS']['FE']['checkFeUserPid'] ?? false) === false) {
136 $this->spid = 0;
137 } elseif ($this->conf['storagePid']) {
138 if ((int)$this->conf['recursive']) {
139 $this->spid = $this->pi_getPidList($this->conf['storagePid'], (int)$this->conf['recursive']);
140 } else {
141 $this->spid = $this->conf['storagePid'];
142 }
143 } else {
144 throw new \RuntimeException('No storage folder (option storagePid) for frontend users given.', 1450904202);
145 }
146 // GPvars:
147 $this->logintype = GeneralUtility::_GP('logintype');
148
149 if ($this->urlValidator->isValid((string)GeneralUtility::_GP('referer'))) {
150 $this->referer = GeneralUtility::_GP('referer');
151 } else {
152 $this->referer = '';
153 }
154 $this->noRedirect = $this->piVars['noredirect'] || $this->conf['redirectDisable'];
155 // If config.typolinkLinkAccessRestrictedPages is set, the var is return_url
156 $this->redirectUrl = GeneralUtility::_GP('return_url') ?: (string)GeneralUtility::_GP('redirect_url');
157 $this->redirectUrl = $this->urlValidator->isValid($this->redirectUrl) ? $this->redirectUrl : '';
158 // Get Template
159 $templateFile = $this->conf['templateFile'] ?: 'EXT:felogin/Resources/Private/Templates/FrontendLogin.html';
160 $template = GeneralUtility::getFileAbsFileName($templateFile);
161 if ($template !== '' && file_exists($template)) {
162 $this->template = file_get_contents($template);
163 }
164 // Is user logged in?
165 $this->userIsLoggedIn = GeneralUtility::makeInstance(Context::class)->getPropertyFromAspect('frontend.user', 'isLoggedIn');
166 // Redirect
167 if ($this->conf['redirectMode'] && !$this->conf['redirectDisable'] && !$this->noRedirect) {
168 $redirectUrl = $this->processRedirect();
169 if (!empty($redirectUrl)) {
170 $this->redirectUrl = $this->conf['redirectFirstMethod'] ? array_shift($redirectUrl) : array_pop($redirectUrl);
171 } else {
172 $this->redirectUrl = '';
173 }
174 }
175 // What to display
176 $content = '';
177 if ($this->piVars['forgot'] && $this->conf['showForgotPasswordLink']) {
178 $content .= $this->showForgot();
179 } elseif ($this->piVars['forgothash']) {
180 $content .= $this->changePassword();
181 } else {
182 if ($this->userIsLoggedIn && !$this->logintype) {
183 $content .= $this->showLogout();
184 } else {
185 $content .= $this->showLogin();
186 }
187 }
188 // Process the redirect
189 if (($this->logintype === LoginType::LOGIN || $this->logintype === LoginType::LOGOUT) && $this->redirectUrl && !$this->noRedirect) {
190 if (!$this->frontendController->fe_user->isCookieSet() && $this->userIsLoggedIn) {
191 $content .= $this->cObj->stdWrap($this->pi_getLL('cookie_warning'), $this->conf['cookieWarning_stdWrap.']);
192 } else {
193 // Add hook for extra processing before redirect
194 $_params = [
195 'loginType' => $this->logintype,
196 'redirectUrl' => &$this->redirectUrl
197 ];
198 foreach ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['felogin']['beforeRedirect'] ?? [] as $_funcRef) {
199 if ($_funcRef) {
200 GeneralUtility::callUserFunction($_funcRef, $_params, $this);
201 }
202 }
203 \TYPO3\CMS\Core\Utility\HttpUtility::redirect($this->redirectUrl);
204 }
205 }
206 // Adds hook for processing of extra item markers / special
207 foreach ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['felogin']['postProcContent'] ?? [] as $_funcRef) {
208 $_params = [
209 'content' => $content
210 ];
211 $content = GeneralUtility::callUserFunction($_funcRef, $_params, $this);
212 }
213 return $this->conf['wrapContentInBaseClass'] ? $this->pi_wrapInBaseClass($content) : $content;
214 }
215
216 /**
217 * Shows the forgot password form
218 *
219 * @return string Content
220 */
221 protected function showForgot()
222 {
223 $markerArray = [];
224 $subpart = $this->templateService->getSubpart($this->template, '###TEMPLATE_FORGOT###');
225 $subpartArray = ($linkpartArray = []);
226 $postData = GeneralUtility::_POST($this->prefixId);
227 if ($postData['forgot_email']) {
228 // Get hashes for compare
229 $postedHash = $postData['forgot_hash'];
230 $hashData = $this->frontendController->fe_user->getKey('ses', 'forgot_hash');
231 if ($postedHash === $hashData['forgot_hash']) {
232 $userTable = $this->frontendController->fe_user->user_table;
233 $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable($userTable);
234 $queryBuilder->setRestrictions(GeneralUtility::makeInstance(FrontendRestrictionContainer::class));
235 $row = $queryBuilder
236 ->select('*')
237 ->from($userTable)
238 ->where(
239 $queryBuilder->expr()->orX(
240 $queryBuilder->expr()->eq(
241 'email',
242 $queryBuilder->createNamedParameter($this->piVars['forgot_email'], \PDO::PARAM_STR)
243 ),
244 $queryBuilder->expr()->eq(
245 'username',
246 $queryBuilder->createNamedParameter($this->piVars['forgot_email'], \PDO::PARAM_STR)
247 )
248 ),
249 $queryBuilder->expr()->in(
250 'pid',
251 $queryBuilder->createNamedParameter(
252 GeneralUtility::intExplode(',', $this->spid),
253 Connection::PARAM_INT_ARRAY
254 )
255 )
256 )
257 ->execute()
258 ->fetch();
259
260 $error = null;
261 if ($row) {
262 // Generate an email with the hashed link
263 $error = $this->generateAndSendHash($row);
264 } elseif ($this->conf['exposeNonexistentUserInForgotPasswordDialog']) {
265 $error = $this->pi_getLL('forgot_reset_message_error');
266 }
267 // Generate message
268 if ($error) {
269 $markerArray['###STATUS_MESSAGE###'] = $this->cObj->stdWrap($error, $this->conf['forgotErrorMessage_stdWrap.']);
270 } else {
271 $markerArray['###STATUS_MESSAGE###'] = $this->cObj->stdWrap(
272 $this->pi_getLL('forgot_reset_message_emailSent'),
273 $this->conf['forgotResetMessageEmailSentMessage_stdWrap.']
274 );
275 }
276 $subpartArray['###FORGOT_FORM###'] = '';
277 } else {
278 // Wrong email
279 $markerArray['###STATUS_MESSAGE###'] = $this->getDisplayText('forgot_reset_message', $this->conf['forgotMessage_stdWrap.']);
280 $markerArray['###BACKLINK_LOGIN###'] = '';
281 }
282 } else {
283 $markerArray['###STATUS_MESSAGE###'] = $this->getDisplayText('forgot_reset_message', $this->conf['forgotMessage_stdWrap.']);
284 $markerArray['###BACKLINK_LOGIN###'] = '';
285 }
286 $markerArray['###BACKLINK_LOGIN###'] = $this->getPageLink(htmlspecialchars($this->pi_getLL('forgot_header_backToLogin')), []);
287 $markerArray['###STATUS_HEADER###'] = $this->getDisplayText('forgot_header', $this->conf['forgotHeader_stdWrap.']);
288 $markerArray['###LEGEND###'] = htmlspecialchars($this->pi_getLL('legend', $this->pi_getLL('reset_password')));
289 $markerArray['###ACTION_URI###'] = $this->getPageLink('', [$this->prefixId . '[forgot]' => 1], true);
290 $markerArray['###EMAIL_LABEL###'] = htmlspecialchars($this->pi_getLL('your_email'));
291 $markerArray['###FORGOT_PASSWORD_ENTEREMAIL###'] = htmlspecialchars($this->pi_getLL('forgot_password_enterEmail'));
292 $markerArray['###FORGOT_EMAIL###'] = $this->prefixId . '[forgot_email]';
293 $markerArray['###SEND_PASSWORD###'] = htmlspecialchars($this->pi_getLL('reset_password'));
294 $markerArray['###DATA_LABEL###'] = htmlspecialchars($this->pi_getLL('enter_your_data'));
295 $markerArray = array_merge($markerArray, $this->getUserFieldMarkers());
296 // Generate hash
297 $hash = md5($this->generatePassword(3));
298 $markerArray['###FORGOTHASH###'] = $hash;
299 // Set hash in feuser session
300 $this->frontendController->fe_user->setKey('ses', 'forgot_hash', ['forgot_hash' => $hash]);
301 return $this->templateService->substituteMarkerArrayCached($subpart, $markerArray, $subpartArray, $linkpartArray);
302 }
303
304 /**
305 * This function checks the hash from link and checks the validity. If it's valid it shows the form for
306 * changing the password and process the change of password after submit, if not valid it returns the error message
307 *
308 * @return string The content.
309 */
310 protected function changePassword()
311 {
312 $markerArray = [];
313 $subpartArray = ($linkpartArray = []);
314 $done = false;
315 $minLength = (int)$this->conf['newPasswordMinLength'] ?: 6;
316 $subpart = $this->templateService->getSubpart($this->template, '###TEMPLATE_CHANGEPASSWORD###');
317 $markerArray['###STATUS_HEADER###'] = $this->getDisplayText('change_password_header', $this->conf['changePasswordHeader_stdWrap.']);
318 $markerArray['###STATUS_MESSAGE###'] = sprintf($this->getDisplayText(
319 'change_password_message',
320 $this->conf['changePasswordMessage_stdWrap.']
321 ), $minLength);
322
323 $markerArray['###BACKLINK_LOGIN###'] = '';
324 $uid = $this->piVars['user'];
325 $piHash = $this->piVars['forgothash'];
326 $hash = explode('|', rawurldecode($piHash));
327 if ((int)$uid === 0) {
328 $markerArray['###STATUS_MESSAGE###'] = $this->getDisplayText(
329 'change_password_notvalid_message',
330 $this->conf['changePasswordNotValidMessage_stdWrap.']
331 );
332 $subpartArray['###CHANGEPASSWORD_FORM###'] = '';
333 } else {
334 $user = $this->pi_getRecord('fe_users', (int)$uid);
335 $userHash = $user['felogin_forgotHash'];
336 $compareHash = explode('|', $userHash);
337 if (strlen($compareHash[1]) === 40) {
338 $hashEquals = hash_equals($compareHash[1], GeneralUtility::hmac((string)$hash[1]));
339 } else {
340 // backward-compatibility for previous MD5 hashes
341 $hashEquals = hash_equals($compareHash[1], md5($hash[1]));
342 }
343 if (!$compareHash || !$compareHash[1] || $compareHash[0] < time() || !hash_equals($compareHash[0], $hash[0]) || !$hashEquals) {
344 $markerArray['###STATUS_MESSAGE###'] = $this->getDisplayText(
345 'change_password_notvalid_message',
346 $this->conf['changePasswordNotValidMessage_stdWrap.']
347 );
348 $subpartArray['###CHANGEPASSWORD_FORM###'] = '';
349 } else {
350 // All is fine, continue with new password
351 $postData = GeneralUtility::_POST($this->prefixId);
352 if (isset($postData['changepasswordsubmit'])) {
353 if (strlen($postData['password1']) < $minLength) {
354 $markerArray['###STATUS_MESSAGE###'] = sprintf(
355 $this->getDisplayText(
356 'change_password_tooshort_message',
357 $this->conf['changePasswordTooShortMessage_stdWrap.']
358 ),
359 $minLength
360 );
361 } elseif ($postData['password1'] != $postData['password2']) {
362 $markerArray['###STATUS_MESSAGE###'] = sprintf(
363 $this->getDisplayText(
364 'change_password_notequal_message',
365 $this->conf['changePasswordNotEqualMessage_stdWrap.']
366 ),
367 $minLength
368 );
369 } else {
370 // Hash password using configured salted passwords hash mechanism for FE
371 $hashInstance = GeneralUtility::makeInstance(PasswordHashFactory::class)->getDefaultHashInstance('FE');
372 $newPass = $hashInstance->getHashedPassword($postData['password1']);
373
374 // Call a hook for further password processing
375 $hookPasswordValid = true;
376 if ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['felogin']['password_changed']) {
377 $_params = [
378 'user' => $user,
379 'newPassword' => $newPass,
380 'newPasswordUnencrypted' => $postData['password1'],
381 'passwordValid' => true,
382 'passwordInvalidMessage' => '',
383 ];
384 foreach ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['felogin']['password_changed'] as $_funcRef) {
385 if ($_funcRef) {
386 GeneralUtility::callUserFunction($_funcRef, $_params, $this);
387 }
388 }
389 $newPass = $_params['newPassword'];
390 $hookPasswordValid = $_params['passwordValid'];
391
392 if (!$hookPasswordValid) {
393 $markerArray['###STATUS_MESSAGE###'] = $_params['passwordInvalidMessage'];
394 }
395 }
396
397 // Change Password only if Hook returns valid
398 if ($hookPasswordValid) {
399 // Save new password and clear DB-hash
400 $userTable = $this->frontendController->fe_user->user_table;
401 $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable($userTable);
402 $queryBuilder->getRestrictions()->removeAll();
403 $queryBuilder->update($userTable)
404 ->set('password', $newPass)
405 ->set('felogin_forgotHash', '')
406 ->set('tstamp', (int)$GLOBALS['EXEC_TIME'])
407 ->where(
408 $queryBuilder->expr()->eq(
409 'uid',
410 $queryBuilder->createNamedParameter($user['uid'], \PDO::PARAM_INT)
411 )
412 )
413 ->execute();
414 $this->invalidateUserSessions((int)$user['uid']);
415
416 $markerArray['###STATUS_MESSAGE###'] = $this->getDisplayText(
417 'change_password_done_message',
418 $this->conf['changePasswordDoneMessage_stdWrap.']
419 );
420 $done = true;
421 $subpartArray['###CHANGEPASSWORD_FORM###'] = '';
422 $markerArray['###BACKLINK_LOGIN###'] = $this->getPageLink(
423 htmlspecialchars($this->pi_getLL('forgot_header_backToLogin')),
424 [$this->prefixId . '[redirectReferrer]' => 'off']
425 );
426 }
427 }
428 }
429 if (!$done) {
430 // Change password form
431 $markerArray['###ACTION_URI###'] = $this->getPageLink('', [
432 $this->prefixId . '[user]' => $user['uid'],
433 $this->prefixId . '[forgothash]' => $piHash
434 ], true);
435 $markerArray['###LEGEND###'] = htmlspecialchars($this->pi_getLL('change_password'));
436 $markerArray['###NEWPASSWORD1_LABEL###'] = htmlspecialchars($this->pi_getLL('newpassword_label1'));
437 $markerArray['###NEWPASSWORD2_LABEL###'] = htmlspecialchars($this->pi_getLL('newpassword_label2'));
438 $markerArray['###NEWPASSWORD1###'] = $this->prefixId . '[password1]';
439 $markerArray['###NEWPASSWORD2###'] = $this->prefixId . '[password2]';
440 $markerArray['###STORAGE_PID###'] = $this->spid;
441 $markerArray['###SEND_PASSWORD###'] = htmlspecialchars($this->pi_getLL('change_password'));
442 $markerArray['###FORGOTHASH###'] = $piHash;
443 }
444 }
445 }
446 return $this->templateService->substituteMarkerArrayCached($subpart, $markerArray, $subpartArray, $linkpartArray);
447 }
448
449 /**
450 * Generates a hashed link and send it with email
451 *
452 * @param array $user Contains user data
453 * @return string Empty string with success, error message with no success
454 */
455 protected function generateAndSendHash($user)
456 {
457 $hours = (int)$this->conf['forgotLinkHashValidTime'] > 0 ? (int)$this->conf['forgotLinkHashValidTime'] : 24;
458 $validEnd = time() + 3600 * $hours;
459 $validEndString = date($this->conf['dateFormat'], $validEnd);
460 $hash = md5(GeneralUtility::makeInstance(Random::class)->generateRandomBytes(64));
461 $randHash = $validEnd . '|' . $hash;
462 $randHashDB = $validEnd . '|' . GeneralUtility::hmac($hash);
463
464 // Write hash to DB
465 $userTable = $this->frontendController->fe_user->user_table;
466 $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable($userTable);
467 $queryBuilder->getRestrictions()->removeAll();
468 $queryBuilder->update($userTable)
469 ->set('felogin_forgotHash', $randHashDB)
470 ->where(
471 $queryBuilder->expr()->eq(
472 'uid',
473 $queryBuilder->createNamedParameter($user['uid'], \PDO::PARAM_INT)
474 )
475 )
476 ->execute();
477
478 // Send hashlink to user
479 $this->conf['linkPrefix'] = -1;
480 $isAbsRefPrefix = !empty($this->frontendController->absRefPrefix);
481 $isBaseURL = !empty($this->frontendController->baseUrl);
482 $isFeloginBaseURL = !empty($this->conf['feloginBaseURL']);
483 $link = $this->pi_getPageLink($this->frontendController->id, '', [
484 $this->prefixId . '[user]' => $user['uid'],
485 $this->prefixId . '[forgothash]' => $randHash
486 ]);
487 // Prefix link if necessary
488 if ($isFeloginBaseURL) {
489 // First priority, use specific base URL
490 // "absRefPrefix" must be removed first, otherwise URL will be prepended twice
491 if ($isAbsRefPrefix) {
492 $link = substr($link, strlen($this->frontendController->absRefPrefix));
493 }
494 $link = $this->conf['feloginBaseURL'] . $link;
495 } elseif ($isAbsRefPrefix) {
496 // Second priority
497 // absRefPrefix must not necessarily contain a hostname and URL scheme, so add it if needed
498 $link = GeneralUtility::locationHeaderUrl($link);
499 } elseif ($isBaseURL) {
500 // Third priority
501 // Add the global base URL to the link
502 $link = $this->frontendController->baseUrlWrap($link);
503 } else {
504 // No prefix is set, return the error
505 return $this->pi_getLL('change_password_nolinkprefix_message');
506 }
507 $msg = sprintf($this->pi_getLL('forgot_validate_reset_password'), $user['username'], $link, $validEndString);
508 // Add hook for extra processing of mail message
509 $params = [
510 'message' => &$msg,
511 'user' => &$user
512 ];
513 foreach ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['felogin']['forgotPasswordMail'] ?? [] as $reference) {
514 if ($reference) {
515 GeneralUtility::callUserFunction($reference, $params, $this);
516 }
517 }
518 if ($user['email']) {
519 $this->sendMail($msg, $user['email'], '', $this->conf['email_from'] ?? '', $this->conf['email_fromName'] ?? '', $this->conf['replyTo'] ?? '');
520 }
521
522 return '';
523 }
524
525 /**
526 * Shows logout form
527 *
528 * @return string The content.
529 */
530 protected function showLogout()
531 {
532 $markerArray = [];
533 $subpart = $this->templateService->getSubpart($this->template, '###TEMPLATE_LOGOUT###');
534 $subpartArray = ($linkpartArray = []);
535 $markerArray['###STATUS_HEADER###'] = $this->getDisplayText('status_header', $this->conf['logoutHeader_stdWrap.']);
536 $markerArray['###STATUS_MESSAGE###'] = $this->getDisplayText('status_message', $this->conf['logoutMessage_stdWrap.']);
537 $this->cObj->stdWrap($this->flexFormValue('message', 's_status'), $this->conf['logoutMessage_stdWrap.']);
538 $markerArray['###LEGEND###'] = htmlspecialchars($this->pi_getLL('logout'));
539 $markerArray['###ACTION_URI###'] = $this->getPageLink('', [], true);
540 $markerArray['###LOGOUT_LABEL###'] = htmlspecialchars($this->pi_getLL('logout'));
541 $markerArray['###NAME###'] = htmlspecialchars($this->frontendController->fe_user->user['name']);
542 $markerArray['###STORAGE_PID###'] = $this->spid;
543 $markerArray['###USERNAME###'] = htmlspecialchars($this->frontendController->fe_user->user['username']);
544 $markerArray['###USERNAME_LABEL###'] = htmlspecialchars($this->pi_getLL('username'));
545 $markerArray['###NOREDIRECT###'] = $this->noRedirect ? '1' : '0';
546 $markerArray['###PREFIXID###'] = $this->prefixId;
547 $markerArray = array_merge($markerArray, $this->getUserFieldMarkers());
548 if ($this->redirectUrl) {
549 // Use redirectUrl for action tag because of possible access restricted pages
550 $markerArray['###ACTION_URI###'] = htmlspecialchars($this->redirectUrl);
551 $this->redirectUrl = '';
552 }
553 return $this->templateService->substituteMarkerArrayCached($subpart, $markerArray, $subpartArray, $linkpartArray);
554 }
555
556 /**
557 * Shows login form
558 *
559 * @return string Content
560 */
561 protected function showLogin()
562 {
563 $subpart = $this->templateService->getSubpart($this->template, '###TEMPLATE_LOGIN###');
564 $subpartArray = ($linkpartArray = ($markerArray = []));
565 $gpRedirectUrl = '';
566 $markerArray['###LEGEND###'] = htmlspecialchars($this->pi_getLL('oLabel_header_welcome'));
567 if ($this->logintype === LoginType::LOGIN) {
568 if ($this->userIsLoggedIn) {
569 // login success
570 $markerArray['###STATUS_HEADER###'] = $this->getDisplayText('success_header', $this->conf['successHeader_stdWrap.']);
571 $markerArray['###STATUS_MESSAGE###'] = $this->getDisplayText('success_message', $this->conf['successMessage_stdWrap.']);
572 $markerArray = array_merge($markerArray, $this->getUserFieldMarkers());
573 $subpartArray['###LOGIN_FORM###'] = '';
574 // Hook for general actions after after login has been confirmed (by Thomas Danzl <thomas@danzl.org>)
575 foreach ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['felogin']['login_confirmed'] ?? [] as $_funcRef) {
576 $_params = [];
577 if ($_funcRef) {
578 GeneralUtility::callUserFunction($_funcRef, $_params, $this);
579 }
580 }
581 // show logout form directly
582 if ($this->conf['showLogoutFormAfterLogin']) {
583 $this->redirectUrl = '';
584 return $this->showLogout();
585 }
586 } else {
587 // Hook for general actions on login error
588 $params = [];
589 foreach ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['felogin']['login_error'] ?? [] as $funcRef) {
590 if ($funcRef) {
591 GeneralUtility::callUserFunction($funcRef, $params, $this);
592 }
593 }
594 // login error
595 $markerArray['###STATUS_HEADER###'] = $this->getDisplayText('error_header', $this->conf['errorHeader_stdWrap.']);
596 $markerArray['###STATUS_MESSAGE###'] = $this->getDisplayText('error_message', $this->conf['errorMessage_stdWrap.']);
597 $gpRedirectUrl = GeneralUtility::_GP('redirect_url');
598 }
599 } else {
600 if ($this->logintype === LoginType::LOGOUT) {
601 // login form after logout
602 $markerArray['###STATUS_HEADER###'] = $this->getDisplayText('logout_header', $this->conf['logoutHeader_stdWrap.']);
603 $markerArray['###STATUS_MESSAGE###'] = $this->getDisplayText('logout_message', $this->conf['logoutMessage_stdWrap.']);
604 } else {
605 // login form
606 $markerArray['###STATUS_HEADER###'] = $this->getDisplayText('welcome_header', $this->conf['welcomeHeader_stdWrap.']);
607 $markerArray['###STATUS_MESSAGE###'] = $this->getDisplayText('welcome_message', $this->conf['welcomeMessage_stdWrap.']);
608 }
609 }
610
611 // This hook allows to call User JS functions.
612 // The methods should also set the required JS functions to get included
613 $onSubmit = '';
614 $extraHidden = '';
615 $onSubmitAr = [];
616 $extraHiddenAr = [];
617 // Check for referer redirect method. if present, save referer in form field
618 if (GeneralUtility::inList($this->conf['redirectMode'], 'referer') || GeneralUtility::inList($this->conf['redirectMode'], 'refererDomains')) {
619 $referer = $this->referer ?: GeneralUtility::getIndpEnv('HTTP_REFERER');
620 if ($referer) {
621 $extraHiddenAr[] = '<input type="hidden" name="referer" value="' . htmlspecialchars($referer) . '" />';
622 if ($this->piVars['redirectReferrer'] === 'off') {
623 $extraHiddenAr[] = '<input type="hidden" name="' . $this->prefixId . '[redirectReferrer]" value="off" />';
624 }
625 }
626 }
627 $_params = [];
628 foreach ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['felogin']['loginFormOnSubmitFuncs'] ?? [] as $funcRef) {
629 [$onSub, $hid] = GeneralUtility::callUserFunction($funcRef, $_params, $this);
630 $onSubmitAr[] = $onSub;
631 $extraHiddenAr[] = $hid;
632 }
633 if (!empty($onSubmitAr)) {
634 $onSubmit = implode('; ', $onSubmitAr) . '; return true;';
635 }
636 if (!empty($extraHiddenAr)) {
637 $extraHidden = implode(LF, $extraHiddenAr);
638 }
639 if (!$gpRedirectUrl && $this->redirectUrl) {
640 $gpRedirectUrl = $this->redirectUrl;
641 }
642 // Login form
643 $markerArray['###ACTION_URI###'] = $this->getPageLink('', [], true);
644 // Used by kb_md5fepw extension...
645 $markerArray['###EXTRA_HIDDEN###'] = $extraHidden;
646 $markerArray['###LEGEND###'] = htmlspecialchars($this->pi_getLL('login'));
647 $markerArray['###LOGIN_LABEL###'] = htmlspecialchars($this->pi_getLL('login'));
648 // Used by kb_md5fepw extension...
649 $markerArray['###ON_SUBMIT###'] = $onSubmit;
650 $markerArray['###PASSWORD_LABEL###'] = htmlspecialchars($this->pi_getLL('password'));
651 $markerArray['###STORAGE_PID###'] = $this->spid;
652 $markerArray['###USERNAME_LABEL###'] = htmlspecialchars($this->pi_getLL('username'));
653 $markerArray['###REDIRECT_URL###'] = htmlspecialchars($gpRedirectUrl);
654 $markerArray['###NOREDIRECT###'] = $this->noRedirect ? '1' : '0';
655 $markerArray['###PREFIXID###'] = $this->prefixId;
656 $markerArray = array_merge($markerArray, $this->getUserFieldMarkers());
657 if ($this->conf['showForgotPasswordLink']) {
658 $linkpartArray['###FORGOT_PASSWORD_LINK###'] = explode('|', $this->getPageLink('|', [$this->prefixId . '[forgot]' => 1]));
659 $markerArray['###FORGOT_PASSWORD###'] = htmlspecialchars($this->pi_getLL('forgot_header'));
660 } else {
661 $subpartArray['###FORGOTP_VALID###'] = '';
662 }
663 // The permanent login checkbox should only be shown if permalogin is not deactivated (-1),
664 // not forced to be always active (2) and lifetime is greater than 0
665 $permalogin = (int)$GLOBALS['TYPO3_CONF_VARS']['FE']['permalogin'];
666 if (
667 $this->conf['showPermaLogin']
668 && ($permalogin === 0 || $permalogin === 1)
669 && $GLOBALS['TYPO3_CONF_VARS']['FE']['lifetime'] > 0
670 ) {
671 $markerArray['###PERMALOGIN###'] = htmlspecialchars($this->pi_getLL('permalogin'));
672 if ($permalogin === 1) {
673 $markerArray['###PERMALOGIN_HIDDENFIELD_ATTRIBUTES###'] = 'disabled="disabled"';
674 $markerArray['###PERMALOGIN_CHECKBOX_ATTRIBUTES###'] = 'checked="checked"';
675 } else {
676 $markerArray['###PERMALOGIN_HIDDENFIELD_ATTRIBUTES###'] = '';
677 $markerArray['###PERMALOGIN_CHECKBOX_ATTRIBUTES###'] = '';
678 }
679 } else {
680 $subpartArray['###PERMALOGIN_VALID###'] = '';
681 }
682 return $this->templateService->substituteMarkerArrayCached($subpart, $markerArray, $subpartArray, $linkpartArray);
683 }
684
685 /**
686 * Process redirect methods. The function searches for a redirect url using all configured methods.
687 *
688 * @return array Redirect URLs
689 */
690 protected function processRedirect()
691 {
692 $redirect_url = [];
693 if ($this->conf['redirectMode']) {
694 $redirectMethods = GeneralUtility::trimExplode(',', $this->conf['redirectMode'], true);
695 foreach ($redirectMethods as $redirMethod) {
696 if ($this->userIsLoggedIn && $this->logintype === LoginType::LOGIN) {
697 // Logintype is needed because the login-page wouldn't be accessible anymore after a login (would always redirect)
698 switch ($redirMethod) {
699 case 'groupLogin':
700 // taken from dkd_redirect_at_login written by Ingmar Schlecht; database-field changed
701 $groupData = $this->frontendController->fe_user->groupData;
702 if (!empty($groupData['uid'])) {
703
704 // take the first group with a redirect page
705 $userGroupTable = $this->frontendController->fe_user->usergroup_table;
706 $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable($userGroupTable);
707 $queryBuilder->getRestrictions()->removeAll();
708 $row = $queryBuilder
709 ->select('felogin_redirectPid')
710 ->from($userGroupTable)
711 ->where(
712 $queryBuilder->expr()->neq(
713 'felogin_redirectPid',
714 $queryBuilder->createNamedParameter('', \PDO::PARAM_STR)
715 ),
716 $queryBuilder->expr()->in(
717 'uid',
718 $queryBuilder->createNamedParameter(
719 $groupData['uid'],
720 Connection::PARAM_INT_ARRAY
721 )
722 )
723 )
724 ->execute()
725 ->fetch();
726
727 if ($row) {
728 $redirect_url[] = $this->pi_getPageLink($row['felogin_redirectPid']);
729 }
730 }
731 break;
732 case 'userLogin':
733
734 $userTable = $this->frontendController->fe_user->user_table;
735 $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable($userTable);
736 $queryBuilder->getRestrictions()->removeAll();
737 $row = $queryBuilder
738 ->select('felogin_redirectPid')
739 ->from($userTable)
740 ->where(
741 $queryBuilder->expr()->neq(
742 'felogin_redirectPid',
743 $queryBuilder->createNamedParameter('', \PDO::PARAM_STR)
744 ),
745 $queryBuilder->expr()->eq(
746 $this->frontendController->fe_user->userid_column,
747 $queryBuilder->createNamedParameter(
748 $this->frontendController->fe_user->user['uid'],
749 \PDO::PARAM_INT
750 )
751 )
752 )
753 ->execute()
754 ->fetch();
755
756 if ($row) {
757 $redirect_url[] = $this->pi_getPageLink($row['felogin_redirectPid']);
758 }
759
760 break;
761 case 'login':
762 if ($this->conf['redirectPageLogin']) {
763 $redirect_url[] = $this->pi_getPageLink((int)$this->conf['redirectPageLogin']);
764 }
765 break;
766 case 'getpost':
767 $redirect_url[] = $this->redirectUrl;
768 break;
769 case 'referer':
770 // Avoid redirect when logging in after changing password
771 if ($this->piVars['redirectReferrer'] !== 'off') {
772 // Avoid forced logout, when trying to login immediately after a logout
773 $redirect_url[] = preg_replace('/[&?]logintype=[a-z]+/', '', $this->referer);
774 }
775 break;
776 case 'refererDomains':
777 // Auto redirect.
778 // Feature to redirect to the page where the user came from (HTTP_REFERER).
779 // Allowed domains to redirect to, can be configured with plugin.tx_felogin_pi1.domains
780 // Thanks to plan2.net / Martin Kutschker for implementing this feature.
781 // also avoid redirect when logging in after changing password
782 if (isset($this->conf['domains']) && $this->conf['domains']
783 && (!isset($this->piVars['redirectReferrer']) || $this->piVars['redirectReferrer'] !== 'off')
784 ) {
785 $url = $this->referer;
786 // Is referring url allowed to redirect?
787 $match = [];
788 if (preg_match('#^http://([[:alnum:]._-]+)/#', $url, $match)) {
789 $redirect_domain = $match[1];
790 $found = false;
791 foreach (GeneralUtility::trimExplode(',', $this->conf['domains'], true) as $d) {
792 if (preg_match('/(?:^|\\.)' . $d . '$/', $redirect_domain)) {
793 $found = true;
794 break;
795 }
796 }
797 if (!$found) {
798 $url = '';
799 }
800 }
801 // Avoid forced logout, when trying to login immediately after a logout
802 if ($url) {
803 $redirect_url[] = preg_replace('/[&?]logintype=[a-z]+/', '', $url);
804 }
805 }
806 break;
807 }
808 } elseif ($this->logintype === LoginType::LOGIN) {
809 // after login-error
810 switch ($redirMethod) {
811 case 'loginError':
812 if ($this->conf['redirectPageLoginError']) {
813 $redirect_url[] = $this->pi_getPageLink((int)$this->conf['redirectPageLoginError']);
814 }
815 break;
816 }
817 } elseif ($this->logintype == '' && $redirMethod === 'login' && $this->conf['redirectPageLogin']) {
818 // If login and page not accessible
819 $this->cObj->typoLink('', [
820 'parameter' => $this->conf['redirectPageLogin'],
821 'linkAccessRestrictedPages' => true
822 ]);
823 $redirect_url[] = $this->cObj->lastTypoLinkUrl;
824 } elseif ($this->logintype == '' && $redirMethod === 'logout' && $this->conf['redirectPageLogout'] && $this->userIsLoggedIn) {
825 // If logout and page not accessible
826 $redirect_url[] = $this->pi_getPageLink((int)$this->conf['redirectPageLogout']);
827 } elseif ($this->logintype === LoginType::LOGOUT) {
828 // after logout
829 // Hook for general actions after after logout has been confirmed
830 foreach ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['felogin']['logout_confirmed'] ?? [] as $_funcRef) {
831 $_params = [];
832 if ($_funcRef) {
833 GeneralUtility::callUserFunction($_funcRef, $_params, $this);
834 }
835 }
836 switch ($redirMethod) {
837 case 'logout':
838 if ($this->conf['redirectPageLogout']) {
839 $redirect_url[] = $this->pi_getPageLink((int)$this->conf['redirectPageLogout']);
840 }
841 break;
842 }
843 } else {
844 // not logged in
845 // Placeholder for maybe future options
846 switch ($redirMethod) {
847 case 'getpost':
848 // Preserve the get/post value
849 $redirect_url[] = $this->redirectUrl;
850 break;
851 }
852 }
853 }
854 }
855 // Remove empty values, but keep "0" as value (that's why "strlen" is used as second parameter)
856 if (!empty($redirect_url)) {
857 return array_filter($redirect_url, 'strlen');
858 }
859 return [];
860 }
861
862 /**
863 * Reads flexform configuration and merge it with $this->conf
864 */
865 protected function mergeflexFormValuesIntoConf()
866 {
867 $flex = [];
868 if ($this->flexFormValue('showForgotPassword', 'sDEF')) {
869 $flex['showForgotPasswordLink'] = $this->flexFormValue('showForgotPassword', 'sDEF');
870 }
871 if ($this->flexFormValue('showPermaLogin', 'sDEF')) {
872 $flex['showPermaLogin'] = $this->flexFormValue('showPermaLogin', 'sDEF');
873 }
874 if ($this->flexFormValue('showLogoutFormAfterLogin', 'sDEF')) {
875 $flex['showLogoutFormAfterLogin'] = $this->flexFormValue('showLogoutFormAfterLogin', 'sDEF');
876 }
877 if ($this->flexFormValue('pages', 'sDEF')) {
878 $flex['pages'] = $this->flexFormValue('pages', 'sDEF');
879 }
880 if ($this->flexFormValue('recursive', 'sDEF')) {
881 $flex['recursive'] = $this->flexFormValue('recursive', 'sDEF');
882 }
883 if ($this->flexFormValue('redirectMode', 's_redirect')) {
884 $flex['redirectMode'] = $this->flexFormValue('redirectMode', 's_redirect');
885 }
886 if ($this->flexFormValue('redirectFirstMethod', 's_redirect')) {
887 $flex['redirectFirstMethod'] = $this->flexFormValue('redirectFirstMethod', 's_redirect');
888 }
889 if ($this->flexFormValue('redirectDisable', 's_redirect')) {
890 $flex['redirectDisable'] = $this->flexFormValue('redirectDisable', 's_redirect');
891 }
892 if ($this->flexFormValue('redirectPageLogin', 's_redirect')) {
893 $flex['redirectPageLogin'] = $this->flexFormValue('redirectPageLogin', 's_redirect');
894 }
895 if ($this->flexFormValue('redirectPageLoginError', 's_redirect')) {
896 $flex['redirectPageLoginError'] = $this->flexFormValue('redirectPageLoginError', 's_redirect');
897 }
898 if ($this->flexFormValue('redirectPageLogout', 's_redirect')) {
899 $flex['redirectPageLogout'] = $this->flexFormValue('redirectPageLogout', 's_redirect');
900 }
901 $pid = $flex['pages'] ? $this->pi_getPidList($flex['pages'], $flex['recursive']) : 0;
902 if ($pid > 0) {
903 $flex['storagePid'] = $pid;
904 }
905 $this->conf = array_merge($this->conf, $flex);
906 }
907
908 /**
909 * Loads a variable from the flexform
910 *
911 * @param string $var Name of variable
912 * @param string $sheet Name of sheet
913 * @return string Value of var
914 */
915 protected function flexFormValue($var, $sheet)
916 {
917 return $this->pi_getFFvalue($this->cObj->data['pi_flexform'], 'settings.' . $var, $sheet);
918 }
919
920 /**
921 * Generate link with typolink function
922 *
923 * @param string $label Linktext
924 * @param array $piVars Link vars
925 * @param bool $returnUrl TRUE: returns only url FALSE (default) returns the link)
926 * @return string Link or url
927 */
928 protected function getPageLink($label, $piVars, $returnUrl = false)
929 {
930 $additionalParams = is_array($piVars) && !empty($piVars) ? $piVars : [];
931 // Should GETvars be preserved?
932 if ($this->conf['preserveGETvars']) {
933 $additionalParams = array_merge_recursive($additionalParams, $this->getPreserveGetVars());
934 }
935 $this->conf['linkConfig.']['parameter'] = $this->frontendController->id;
936 if (!empty($additionalParams)) {
937 $this->conf['linkConfig.']['additionalParams'] = HttpUtility::buildQueryString($additionalParams, '&');
938 }
939 if ($returnUrl) {
940 return htmlspecialchars($this->cObj->typoLink_URL($this->conf['linkConfig.']));
941 }
942 return $this->cObj->typoLink($label, $this->conf['linkConfig.']);
943 }
944
945 /**
946 * Add additional parameters for links according to TS setting preserveGETvars.
947 * Possible values are "all" or a comma separated list of allowed GET-vars.
948 * Supports multi-dimensional GET-vars.
949 * Some hardcoded values are dropped.
950 *
951 * @return array additionalParams-array
952 */
953 protected function getPreserveGetVars()
954 {
955 $getVars = GeneralUtility::_GET();
956 unset(
957 $getVars['id'],
958 $getVars['no_cache'],
959 $getVars['logintype'],
960 $getVars['redirect_url'],
961 $getVars['cHash'],
962 $getVars[$this->prefixId]
963 );
964 if ($this->conf['preserveGETvars'] === 'all') {
965 $preserveQueryParts = $getVars;
966 } else {
967 $preserveQueryStringProperties = GeneralUtility::trimExplode(',', $this->conf['preserveGETvars']);
968 $preserveQueryParts = [];
969 parse_str(implode('=1&', $preserveQueryStringProperties) . '=1', $preserveQueryParts);
970 $preserveQueryParts = \TYPO3\CMS\Core\Utility\ArrayUtility::intersectRecursive($getVars, $preserveQueryParts);
971 }
972 return $preserveQueryParts;
973 }
974
975 /**
976 * Is used by forgot password - function with md5 option.
977 * @param int $len Length of new password
978 * @return string New password
979 */
980 protected function generatePassword($len)
981 {
982 $pass = '';
983 while ($len--) {
984 $char = random_int(0, 35);
985 if ($char < 10) {
986 $pass .= '' . $char;
987 } else {
988 $pass .= chr($char - 10 + 97);
989 }
990 }
991 return $pass;
992 }
993
994 /**
995 * Returns the header / message value from flexform if present, else from locallang.xlf
996 *
997 * @param string $label label name
998 * @param array $stdWrapArray TS stdWrap array
999 * @return string label text
1000 */
1001 protected function getDisplayText($label, $stdWrapArray = [])
1002 {
1003 $text = $this->flexFormValue($label, 's_messages') ? $this->cObj->stdWrap($this->flexFormValue($label, 's_messages'), $stdWrapArray) : $this->cObj->stdWrap($this->pi_getLL($label), $stdWrapArray);
1004 $replace = $this->getUserFieldMarkers();
1005 return strtr($text, $replace);
1006 }
1007
1008 /**
1009 * Returns Array of markers filled with user fields
1010 *
1011 * @return array Marker array
1012 */
1013 protected function getUserFieldMarkers()
1014 {
1015 $marker = [];
1016 // replace markers with fe_user data
1017 if ($this->frontendController->fe_user->user) {
1018 // All fields of fe_user will be replaced, scheme is ###FEUSER_FIELDNAME###
1019 foreach ($this->frontendController->fe_user->user as $field => $value) {
1020 $conf = $this->conf['userfields.'][$field . '.'] ?? [];
1021 $conf = array_replace_recursive(['htmlSpecialChars' => '1'], $conf);
1022 $marker['###FEUSER_' . strtoupper($field) . '###'] = $this->cObj->stdWrap($value, $conf);
1023 }
1024 // Add ###USER### for compatibility
1025 $marker['###USER###'] = $marker['###FEUSER_USERNAME###'];
1026 }
1027 return $marker;
1028 }
1029
1030 /**
1031 * Invalidate all frontend user sessions by given user id
1032 *
1033 * @param int $userId the user UID
1034 */
1035 protected function invalidateUserSessions(int $userId)
1036 {
1037 $sessionManager = GeneralUtility::makeInstance(SessionManager::class);
1038 $sessionBackend = $sessionManager->getSessionBackend('FE');
1039 $sessionManager->invalidateAllSessionsByUserId($sessionBackend, $userId, $this->frontendController->fe_user);
1040 }
1041
1042 /**
1043 * Sends "forgot password" mail
1044 *
1045 * @param string $message The message content. If blank, no email is sent.
1046 * @param string $recipients Comma list of recipient email addresses
1047 * @param string $cc Email address of recipient of an extra mail. The same mail will be sent ONCE more; not using a CC header but sending twice.
1048 * @param string $senderAddress "From" email address
1049 * @param string $senderName Optional "From" name
1050 * @param string $replyTo Optional "Reply-To" header email address.
1051 * @return bool Returns TRUE if sent
1052 */
1053 protected function sendMail(string $message, string $recipients, string $cc, string $senderAddress, string $senderName = '', string $replyTo = ''): bool
1054 {
1055 if (trim($message) === '') {
1056 return false;
1057 }
1058
1059 $mail = GeneralUtility::makeInstance(MailMessage::class);
1060 $senderName = trim($senderName);
1061 $senderAddress = trim($senderAddress);
1062 if ($senderAddress !== '') {
1063 $mail->from(new Address($senderAddress, $senderName));
1064 }
1065 $parsedReplyTo = MailUtility::parseAddresses($replyTo);
1066 if (!empty($parsedReplyTo)) {
1067 $mail->replyTo($parsedReplyTo);
1068 }
1069 // First line is subject
1070 $messageParts = explode(LF, trim($message), 2);
1071 $subject = trim($messageParts[0]);
1072 $plainMessage = trim($messageParts[1]);
1073 $parsedRecipients = MailUtility::parseAddresses($recipients);
1074 if (!empty($parsedRecipients)) {
1075 $mail->to(...$parsedRecipients)
1076 ->subject($subject)
1077 ->text($plainMessage);
1078 $mail->send();
1079 }
1080 $parsedCc = MailUtility::parseAddresses($cc);
1081 if (!empty($parsedCc)) {
1082 $from = $mail->getFrom();
1083 /** @var MailMessage $mail */
1084 $mail = GeneralUtility::makeInstance(MailMessage::class);
1085 if (!empty($parsedReplyTo)) {
1086 $mail->replyTo($parsedReplyTo);
1087 }
1088 $mail->from($from)
1089 ->to(...$parsedCc)
1090 ->subject($subject)
1091 ->text($plainMessage);
1092 $mail->send();
1093 }
1094 return true;
1095 }
1096 }