Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 21 |
|
0.00% |
0 / 1 |
CRAP | |
0.00% |
0 / 1 |
| Authenticator | |
0.00% |
0 / 21 |
|
0.00% |
0 / 1 |
42 | |
0.00% |
0 / 1 |
| login | |
0.00% |
0 / 21 |
|
0.00% |
0 / 1 |
42 | |||
| 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\controller; |
| 24 | |
| 25 | use oat\taoClientDiagnostic\exception\InvalidCallException; |
| 26 | use oat\taoClientDiagnostic\exception\InvalidLoginException; |
| 27 | use oat\taoClientDiagnostic\model\authorization\Authorization; |
| 28 | use oat\taoClientDiagnostic\model\authorization\RequireUsername; |
| 29 | |
| 30 | /** |
| 31 | * Class Authenticator |
| 32 | * @package oat\taoClientDiagnostic\controller |
| 33 | */ |
| 34 | class Authenticator extends \tao_actions_CommonModule |
| 35 | { |
| 36 | /** |
| 37 | * Login process |
| 38 | * Check if url successCallback is set |
| 39 | * If login form is post valid, setcookie & redirect to successCallback |
| 40 | * Else create LoginForm with ?errorMessage |
| 41 | */ |
| 42 | public function login() |
| 43 | { |
| 44 | try { |
| 45 | if (!$this->hasRequestParameter('successCallback')) { |
| 46 | throw new \common_exception_MissingParameter('Internal error, please retry in few moment'); |
| 47 | } |
| 48 | |
| 49 | if ($this->isRequestPost()) { |
| 50 | $authorizationService = $this->getServiceLocator()->get(Authorization::SERVICE_ID); |
| 51 | |
| 52 | if (!$authorizationService instanceof RequireUsername) { |
| 53 | throw new InvalidCallException('Authenticator need to be call by requireusername'); |
| 54 | } |
| 55 | |
| 56 | if ($authorizationService->validateLogin($this->getRequestParameter('login'))) { |
| 57 | $baseUrl = $this->getServiceLocator() |
| 58 | ->get(\common_ext_ExtensionsManager::SERVICE_ID) |
| 59 | ->getExtensionById('taoClientDiagnostic') |
| 60 | ->getConstant('BASE_URL'); |
| 61 | $elements = parse_url($baseUrl); |
| 62 | $this->setCookie('login', $this->getRequestParameter('login'), null, $elements['path']); |
| 63 | $this->redirect($this->getRequestParameter('successCallback')); |
| 64 | } |
| 65 | } |
| 66 | } catch (InvalidLoginException $e) { |
| 67 | $this->setData('errorMessage', $e->getUserMessage()); |
| 68 | } |
| 69 | |
| 70 | $this->setData('successCallback', $this->getRequestParameter('successCallback')); |
| 71 | $this->setData('client_config_url', $this->getClientConfigUrl()); |
| 72 | $this->setData('content-controller', 'taoClientDiagnostic/controller/Authenticator/login'); |
| 73 | $this->setData('content-template', 'Authenticator' . DIRECTORY_SEPARATOR . 'login.tpl'); |
| 74 | $this->setView('index.tpl'); |
| 75 | } |
| 76 | } |