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