‪TYPO3CMS  10.4
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;
29 
33 class ‪RecoveryConfiguration implements LoggerAwareInterface
34 {
35  use LoggerAwareTrait;
36 
40  protected ‪$context;
41 
45  protected ‪$forgotHash;
46 
50  protected ‪$replyTo;
51 
55  protected ‪$sender;
56 
60  protected ‪$settings;
61 
65  protected ‪$mailTemplateName;
66 
70  protected ‪$timestamp;
71 
81  public function ‪__construct(
83  ‪ConfigurationManager $configurationManager,
84  ‪Random $random,
85  ‪HashService $hashService
86  ) {
87  $this->context = ‪$context;
88  $this->settings = $configurationManager->‪getConfiguration(‪ConfigurationManager::CONFIGURATION_TYPE_SETTINGS);
89  $this->forgotHash = $this->‪getLifeTimeTimestamp() . '|' . $this->‪generateHash($random, $hashService);
90  $this->‪resolveFromTypoScript();
91  }
92 
98  public function ‪getForgotHash(): string
99  {
100  return ‪$this->forgotHash;
101  }
102 
109  public function ‪getMailTemplatePaths(): ‪TemplatePaths
110  {
111  $pathArray = array_replace_recursive(
112  [
113  'layoutRootPaths' => ‪$GLOBALS['TYPO3_CONF_VARS']['MAIL']['layoutRootPaths'],
114  'templateRootPaths' => ‪$GLOBALS['TYPO3_CONF_VARS']['MAIL']['templateRootPaths'],
115  'partialRootPaths' => ‪$GLOBALS['TYPO3_CONF_VARS']['MAIL']['partialRootPaths']
116  ],
117  [
118  'layoutRootPaths' => $this->settings['email']['layoutRootPaths'],
119  'templateRootPaths' => $this->settings['email']['templateRootPaths'],
120  'partialRootPaths' => $this->settings['email']['partialRootPaths']
121  ]
122  );
123 
124  return new ‪TemplatePaths($pathArray);
125  }
126 
132  public function ‪getMailTemplateName(): string
133  {
135  }
136 
142  public function ‪getLifeTimeTimestamp(): int
143  {
144  if ($this->timestamp === null) {
145  $lifetimeInHours = $this->settings['forgotLinkHashValidTime'] ?: 12;
146  $currentTimestamp = $this->context->getPropertyFromAspect('date', 'timestamp');
147  $this->timestamp = $currentTimestamp + 3600 * $lifetimeInHours;
148  }
149 
150  return ‪$this->timestamp;
151  }
152 
158  public function ‪getReplyTo(): ?Address
159  {
160  return ‪$this->replyTo;
161  }
162 
168  public function ‪getSender(): Address
169  {
170  return ‪$this->sender;
171  }
172 
173  protected function ‪generateHash(‪Random $random, ‪HashService $hashService): string
174  {
175  $randomString = $random->‪generateRandomHexString(16);
176 
177  return $hashService->‪generateHmac($randomString);
178  }
179 
180  protected function ‪resolveFromTypoScript(): void
181  {
182  $fromAddress = $this->settings['email_from'] ?: ‪$GLOBALS['TYPO3_CONF_VARS']['MAIL']['defaultMailFromAddress'];
183  if (empty($fromAddress)) {
185  'Either "$GLOBALS[\'TYPO3_CONF_VARS\'][\'MAIL\'][\'defaultMailFromAddress\']" or extension key "plugin.tx_felogin_login.settings.email_from" cannot be empty!',
186  1573825624
187  );
188  }
189  $fromName = $this->settings['email_fromName'] ?: ‪$GLOBALS['TYPO3_CONF_VARS']['MAIL']['defaultMailFromName'];
190  if (empty($fromName)) {
191  throw new IncompleteConfigurationException(
192  'Either "$GLOBALS[\'TYPO3_CONF_VARS\'][\'MAIL\'][\'defaultMailFromName\']" or extension key "plugin.tx_felogin_login.settings.email_fromName" cannot be empty!',
193  1573825625
194  );
195  }
196  $this->sender = new Address($fromAddress, $fromName);
197  if (!empty(‪$GLOBALS['TYPO3_CONF_VARS']['MAIL']['defaultMailReplyToAddress'])) {
198  if (‪$GLOBALS['TYPO3_CONF_VARS']['MAIL']['defaultMailReplyToName']) {
199  $this->replyTo = new Address(
200  ‪$GLOBALS['TYPO3_CONF_VARS']['MAIL']['defaultMailReplyToAddress'],
201  ‪$GLOBALS['TYPO3_CONF_VARS']['MAIL']['defaultMailReplyToName']
202  );
203  } else {
204  $this->replyTo = new Address(
205  ‪$GLOBALS['TYPO3_CONF_VARS']['MAIL']['defaultMailReplyToAddress']
206  );
207  }
208  }
209  $this->mailTemplateName = $this->settings['email']['templateName'];
210  if (empty($this->mailTemplateName)) {
211  throw new IncompleteConfigurationException(
212  'Key "plugin.tx_felogin_login.settings.email.templateName" cannot be empty!',
213  1584998393
214  );
215  }
216  }
217 }
‪TYPO3\CMS\FrontendLogin\Configuration\RecoveryConfiguration\$forgotHash
‪string $forgotHash
Definition: RecoveryConfiguration.php:43
‪TYPO3\CMS\FrontendLogin\Configuration\RecoveryConfiguration\getReplyTo
‪Address null getReplyTo()
Definition: RecoveryConfiguration.php:151
‪TYPO3\CMS\Fluid\View\TemplatePaths
Definition: TemplatePaths.php:35
‪TYPO3\CMS\FrontendLogin\Configuration\RecoveryConfiguration\$sender
‪Address $sender
Definition: RecoveryConfiguration.php:51
‪TYPO3\CMS\FrontendLogin\Configuration\RecoveryConfiguration\getMailTemplateName
‪string getMailTemplateName()
Definition: RecoveryConfiguration.php:125
‪TYPO3\CMS\FrontendLogin\Configuration\RecoveryConfiguration\$replyTo
‪Address null $replyTo
Definition: RecoveryConfiguration.php:47
‪TYPO3\CMS\FrontendLogin\Configuration\RecoveryConfiguration\resolveFromTypoScript
‪resolveFromTypoScript()
Definition: RecoveryConfiguration.php:173
‪TYPO3\CMS\FrontendLogin\Configuration
Definition: IncompleteConfigurationException.php:18
‪TYPO3\CMS\Extbase\Configuration\ConfigurationManager\getConfiguration
‪array getConfiguration(string $configurationType, string $extensionName=null, string $pluginName=null)
Definition: ConfigurationManager.php:113
‪TYPO3\CMS\Core\Crypto\Random\generateRandomHexString
‪string generateRandomHexString(int $length)
Definition: Random.php:54
‪TYPO3\CMS\FrontendLogin\Configuration\RecoveryConfiguration\__construct
‪__construct(Context $context, ConfigurationManager $configurationManager, Random $random, HashService $hashService)
Definition: RecoveryConfiguration.php:74
‪TYPO3\CMS\Extbase\Security\Cryptography\HashService
Definition: HashService.php:31
‪TYPO3\CMS\FrontendLogin\Configuration\RecoveryConfiguration\$settings
‪array $settings
Definition: RecoveryConfiguration.php:55
‪TYPO3\CMS\Core\Context\Context
Definition: Context.php:53
‪TYPO3\CMS\FrontendLogin\Configuration\IncompleteConfigurationException
Definition: IncompleteConfigurationException.php:24
‪TYPO3\CMS\FrontendLogin\Configuration\RecoveryConfiguration\getMailTemplatePaths
‪TemplatePaths getMailTemplatePaths()
Definition: RecoveryConfiguration.php:102
‪TYPO3\CMS\FrontendLogin\Configuration\RecoveryConfiguration\getSender
‪Address getSender()
Definition: RecoveryConfiguration.php:161
‪TYPO3\CMS\Extbase\Configuration\ConfigurationManager
Definition: ConfigurationManager.php:33
‪TYPO3\CMS\FrontendLogin\Configuration\RecoveryConfiguration\$context
‪Context $context
Definition: RecoveryConfiguration.php:39
‪TYPO3\CMS\FrontendLogin\Configuration\RecoveryConfiguration\$mailTemplateName
‪string $mailTemplateName
Definition: RecoveryConfiguration.php:59
‪TYPO3\CMS\FrontendLogin\Configuration\RecoveryConfiguration\generateHash
‪generateHash(Random $random, HashService $hashService)
Definition: RecoveryConfiguration.php:166
‪TYPO3\CMS\FrontendLogin\Configuration\RecoveryConfiguration\getLifeTimeTimestamp
‪int getLifeTimeTimestamp()
Definition: RecoveryConfiguration.php:135
‪TYPO3\CMS\FrontendLogin\Configuration\RecoveryConfiguration
Definition: RecoveryConfiguration.php:34
‪TYPO3\CMS\Extbase\Configuration\Exception\InvalidConfigurationTypeException
Definition: InvalidConfigurationTypeException.php:26
‪TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface\CONFIGURATION_TYPE_SETTINGS
‪const CONFIGURATION_TYPE_SETTINGS
Definition: ConfigurationManagerInterface.php:30
‪TYPO3\CMS\Extbase\Security\Cryptography\HashService\generateHmac
‪string generateHmac(string $string)
Definition: HashService.php:39
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\FrontendLogin\Configuration\RecoveryConfiguration\getForgotHash
‪string getForgotHash()
Definition: RecoveryConfiguration.php:91
‪TYPO3\CMS\Core\Crypto\Random
Definition: Random.php:24
‪TYPO3\CMS\FrontendLogin\Configuration\RecoveryConfiguration\$timestamp
‪int $timestamp
Definition: RecoveryConfiguration.php:63