|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Alpha\Controller; |
|
4
|
|
|
|
|
5
|
|
|
use Alpha\Util\Logging\Logger; |
|
6
|
|
|
use Alpha\Util\Config\ConfigProvider; |
|
7
|
|
|
use Alpha\Util\Service\ServiceFactory; |
|
8
|
|
|
use Alpha\Util\Http\Response; |
|
9
|
|
|
use Alpha\Model\Person; |
|
10
|
|
|
use Alpha\View\View; |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* Logout controller that removes the current user object from the session. |
|
14
|
|
|
* |
|
15
|
|
|
* @since 1.0 |
|
16
|
|
|
* |
|
17
|
|
|
* @author John Collins <[email protected]> |
|
18
|
|
|
* @license http://www.opensource.org/licenses/bsd-license.php The BSD License |
|
19
|
|
|
* @copyright Copyright (c) 2018, John Collins (founder of Alpha Framework). |
|
20
|
|
|
* All rights reserved. |
|
21
|
|
|
* |
|
22
|
|
|
* <pre> |
|
23
|
|
|
* Redistribution and use in source and binary forms, with or |
|
24
|
|
|
* without modification, are permitted provided that the |
|
25
|
|
|
* following conditions are met: |
|
26
|
|
|
* |
|
27
|
|
|
* * Redistributions of source code must retain the above |
|
28
|
|
|
* copyright notice, this list of conditions and the |
|
29
|
|
|
* following disclaimer. |
|
30
|
|
|
* * Redistributions in binary form must reproduce the above |
|
31
|
|
|
* copyright notice, this list of conditions and the |
|
32
|
|
|
* following disclaimer in the documentation and/or other |
|
33
|
|
|
* materials provided with the distribution. |
|
34
|
|
|
* * Neither the name of the Alpha Framework nor the names |
|
35
|
|
|
* of its contributors may be used to endorse or promote |
|
36
|
|
|
* products derived from this software without specific |
|
37
|
|
|
* prior written permission. |
|
38
|
|
|
* |
|
39
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND |
|
40
|
|
|
* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, |
|
41
|
|
|
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
|
42
|
|
|
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
|
43
|
|
|
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR |
|
44
|
|
|
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
|
45
|
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
|
46
|
|
|
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
|
47
|
|
|
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
|
48
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
|
49
|
|
|
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE |
|
50
|
|
|
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
|
51
|
|
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|
52
|
|
|
* </pre> |
|
53
|
|
|
*/ |
|
54
|
|
|
class LogoutController extends Controller implements ControllerInterface |
|
55
|
|
|
{ |
|
56
|
|
|
/** |
|
57
|
|
|
* Trace logger. |
|
58
|
|
|
* |
|
59
|
|
|
* @var \Alpha\Util\Logging\Logger |
|
60
|
|
|
* |
|
61
|
|
|
* @since 1.0 |
|
62
|
|
|
*/ |
|
63
|
|
|
private static $logger = null; |
|
|
|
|
|
|
64
|
|
|
|
|
65
|
|
|
/** |
|
66
|
|
|
* constructor to set up the object. |
|
67
|
|
|
* |
|
68
|
|
|
* @since 1.0 |
|
69
|
|
|
*/ |
|
70
|
|
|
public function __construct() |
|
71
|
|
|
{ |
|
72
|
|
|
self::$logger = new Logger('LogoutController'); |
|
73
|
|
|
self::$logger->debug('>>__construct()'); |
|
74
|
|
|
|
|
75
|
|
|
// ensure that the super class constructor is called, indicating the rights group |
|
76
|
|
|
parent::__construct('Public'); |
|
77
|
|
|
|
|
78
|
|
|
$config = ConfigProvider::getInstance(); |
|
79
|
|
|
$sessionProvider = $config->get('session.provider.name'); |
|
80
|
|
|
$session = ServiceFactory::getInstance($sessionProvider, 'Alpha\Util\Http\Session\SessionProviderInterface'); |
|
81
|
|
|
|
|
82
|
|
|
if ($session->get('currentUser') !== false) { |
|
83
|
|
|
$this->setRecord($session->get('currentUser')); |
|
84
|
|
|
} else { |
|
85
|
|
|
self::$logger->warn('Logout controller called when no user is logged in'); |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
// set up the title and meta details |
|
89
|
|
|
$this->setTitle('Logged out successfully.'); |
|
90
|
|
|
$this->setDescription('Logout page.'); |
|
91
|
|
|
$this->setKeywords('Logout,logon'); |
|
92
|
|
|
|
|
93
|
|
|
self::$logger->debug('<<__construct'); |
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
|
/** |
|
97
|
|
|
* Handle GET requests. |
|
98
|
|
|
* |
|
99
|
|
|
* @param \Alpha\Util\Http\Request $request |
|
100
|
|
|
* |
|
101
|
|
|
* @return \Alpha\Util\Http\Response |
|
102
|
|
|
* |
|
103
|
|
|
* @since 1.0 |
|
104
|
|
|
*/ |
|
105
|
|
|
public function doGET($request) |
|
106
|
|
|
{ |
|
107
|
|
|
self::$logger->debug('>>doGET($request=['.var_export($request, true).'])'); |
|
108
|
|
|
|
|
109
|
|
|
$config = ConfigProvider::getInstance(); |
|
110
|
|
|
|
|
111
|
|
|
if ($this->record instanceof Person) { |
|
112
|
|
|
self::$logger->debug('Logging out ['.$this->record->get('email').'] at ['.date('Y-m-d H:i:s').']'); |
|
113
|
|
|
self::$logger->action('Logout'); |
|
114
|
|
|
} |
|
115
|
|
|
|
|
116
|
|
|
$sessionProvider = $config->get('session.provider.name'); |
|
117
|
|
|
$session = ServiceFactory::getInstance($sessionProvider, 'Alpha\Util\Http\Session\SessionProviderInterface'); |
|
118
|
|
|
$session->destroy(); |
|
119
|
|
|
|
|
120
|
|
|
$body = View::displayPageHead($this); |
|
121
|
|
|
|
|
122
|
|
|
$body .= View::displayUpdateMessage('You have successfully logged out of the system.'); |
|
123
|
|
|
|
|
124
|
|
|
$body .= '<div align="center"><a href="'.$config->get('app.url').'">Home Page</a></div>'; |
|
125
|
|
|
|
|
126
|
|
|
$body .= View::displayPageFoot($this); |
|
127
|
|
|
|
|
128
|
|
|
self::$logger->debug('<<doGET'); |
|
129
|
|
|
|
|
130
|
|
|
return new Response(200, $body, array('Content-Type' => 'text/html')); |
|
131
|
|
|
} |
|
132
|
|
|
} |
|
133
|
|
|
|