3 namespace CoreFramework\Filter\Change\Email;
5 // Import framework stuff
6 use CoreFramework\Filter\BaseFilter;
7 use CoreFramework\Filter\Filterable;
8 use CoreFramework\Registry\Registry;
9 use CoreFramework\Request\Requestable;
10 use CoreFramework\Response\Responseable;
13 * A filter for password change detection
15 * @author Roland Haeder <webmaster@shipsimu.org>
17 * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2017 Core Developer Team
18 * @license GNU GPL 3.0 or any newer version
19 * @link http://www.shipsimu.org
21 * This program is free software: you can redistribute it and/or modify
22 * it under the terms of the GNU General Public License as published by
23 * the Free Software Foundation, either version 3 of the License, or
24 * (at your option) any later version.
26 * This program is distributed in the hope that it will be useful,
27 * but WITHOUT ANY WARRANTY; without even the implied warranty of
28 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29 * GNU General Public License for more details.
31 * You should have received a copy of the GNU General Public License
32 * along with this program. If not, see <http://www.gnu.org/licenses/>.
34 class PasswordChangeFilter extends BaseFilter implements Filterable {
36 * Protected constructor
40 protected function __construct () {
41 // Call parent constructor
42 parent::__construct(__CLASS__);
46 * Creates an instance of this filter class
48 * @param $controllerInstance An instance of a controller class
49 * @return $filterInstance An instance of this filter class
51 public static final function createPasswordChangeFilter () {
53 $filterInstance = new PasswordChangeFilter();
55 // Return the instance
56 return $filterInstance;
60 * Executes the filter with given request and response objects
62 * @param $requestInstance An instance of a class with an Requestable interface
63 * @param $responseInstance An instance of a class with an Responseable interface
65 * @todo Finished updating user password hash here. HINT: Use the User class again.
66 * @throws FilterChainException If this filter fails to operate
68 public function execute (Requestable $requestInstance, Responseable $responseInstance) {
70 $pass1 = $requestInstance->getRequestElement('pass1');
71 $pass2 = $requestInstance->getRequestElement('pass2');
73 // Is only first email set?
74 if ((!empty($pass1)) && (empty($pass2))) {
75 // Request is invalid!
76 $requestInstance->requestIsValid(FALSE);
79 $responseInstance->addFatalMessage('pass2_empty');
81 // Stop processing here
82 throw new FilterChainException($this, self::EXCEPTION_FILTER_CHAIN_INTERCEPTED);
85 // Is only second pass set?
86 if ((empty($pass1)) && (!empty($pass2))) {
87 // Request is invalid!
88 $requestInstance->requestIsValid(FALSE);
91 $responseInstance->addFatalMessage('pass1_empty');
93 // Stop processing here
94 throw new FilterChainException($this, self::EXCEPTION_FILTER_CHAIN_INTERCEPTED);
97 // Are password and confirmation empty?
98 if ((empty($pass1)) && (empty($pass2))) {
99 // Don't change password here
104 if ($pass1 != $pass2) {
105 // Request is invalid!
106 $requestInstance->requestIsValid(FALSE);
108 // Emails are mismatching
109 $responseInstance->addFatalMessage('pass_mismatch');
111 // Stop processing here
112 throw new FilterChainException($this, self::EXCEPTION_FILTER_CHAIN_INTERCEPTED);
115 // Now, get a user instance for comparison
116 $userInstance = Registry::getRegistry()->getInstance('user');
118 // Update the "password" field
119 $this->partialStub('Unfinished part.');