Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 26 |
|
0.00% |
0 / 8 |
CRAP | |
0.00% |
0 / 1 |
| RdfLockoutStorage | |
0.00% |
0 / 26 |
|
0.00% |
0 / 8 |
110 | |
0.00% |
0 / 1 |
| getUser | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
6 | |||
| getStatus | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| setLockedStatus | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
2 | |||
| setUnlockedStatus | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
| getFailures | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
2 | |||
| setFailures | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
6 | |||
| getLastFailureTime | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
| getLockedBy | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * This program is free software; you can redistribute it and/or |
| 5 | * modify it under the terms of the GNU General Public License |
| 6 | * as published by the Free Software Foundation; under version 2 |
| 7 | * of the License (non-upgradable). |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | * GNU General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU General Public License |
| 15 | * along with this program; if not, write to the Free Software |
| 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 17 | * |
| 18 | * Copyright (c) 2018 (original work) Open Assessment Technologies SA (under the project TAO-PRODUCT); |
| 19 | */ |
| 20 | |
| 21 | namespace oat\tao\model\user\implementation; |
| 22 | |
| 23 | use core_kernel_classes_Resource; |
| 24 | use core_kernel_users_Exception; |
| 25 | use core_kernel_users_Service; |
| 26 | use oat\generis\model\OntologyAwareTrait; |
| 27 | use oat\tao\model\user\LockoutStorage; |
| 28 | |
| 29 | /** |
| 30 | * Class RdfLockoutStorage |
| 31 | * @package oat\tao\model\user\implementation |
| 32 | */ |
| 33 | class RdfLockoutStorage implements LockoutStorage |
| 34 | { |
| 35 | use OntologyAwareTrait; |
| 36 | |
| 37 | public const PROPERTY_USER_ACCOUNT_STATUS = 'http://www.tao.lu/Ontologies/TAO.rdf#accountStatus'; |
| 38 | |
| 39 | public const PROPERTY_USER_STATUS_LOCKED = 'http://www.tao.lu/Ontologies/TAO.rdf#Locked'; |
| 40 | |
| 41 | public const PROPERTY_USER_LOCKED_BY = 'http://www.tao.lu/Ontologies/TAO.rdf#lockedBy'; |
| 42 | |
| 43 | public const PROPERTY_USER_LOGON_FAILURES = 'http://www.tao.lu/Ontologies/TAO.rdf#logonFailures'; |
| 44 | |
| 45 | public const PROPERTY_USER_LAST_LOGON_FAILURE_TIME = 'http://www.tao.lu/Ontologies/TAO.rdf#lastLogonFailureTime'; |
| 46 | |
| 47 | /** |
| 48 | * @param string $login |
| 49 | * @return core_kernel_classes_Resource |
| 50 | * @throws core_kernel_users_Exception |
| 51 | */ |
| 52 | public function getUser($login) |
| 53 | { |
| 54 | $user = core_kernel_users_Service::singleton()->getOneUser($login); |
| 55 | |
| 56 | if (is_null($user)) { |
| 57 | throw new core_kernel_users_Exception(sprintf('Requested user with login %s not found.', $login)); |
| 58 | } |
| 59 | |
| 60 | return $user; |
| 61 | } |
| 62 | |
| 63 | /** |
| 64 | * @param $login |
| 65 | * @return \core_kernel_classes_Container |
| 66 | * @throws \core_kernel_persistence_Exception |
| 67 | * @throws core_kernel_users_Exception |
| 68 | */ |
| 69 | public function getStatus($login) |
| 70 | { |
| 71 | return $this->getUser($login)->getOnePropertyValue($this->getProperty(self::PROPERTY_USER_ACCOUNT_STATUS)); |
| 72 | } |
| 73 | |
| 74 | /** |
| 75 | * @param $login |
| 76 | * @param $by |
| 77 | * @throws core_kernel_users_Exception |
| 78 | */ |
| 79 | public function setLockedStatus($login, $by) |
| 80 | { |
| 81 | $this->getUser($login)->editPropertyValues( |
| 82 | $this->getProperty(self::PROPERTY_USER_ACCOUNT_STATUS), |
| 83 | self::PROPERTY_USER_STATUS_LOCKED |
| 84 | ); |
| 85 | $this->getUser($login)->editPropertyValues($this->getProperty(self::PROPERTY_USER_LOCKED_BY), $by); |
| 86 | } |
| 87 | |
| 88 | /** |
| 89 | * @param $login |
| 90 | * @throws core_kernel_users_Exception |
| 91 | */ |
| 92 | public function setUnlockedStatus($login) |
| 93 | { |
| 94 | $this->getUser($login)->removePropertyValues($this->getProperty(self::PROPERTY_USER_ACCOUNT_STATUS)); |
| 95 | $this->getUser($login)->editPropertyValues($this->getProperty(self::PROPERTY_USER_LOCKED_BY), null); |
| 96 | } |
| 97 | |
| 98 | /** |
| 99 | * @param string $login |
| 100 | * @return int |
| 101 | * @throws \core_kernel_persistence_Exception |
| 102 | * @throws core_kernel_users_Exception |
| 103 | */ |
| 104 | public function getFailures($login) |
| 105 | { |
| 106 | return intval( |
| 107 | (string)$this->getUser($login)->getOnePropertyValue( |
| 108 | $this->getProperty(self::PROPERTY_USER_LOGON_FAILURES) |
| 109 | ) |
| 110 | ); |
| 111 | } |
| 112 | |
| 113 | /** |
| 114 | * @param string $login |
| 115 | * @param $value |
| 116 | * @return bool |
| 117 | * @throws core_kernel_users_Exception |
| 118 | */ |
| 119 | public function setFailures($login, $value) |
| 120 | { |
| 121 | $user = $this->getUser($login); |
| 122 | |
| 123 | $user->editPropertyValues($this->getProperty(self::PROPERTY_USER_LOGON_FAILURES), $value); |
| 124 | |
| 125 | if ($value) { |
| 126 | $user->editPropertyValues($this->getProperty(self::PROPERTY_USER_LAST_LOGON_FAILURE_TIME), time()); |
| 127 | } |
| 128 | |
| 129 | return true; |
| 130 | } |
| 131 | |
| 132 | /** |
| 133 | * @param string $login |
| 134 | * @return mixed |
| 135 | * @throws \core_kernel_persistence_Exception |
| 136 | * @throws core_kernel_users_Exception |
| 137 | */ |
| 138 | public function getLastFailureTime($login) |
| 139 | { |
| 140 | return $this->getUser($login)->getOnePropertyValue( |
| 141 | $this->getProperty(self::PROPERTY_USER_LAST_LOGON_FAILURE_TIME) |
| 142 | ); |
| 143 | } |
| 144 | |
| 145 | /** |
| 146 | * @param $login |
| 147 | * @return \core_kernel_classes_Container |
| 148 | * @throws \core_kernel_persistence_Exception |
| 149 | * @throws core_kernel_users_Exception |
| 150 | */ |
| 151 | public function getLockedBy($login) |
| 152 | { |
| 153 | return $this->getUser($login)->getOnePropertyValue($this->getProperty(self::PROPERTY_USER_LOCKED_BY)); |
| 154 | } |
| 155 | } |