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