1
|
|
|
<?php |
2
|
|
|
declare(strict_types=1); |
3
|
|
|
namespace Derhansen\FeChangePwd\Service; |
4
|
|
|
|
5
|
|
|
/* |
6
|
|
|
* This file is part of the Extension "fe_change_pwd" for TYPO3 CMS. |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please read the |
9
|
|
|
* LICENSE.txt file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
use TYPO3\CMS\Core\Utility\GeneralUtility; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* Class SettingsService |
16
|
|
|
*/ |
17
|
|
|
class SettingsService |
18
|
|
|
{ |
19
|
|
|
/** |
20
|
|
|
* @var mixed |
21
|
|
|
*/ |
22
|
|
|
protected $settings = null; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* Returns the settings |
26
|
|
|
* |
27
|
|
|
* @return array |
28
|
|
|
*/ |
29
|
|
|
public function getSettings() |
30
|
|
|
{ |
31
|
|
|
if ($this->settings === null) { |
32
|
|
|
// Ensure, TSFE setup is loaded for cached pages |
33
|
|
|
if ($GLOBALS['TSFE']->tmpl === null || $GLOBALS['TSFE']->tmpl && empty($GLOBALS['TSFE']->tmpl->setup)) { |
34
|
|
|
$GLOBALS['TSFE']->forceTemplateParsing = true; |
35
|
|
|
$GLOBALS['TSFE']->getConfigArray(); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
$settings = $GLOBALS['TSFE']->tmpl->setup['plugin.']['tx_fechangepwd.']['settings.'] ?? []; |
39
|
|
|
$this->settings = GeneralUtility::removeDotsFromTS($settings); |
40
|
|
|
} |
41
|
|
|
return $this->settings; |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* Returns the password expiry timestamp depending on the configured setting switch. If password expiry is not |
46
|
|
|
* enabled, 0 is returned. If no password validity in days is configured, 90 days is taken as fallback |
47
|
|
|
* |
48
|
|
|
* @param null|\DateTime $currentDate |
49
|
|
|
* @return int |
50
|
|
|
*/ |
51
|
|
|
public function getPasswordExpiryTimestamp($currentDate = null) |
52
|
|
|
{ |
53
|
|
|
if (!$currentDate) { |
54
|
|
|
$currentDate = new \DateTime(); |
55
|
|
|
} |
56
|
|
|
$result = 0; |
57
|
|
|
$settings = $this->getSettings(); |
58
|
|
|
if (isset($settings['passwordExpiration']['enabled']) && (bool)$settings['passwordExpiration']['enabled']) { |
59
|
|
|
$validityInDays = $settings['passwordExpiration']['validityInDays'] ?? 90; |
60
|
|
|
$currentDate->modify('+' . $validityInDays . 'days'); |
61
|
|
|
$result = $currentDate->getTimestamp(); |
62
|
|
|
} |
63
|
|
|
return $result; |
64
|
|
|
} |
65
|
|
|
} |
66
|
|
|
|