‪TYPO3CMS  ‪main
RecoveryConfiguration.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
19 
20 use Psr\Log\LoggerAwareInterface;
21 use Psr\Log\LoggerAwareTrait;
22 use Symfony\Component\Mime\Address;
28 
32 class ‪RecoveryConfiguration implements LoggerAwareInterface
33 {
34  use LoggerAwareTrait;
35 
36  protected string ‪$forgotHash;
37  protected ?Address ‪$replyTo = null;
38  protected Address ‪$sender;
39  protected array ‪$settings;
40  protected string ‪$mailTemplateName = '';
41  protected ?int ‪$timestamp = null;
42 
43  public function ‪__construct(
44  protected ‪Context $context,
45  ‪ConfigurationManagerInterface $configurationManager,
46  ‪Random $random,
47  ‪HashService $hashService
48  ) {
50  $this->forgotHash = $this->‪getLifeTimeTimestamp() . '|' . $this->‪generateHash($random, $hashService);
51  $this->‪resolveFromTypoScript();
52  }
53 
57  public function ‪getForgotHash(): string
58  {
59  return ‪$this->forgotHash;
60  }
61 
67  {
68  $pathArray = array_replace_recursive(
69  [
70  'layoutRootPaths' => ‪$GLOBALS['TYPO3_CONF_VARS']['MAIL']['layoutRootPaths'],
71  'templateRootPaths' => ‪$GLOBALS['TYPO3_CONF_VARS']['MAIL']['templateRootPaths'],
72  'partialRootPaths' => ‪$GLOBALS['TYPO3_CONF_VARS']['MAIL']['partialRootPaths'],
73  ],
74  [
75  'layoutRootPaths' => $this->settings['email']['layoutRootPaths'],
76  'templateRootPaths' => $this->settings['email']['templateRootPaths'],
77  'partialRootPaths' => $this->settings['email']['partialRootPaths'],
78  ]
79  );
80 
81  return new ‪TemplatePaths($pathArray);
82  }
83 
87  public function ‪getMailTemplateName(): string
88  {
90  }
91 
95  public function ‪getLifeTimeTimestamp(): int
96  {
97  if ($this->timestamp === null) {
98  $lifetimeInHours = $this->settings['forgotLinkHashValidTime'] ?: 12;
99  $currentTimestamp = $this->context->getPropertyFromAspect('date', 'timestamp');
100  $this->timestamp = $currentTimestamp + 3600 * $lifetimeInHours;
101  }
102 
103  return ‪$this->timestamp;
104  }
105 
109  public function ‪getReplyTo(): ?Address
110  {
111  return ‪$this->replyTo;
112  }
113 
117  public function ‪getSender(): Address
118  {
119  return ‪$this->sender;
120  }
121 
122  protected function ‪generateHash(‪Random $random, ‪HashService $hashService): string
123  {
124  $randomString = $random->‪generateRandomHexString(16);
125 
126  return $hashService->‪hmac($randomString, self::class);
127  }
128 
129  protected function ‪resolveFromTypoScript(): void
130  {
131  $fromAddress = $this->settings['email_from'] ?: ‪$GLOBALS['TYPO3_CONF_VARS']['MAIL']['defaultMailFromAddress'];
132  if (empty($fromAddress)) {
134  'Either "$GLOBALS[\'TYPO3_CONF_VARS\'][\'MAIL\'][\'defaultMailFromAddress\']" or extension key "plugin.tx_felogin_login.settings.email_from" cannot be empty!',
135  1573825624
136  );
137  }
138  $fromName = $this->settings['email_fromName'] ?: ‪$GLOBALS['TYPO3_CONF_VARS']['MAIL']['defaultMailFromName'];
139  if (empty($fromName)) {
141  'Either "$GLOBALS[\'TYPO3_CONF_VARS\'][\'MAIL\'][\'defaultMailFromName\']" or extension key "plugin.tx_felogin_login.settings.email_fromName" cannot be empty!',
142  1573825625
143  );
144  }
145  $this->sender = new Address($fromAddress, $fromName);
146  if (!empty(‪$GLOBALS['TYPO3_CONF_VARS']['MAIL']['defaultMailReplyToAddress'])) {
147  if (‪$GLOBALS['TYPO3_CONF_VARS']['MAIL']['defaultMailReplyToName']) {
148  $this->replyTo = new Address(
149  ‪$GLOBALS['TYPO3_CONF_VARS']['MAIL']['defaultMailReplyToAddress'],
150  ‪$GLOBALS['TYPO3_CONF_VARS']['MAIL']['defaultMailReplyToName']
151  );
152  } else {
153  $this->replyTo = new Address(
154  ‪$GLOBALS['TYPO3_CONF_VARS']['MAIL']['defaultMailReplyToAddress']
155  );
156  }
157  }
158  $this->mailTemplateName = (string)$this->settings['email']['templateName'];
159  if (empty($this->mailTemplateName)) {
161  'Key "plugin.tx_felogin_login.settings.email.templateName" cannot be empty!',
162  1584998393
163  );
164  }
165  }
166 }
‪TYPO3\CMS\FrontendLogin\Configuration\RecoveryConfiguration\$forgotHash
‪string $forgotHash
Definition: RecoveryConfiguration.php:36
‪TYPO3\CMS\Fluid\View\TemplatePaths
Definition: TemplatePaths.php:37
‪TYPO3\CMS\FrontendLogin\Configuration\RecoveryConfiguration\$sender
‪Address $sender
Definition: RecoveryConfiguration.php:38
‪TYPO3\CMS\FrontendLogin\Configuration\RecoveryConfiguration\getSender
‪getSender()
Definition: RecoveryConfiguration.php:117
‪TYPO3\CMS\Core\Crypto\Random\generateRandomHexString
‪generateRandomHexString(int $length)
Definition: Random.php:53
‪TYPO3\CMS\FrontendLogin\Configuration\RecoveryConfiguration\getMailTemplateName
‪getMailTemplateName()
Definition: RecoveryConfiguration.php:87
‪TYPO3\CMS\FrontendLogin\Configuration\RecoveryConfiguration\resolveFromTypoScript
‪resolveFromTypoScript()
Definition: RecoveryConfiguration.php:129
‪TYPO3\CMS\FrontendLogin\Configuration
Definition: IncompleteConfigurationException.php:18
‪TYPO3\CMS\Core\Crypto\HashService\hmac
‪hmac(string $input, string $additionalSecret)
Definition: HashService.php:34
‪TYPO3\CMS\FrontendLogin\Configuration\RecoveryConfiguration\getForgotHash
‪getForgotHash()
Definition: RecoveryConfiguration.php:57
‪TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface
Definition: ConfigurationManagerInterface.php:27
‪TYPO3\CMS\FrontendLogin\Configuration\RecoveryConfiguration\$replyTo
‪Address $replyTo
Definition: RecoveryConfiguration.php:37
‪TYPO3\CMS\FrontendLogin\Configuration\RecoveryConfiguration\$settings
‪array $settings
Definition: RecoveryConfiguration.php:39
‪TYPO3\CMS\Core\Context\Context
Definition: Context.php:54
‪TYPO3\CMS\FrontendLogin\Configuration\IncompleteConfigurationException
Definition: IncompleteConfigurationException.php:23
‪TYPO3\CMS\FrontendLogin\Configuration\RecoveryConfiguration\getLifeTimeTimestamp
‪getLifeTimeTimestamp()
Definition: RecoveryConfiguration.php:95
‪TYPO3\CMS\FrontendLogin\Configuration\RecoveryConfiguration\$mailTemplateName
‪string $mailTemplateName
Definition: RecoveryConfiguration.php:40
‪TYPO3\CMS\FrontendLogin\Configuration\RecoveryConfiguration\generateHash
‪generateHash(Random $random, HashService $hashService)
Definition: RecoveryConfiguration.php:122
‪TYPO3\CMS\FrontendLogin\Configuration\RecoveryConfiguration
Definition: RecoveryConfiguration.php:33
‪TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface\getConfiguration
‪array getConfiguration(string $configurationType, ?string $extensionName=null, ?string $pluginName=null)
‪TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface\CONFIGURATION_TYPE_SETTINGS
‪const CONFIGURATION_TYPE_SETTINGS
Definition: ConfigurationManagerInterface.php:29
‪TYPO3\CMS\FrontendLogin\Configuration\RecoveryConfiguration\getMailTemplatePaths
‪getMailTemplatePaths()
Definition: RecoveryConfiguration.php:66
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:25
‪TYPO3\CMS\Core\Crypto\Random
Definition: Random.php:27
‪TYPO3\CMS\FrontendLogin\Configuration\RecoveryConfiguration\__construct
‪__construct(protected Context $context, ConfigurationManagerInterface $configurationManager, Random $random, HashService $hashService)
Definition: RecoveryConfiguration.php:43
‪TYPO3\CMS\Core\Crypto\HashService
Definition: HashService.php:27
‪TYPO3\CMS\FrontendLogin\Configuration\RecoveryConfiguration\getReplyTo
‪getReplyTo()
Definition: RecoveryConfiguration.php:109
‪TYPO3\CMS\FrontendLogin\Configuration\RecoveryConfiguration\$timestamp
‪int $timestamp
Definition: RecoveryConfiguration.php:41