3 namespace Org\Mxchange\CoreFramework\Auth;
5 // Import framework stuff
6 use Org\Mxchange\CoreFramework\Bootstrap\FrameworkBootstrap;
7 use Org\Mxchange\CoreFramework\Object\BaseFrameworkSystem;
8 use Org\Mxchange\CoreFramework\Registry\Registerable;
9 use Org\Mxchange\CoreFramework\Response\Responseable;
12 * A cookie-bases authorization class
14 * @author Roland Haeder <webmaster@shipsimu.org>
16 <<<<<<< HEAD:framework/main/classes/auth/class_CookieAuth.php
17 * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2017 Core Developer Team
19 * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2016 Core Developer Team
20 >>>>>>> Some updates::inc/main/classes/auth/class_CookieAuth.php
21 * @license GNU GPL 3.0 or any newer version
22 * @link http://www.shipsimu.org
24 * This program is free software: you can redistribute it and/or modify
25 * it under the terms of the GNU General Public License as published by
26 * the Free Software Foundation, either version 3 of the License, or
27 * (at your option) any later version.
29 * This program is distributed in the hope that it will be useful,
30 * but WITHOUT ANY WARRANTY; without even the implied warranty of
31 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
32 * GNU General Public License for more details.
34 * You should have received a copy of the GNU General Public License
35 * along with this program. If not, see <http://www.gnu.org/licenses/>.
37 class CookieAuth extends BaseFrameworkSystem implements Authorizeable, Registerable {
39 * Protected constructor
43 protected function __construct () {
44 // Call parent constructor
45 parent::__construct(__CLASS__);
49 * Creates an instance of this class by the given response instance
51 * @param $responseInstance An instance of a Responseable class
52 * @return $loginInstance An instance of this login class
54 public static final function createCookieAuth (Responseable $responseInstance) {
56 $loginInstance = new CookieAuth();
58 // Return the prepared instance
59 return $loginInstance;
63 * "Setter" for username auth data
65 * @param $userName The username from request we shall set
68 public function setUserAuth ($userName) {
69 FrameworkBootstrap::getResponseInstance()->addCookie('username', $userName);
73 * "Setter" for password hash auth data
75 * @param $passHash The hashed password from request we shall set
78 public function setPasswordAuth ($passHash) {
79 FrameworkBootstrap::getResponseInstance()->addCookie('u_hash', $passHash);
83 * Getter for user auth cookie
85 * @return $userName Username to get from cookie
87 public function getUserAuth () {
88 // Get the username from cookie
89 $userName = FrameworkBootstrap::getRequestInstance()->readCookie('username');
91 // Return the username
96 * Getter for password hash auth cookie
98 * @return $passHash Password hash to get from cookie
100 public function getPasswordAuth () {
101 // Get the username from cookie
102 $passHash = FrameworkBootstrap::getRequestInstance()->readCookie('u_hash');
104 // Return the username
109 * Destroy the authorization data
113 public function destroyAuthData () {
114 // Expire both cookies
115 FrameworkBootstrap::getResponseInstance()->expireCookie('username');
116 FrameworkBootstrap::getResponseInstance()->expireCookie('u_hash');
120 * Updates the authorization data and/or sets additional tracking data
124 public function updateAuthData () {
125 FrameworkBootstrap::getResponseInstance()->refreshCookie('username');
126 FrameworkBootstrap::getResponseInstance()->refreshCookie('u_hash');