1: <?php
2:
3: // include the config file
4: if(!isset($config)) {
5: require_once '../util/AlphaConfig.inc';
6: $config = AlphaConfig::getInstance();
7:
8: require_once $config->get('app.root').'alpha/util/AlphaAutoLoader.inc';
9: }
10:
11: /**
12: * Logout controller that removes the current user object from the session
13: *
14: * @package alpha::controller
15: * @since 1.0
16: * @author John Collins <dev@alphaframework.org>
17: * @version $Id: Logout.php 1645 2013-02-14 16:11:19Z alphadevx $
18: * @license http://www.opensource.org/licenses/bsd-license.php The BSD License
19: * @copyright Copyright (c) 2013, 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: */
55: class Logout extends AlphaController implements AlphaControllerInterface {
56: /**
57: * Trace logger
58: *
59: * @var Logger
60: * @since 1.0
61: */
62: private static $logger = null;
63:
64: /**
65: * constructor to set up the object
66: *
67: * @since 1.0
68: */
69: public function __construct() {
70: self::$logger = new Logger('Logout');
71: self::$logger->debug('>>__construct()');
72:
73: // ensure that the super class constructor is called, indicating the rights group
74: parent::__construct('Public');
75:
76: if(isset($_SESSION['currentUser']))
77: $this->setBO($_SESSION['currentUser']);
78: else
79: self::$logger->warn('Logout controller called when no user is logged in');
80:
81: // set up the title and meta details
82: $this->setTitle('Logged out successfully.');
83: $this->setDescription('Logout page.');
84: $this->setKeywords('Logout,logon');
85:
86: self::$logger->debug('<<__construct');
87: }
88:
89: /**
90: * Handle POST requests (adds $currentUser PersonObject to the session)
91: *
92: * @param array $params
93: * @since 1.0
94: */
95: public function doPOST($params) {
96: self::$logger->debug('>>doPOST($params=['.var_export($params, true).'])');
97:
98: self::$logger->debug('<<doPOST');
99: }
100:
101: /**
102: * Handle GET requests
103: *
104: * @param array $params
105: * @since 1.0
106: * @throws AlphaException
107: */
108: public function doGET($params) {
109: self::$logger->debug('>>doGET($params=['.var_export($params, true).'])');
110:
111: global $config;
112:
113: if($this->BO instanceof PersonObject) {
114: self::$logger->debug('Logging out ['.$this->BO->get('email').'] at ['.date("Y-m-d H:i:s").']');
115: self::$logger->action('Logout');
116: }
117:
118: $_SESSION = array();
119:
120: session_destroy();
121:
122: echo AlphaView::displayPageHead($this);
123:
124: echo AlphaView::displayUpdateMessage('You have successfully logged out of the system.');
125:
126: echo '<div align="center"><a href="'.$config->get('app.url').'">Home Page</a></div>';
127:
128: echo AlphaView::displayPageFoot($this);
129:
130: self::$logger->debug('<<doGET');
131: }
132: }
133:
134: // now build the new controller if this file is called directly
135: if ('Logout.php' == basename($_SERVER['PHP_SELF'])) {
136: $controller = new Logout();
137:
138: if(!empty($_POST)) {
139: $controller->doPOST($_POST);
140: }else{
141: $controller->doGET($_GET);
142: }
143: }
144:
145: ?>