Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 22 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
| CookieUtils | |
0.00% |
0 / 22 |
|
0.00% |
0 / 2 |
30 | |
0.00% |
0 / 1 |
| verifyCookie | |
0.00% |
0 / 8 |
|
0.00% |
0 / 1 |
6 | |||
| restoreSession | |
0.00% |
0 / 14 |
|
0.00% |
0 / 1 |
12 | |||
| 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) 2014 (original work) Open Assessment Technologies SA (under the project TAO-PRODUCT); |
| 19 | * |
| 20 | * |
| 21 | */ |
| 22 | |
| 23 | namespace oat\taoLti\controller; |
| 24 | |
| 25 | use common_Logger; |
| 26 | use tao_actions_CommonModule; |
| 27 | |
| 28 | /** |
| 29 | * A controller to bypass some restrictions on cookies |
| 30 | * |
| 31 | * @author Joel Bout <joel@taotesting.com> |
| 32 | * @package taoLti |
| 33 | |
| 34 | */ |
| 35 | class CookieUtils extends tao_actions_CommonModule |
| 36 | { |
| 37 | /** |
| 38 | * Verifies whenever or not the cookie was set correctly |
| 39 | * Redirects the user to his destination if it was |
| 40 | * or prompts the user to restore the session if it wasn't |
| 41 | */ |
| 42 | public function verifyCookie() |
| 43 | { |
| 44 | $url = $this->getRequestParameter('redirect'); |
| 45 | $url = rawurldecode($url); |
| 46 | $session = $this->getRequestParameter('session'); |
| 47 | if (session_id() == $session) { |
| 48 | $this->forwardUrl($url); |
| 49 | } else { |
| 50 | $this->setData('session', $session); |
| 51 | $this->setData('redirect', $url); |
| 52 | $this->setView('cookieError.tpl'); |
| 53 | } |
| 54 | } |
| 55 | |
| 56 | /** |
| 57 | * Closses the current session, restores the session provided |
| 58 | * in the parameter session, regenerates a new sessionid and |
| 59 | * redirects the user to the original address |
| 60 | * @throws \common_Exception |
| 61 | */ |
| 62 | public function restoreSession() |
| 63 | { |
| 64 | $sessId = $this->getRequestParameter('session'); |
| 65 | $url = $this->getRequestParameter('redirect'); |
| 66 | if (session_id() != $sessId) { |
| 67 | common_Logger::i('Changing session to ' . $sessId); |
| 68 | session_unset(); |
| 69 | session_destroy(); |
| 70 | |
| 71 | session_id($sessId); |
| 72 | session_start(); |
| 73 | if (session_id() != $sessId) { |
| 74 | $this->returnError(__('Unable to restore Session')); |
| 75 | } |
| 76 | session_regenerate_id(true); |
| 77 | common_Logger::d('regenerated session to id \'' . session_id() . '\''); |
| 78 | } else { |
| 79 | common_Logger::w('Restore session called with correct session id \'' . session_id() . '\''); |
| 80 | } |
| 81 | $this->forwardUrl($url); |
| 82 | } |
| 83 | } |