‪TYPO3CMS  11.5
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 
96  public function ‪getForgotHash(): string
97  {
99  }
100 
105  public function ‪getMailTemplatePaths(): ‪TemplatePaths
106  {
107  $pathArray = array_replace_recursive(
108  [
109  'layoutRootPaths' => ‪$GLOBALS['TYPO3_CONF_VARS']['MAIL']['layoutRootPaths'],
110  'templateRootPaths' => ‪$GLOBALS['TYPO3_CONF_VARS']['MAIL']['templateRootPaths'],
111  'partialRootPaths' => ‪$GLOBALS['TYPO3_CONF_VARS']['MAIL']['partialRootPaths'],
112  ],
113  [
114  'layoutRootPaths' => $this->settings['email']['layoutRootPaths'],
115  'templateRootPaths' => $this->settings['email']['templateRootPaths'],
116  'partialRootPaths' => $this->settings['email']['partialRootPaths'],
117  ]
118  );
119 
120  return new ‪TemplatePaths($pathArray);
121  }
122 
126  public function ‪getMailTemplateName(): string
127  {
129  }
130 
134  public function ‪getLifeTimeTimestamp(): int
135  {
136  if ($this->timestamp === null) {
137  $lifetimeInHours = $this->settings['forgotLinkHashValidTime'] ?: 12;
138  $currentTimestamp = $this->context->getPropertyFromAspect('date', 'timestamp');
139  $this->timestamp = $currentTimestamp + 3600 * $lifetimeInHours;
140  }
141 
142  return ‪$this->timestamp;
143  }
144 
148  public function ‪getReplyTo(): ?Address
149  {
150  return ‪$this->replyTo;
151  }
152 
156  public function ‪getSender(): Address
157  {
158  return ‪$this->sender;
159  }
160 
161  protected function ‪generateHash(‪Random $random, ‪HashService $hashService): string
162  {
163  $randomString = $random->‪generateRandomHexString(16);
164 
165  return $hashService->‪generateHmac($randomString);
166  }
167 
168  protected function ‪resolveFromTypoScript(): void
169  {
170  $fromAddress = $this->settings['email_from'] ?: ‪$GLOBALS['TYPO3_CONF_VARS']['MAIL']['defaultMailFromAddress'];
171  if (empty($fromAddress)) {
173  'Either "$GLOBALS[\'TYPO3_CONF_VARS\'][\'MAIL\'][\'defaultMailFromAddress\']" or extension key "plugin.tx_felogin_login.settings.email_from" cannot be empty!',
174  1573825624
175  );
176  }
177  $fromName = $this->settings['email_fromName'] ?: ‪$GLOBALS['TYPO3_CONF_VARS']['MAIL']['defaultMailFromName'];
178  if (empty($fromName)) {
179  throw new IncompleteConfigurationException(
180  'Either "$GLOBALS[\'TYPO3_CONF_VARS\'][\'MAIL\'][\'defaultMailFromName\']" or extension key "plugin.tx_felogin_login.settings.email_fromName" cannot be empty!',
181  1573825625
182  );
183  }
184  $this->sender = new Address($fromAddress, $fromName);
185  if (!empty(‪$GLOBALS['TYPO3_CONF_VARS']['MAIL']['defaultMailReplyToAddress'])) {
186  if (‪$GLOBALS['TYPO3_CONF_VARS']['MAIL']['defaultMailReplyToName']) {
187  $this->replyTo = new Address(
188  ‪$GLOBALS['TYPO3_CONF_VARS']['MAIL']['defaultMailReplyToAddress'],
189  ‪$GLOBALS['TYPO3_CONF_VARS']['MAIL']['defaultMailReplyToName']
190  );
191  } else {
192  $this->replyTo = new Address(
193  ‪$GLOBALS['TYPO3_CONF_VARS']['MAIL']['defaultMailReplyToAddress']
194  );
195  }
196  }
197  $this->mailTemplateName = $this->settings['email']['templateName'];
198  if (empty($this->mailTemplateName)) {
199  throw new IncompleteConfigurationException(
200  'Key "plugin.tx_felogin_login.settings.email.templateName" cannot be empty!',
201  1584998393
202  );
203  }
204  }
205 }
‪TYPO3\CMS\FrontendLogin\Configuration\RecoveryConfiguration\$forgotHash
‪string $forgotHash
Definition: RecoveryConfiguration.php:43
‪TYPO3\CMS\Fluid\View\TemplatePaths
Definition: TemplatePaths.php:37
‪TYPO3\CMS\FrontendLogin\Configuration\RecoveryConfiguration\$sender
‪Address $sender
Definition: RecoveryConfiguration.php:51
‪TYPO3\CMS\FrontendLogin\Configuration\RecoveryConfiguration\getSender
‪getSender()
Definition: RecoveryConfiguration.php:149
‪TYPO3\CMS\FrontendLogin\Configuration\RecoveryConfiguration\$replyTo
‪Address null $replyTo
Definition: RecoveryConfiguration.php:47
‪TYPO3\CMS\FrontendLogin\Configuration\RecoveryConfiguration\getMailTemplateName
‪getMailTemplateName()
Definition: RecoveryConfiguration.php:119
‪TYPO3\CMS\FrontendLogin\Configuration\RecoveryConfiguration\resolveFromTypoScript
‪resolveFromTypoScript()
Definition: RecoveryConfiguration.php:161
‪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:101
‪TYPO3\CMS\FrontendLogin\Configuration\RecoveryConfiguration\getForgotHash
‪getForgotHash()
Definition: RecoveryConfiguration.php:89
‪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:23
‪TYPO3\CMS\Extbase\Configuration\ConfigurationManager
Definition: ConfigurationManager.php:33
‪TYPO3\CMS\FrontendLogin\Configuration\RecoveryConfiguration\getLifeTimeTimestamp
‪getLifeTimeTimestamp()
Definition: RecoveryConfiguration.php:127
‪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:154
‪TYPO3\CMS\FrontendLogin\Configuration\RecoveryConfiguration
Definition: RecoveryConfiguration.php:34
‪TYPO3\CMS\Extbase\Configuration\Exception\InvalidConfigurationTypeException
Definition: InvalidConfigurationTypeException.php:25
‪TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface\CONFIGURATION_TYPE_SETTINGS
‪const CONFIGURATION_TYPE_SETTINGS
Definition: ConfigurationManagerInterface.php:30
‪TYPO3\CMS\FrontendLogin\Configuration\RecoveryConfiguration\getMailTemplatePaths
‪getMailTemplatePaths()
Definition: RecoveryConfiguration.php:98
‪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:25
‪TYPO3\CMS\Core\Crypto\Random
Definition: Random.php:24
‪TYPO3\CMS\FrontendLogin\Configuration\RecoveryConfiguration\getReplyTo
‪getReplyTo()
Definition: RecoveryConfiguration.php:141
‪TYPO3\CMS\FrontendLogin\Configuration\RecoveryConfiguration\$timestamp
‪int $timestamp
Definition: RecoveryConfiguration.php:63