9
9
use Magento \Authorization \Model \Acl \Role \Group as RoleGroup ;
10
10
use Magento \Authorization \Model \Acl \Role \User as RoleUser ;
11
11
use Magento \Authorization \Model \UserContextInterface ;
12
+ use Magento \Framework \Acl \Data \CacheInterface ;
13
+ use Magento \Framework \App \ObjectManager ;
14
+ use Magento \User \Model \Backend \Config \ObserverConfig ;
12
15
use Magento \User \Model \User as ModelUser ;
13
16
14
17
/**
@@ -32,32 +35,38 @@ class User extends \Magento\Framework\Model\ResourceModel\Db\AbstractDb
32
35
protected $ dateTime ;
33
36
34
37
/**
35
- * @var \Magento\Framework\Acl\Data\ CacheInterface
38
+ * @var CacheInterface
36
39
*/
37
40
private $ aclDataCache ;
38
41
42
+ /**
43
+ * @var ObserverConfig|null
44
+ */
45
+ private $ observerConfig ;
46
+
39
47
/**
40
48
* Construct
41
49
*
42
50
* @param \Magento\Framework\Model\ResourceModel\Db\Context $context
43
51
* @param \Magento\Authorization\Model\RoleFactory $roleFactory
44
52
* @param \Magento\Framework\Stdlib\DateTime $dateTime
45
53
* @param string $connectionName
46
- * @param \Magento\Framework\Acl\Data\CacheInterface $aclDataCache
54
+ * @param CacheInterface $aclDataCache
55
+ * @param ObserverConfig|null $observerConfig
47
56
*/
48
57
public function __construct (
49
58
\Magento \Framework \Model \ResourceModel \Db \Context $ context ,
50
59
\Magento \Authorization \Model \RoleFactory $ roleFactory ,
51
60
\Magento \Framework \Stdlib \DateTime $ dateTime ,
52
61
$ connectionName = null ,
53
- \Magento \Framework \Acl \Data \CacheInterface $ aclDataCache = null
62
+ CacheInterface $ aclDataCache = null ,
63
+ ObserverConfig $ observerConfig = null
54
64
) {
55
65
parent ::__construct ($ context , $ connectionName );
56
66
$ this ->_roleFactory = $ roleFactory ;
57
67
$ this ->dateTime = $ dateTime ;
58
- $ this ->aclDataCache = $ aclDataCache ?: \Magento \Framework \App \ObjectManager::getInstance ()->get (
59
- \Magento \Framework \Acl \Data \CacheInterface::class
60
- );
68
+ $ this ->aclDataCache = $ aclDataCache ?: ObjectManager::getInstance ()->get (CacheInterface::class);
69
+ $ this ->observerConfig = $ observerConfig ?: ObjectManager::getInstance ()->get (ObserverConfig::class);
61
70
}
62
71
63
72
/**
@@ -559,12 +568,14 @@ public function getOldPasswords($user, $retainLimit = 4)
559
568
->select ()
560
569
->from ($ table , 'password_id ' )
561
570
->where ('user_id = :user_id ' )
562
- ->order ('expires ' . \Magento \Framework \DB \Select::SQL_DESC )
563
571
->order ('password_id ' . \Magento \Framework \DB \Select::SQL_DESC )
564
572
->limit ($ retainLimit ),
565
573
[':user_id ' => $ userId ]
566
574
);
567
- $ where = ['user_id = ? ' => $ userId , 'expires <= ? ' => time ()];
575
+ $ where = [
576
+ 'user_id = ? ' => $ userId ,
577
+ 'last_updated <= ? ' => time () - $ this ->observerConfig ->getAdminPasswordLifetime ()
578
+ ];
568
579
if ($ retainPasswordIds ) {
569
580
$ where ['password_id NOT IN (?) ' ] = $ retainPasswordIds ;
570
581
}
@@ -585,19 +596,21 @@ public function getOldPasswords($user, $retainLimit = 4)
585
596
*
586
597
* @param ModelUser $user
587
598
* @param string $passwordHash
588
- * @param int $lifetime
599
+ * @param int $lifetime deprecated, password expiration date doesn't save anymore,
600
+ * it is calculated in runtime based on password created date and lifetime config value
589
601
* @return void
602
+ * @SuppressWarnings(PHPMD.UnusedFormalParameter)
603
+ *
604
+ * @see \Magento\User\Model\Backend\Config\ObserverConfig::_isLatestPasswordExpired()
590
605
*/
591
- public function trackPassword ($ user , $ passwordHash , $ lifetime )
606
+ public function trackPassword ($ user , $ passwordHash , $ lifetime = 0 )
592
607
{
593
- $ now = time ();
594
608
$ this ->getConnection ()->insert (
595
609
$ this ->getTable ('admin_passwords ' ),
596
610
[
597
611
'user_id ' => $ user ->getId (),
598
612
'password_hash ' => $ passwordHash ,
599
- 'expires ' => $ now + $ lifetime ,
600
- 'last_updated ' => $ now
613
+ 'last_updated ' => time ()
601
614
]
602
615
);
603
616
}
0 commit comments