Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 8 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 1 |
| RequireUsername | |
0.00% |
0 / 8 |
|
0.00% |
0 / 3 |
72 | |
0.00% |
0 / 1 |
| isAuthorized | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
6 | |||
| getAuthorizationUrl | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| validateLogin | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
30 | |||
| 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) 2015 (original work) Open Assessment Technologies SA; |
| 19 | * |
| 20 | * |
| 21 | */ |
| 22 | |
| 23 | namespace oat\taoClientDiagnostic\model\authorization; |
| 24 | |
| 25 | use oat\oatbox\service\ConfigurableService; |
| 26 | use oat\taoClientDiagnostic\exception\InvalidLoginException; |
| 27 | |
| 28 | /** |
| 29 | * Class RequireAnonymousLogin |
| 30 | * @package oat\taoClientDiagnostic\model\authorization |
| 31 | */ |
| 32 | class RequireUsername extends ConfigurableService implements Authorization |
| 33 | { |
| 34 | /** |
| 35 | * Check if login cookie is set |
| 36 | * @return bool |
| 37 | */ |
| 38 | public function isAuthorized() |
| 39 | { |
| 40 | return empty($_COOKIE['login']) ? false : true; |
| 41 | } |
| 42 | |
| 43 | /** |
| 44 | * Redirect to authentifier controller to process login |
| 45 | * @param $url |
| 46 | * @return string to oat\taoClientDiagnostic\controller\Authenticator:login |
| 47 | */ |
| 48 | public function getAuthorizationUrl($url) |
| 49 | { |
| 50 | return _url('login', 'Authenticator', 'taoClientDiagnostic', array('successCallback' => $url)); |
| 51 | } |
| 52 | |
| 53 | /** |
| 54 | * Check if login is valid |
| 55 | * - not empty |
| 56 | * - exists in TAO ACL -OR- match with regex |
| 57 | * @param $login |
| 58 | * @return bool |
| 59 | * |
| 60 | * @throws InvalidLoginException |
| 61 | */ |
| 62 | public function validateLogin($login = null) |
| 63 | { |
| 64 | if (empty($login)) { |
| 65 | throw new InvalidLoginException('No login found'); |
| 66 | } |
| 67 | |
| 68 | if ( |
| 69 | $this->getServiceLocator()->get(\tao_models_classes_UserService::SERVICE_ID)->loginExists($login) |
| 70 | || ($this->hasOption('regexValidator') && preg_match($this->getOption('regexValidator'), $login) === 1) |
| 71 | ) { |
| 72 | return true; |
| 73 | } |
| 74 | |
| 75 | throw new InvalidLoginException('This login does not exist'); |
| 76 | } |
| 77 | } |