Rewrite continued:
[core.git] / framework / main / classes / filter / change / class_PasswordChangeFilter.php
1 <?php
2 // Own namespace
3 namespace CoreFramework\Filter\Change\Password;
4
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;
11
12 /**
13  * A filter for password change detection
14  *
15  * @author              Roland Haeder <webmaster@shipsimu.org>
16  * @version             0.0.0
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
20  *
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.
25  *
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.
30  *
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/>.
33  */
34 class PasswordChangeFilter extends BaseFilter implements Filterable {
35         /**
36          * Protected constructor
37          *
38          * @return      void
39          */
40         protected function __construct () {
41                 // Call parent constructor
42                 parent::__construct(__CLASS__);
43         }
44
45         /**
46          * Creates an instance of this filter class
47          *
48          * @param       $controllerInstance             An instance of a controller class
49          * @return      $filterInstance                 An instance of this filter class
50          */
51         public static final function createPasswordChangeFilter () {
52                 // Get a new instance
53                 $filterInstance = new PasswordChangeFilter();
54
55                 // Return the instance
56                 return $filterInstance;
57         }
58
59         /**
60          * Executes the filter with given request and response objects
61          *
62          * @param       $requestInstance        An instance of a class with an Requestable interface
63          * @param       $responseInstance       An instance of a class with an Responseable interface
64          * @return      void
65          * @todo        Finished updating user password hash here. HINT: Use the User class again.
66          * @throws      FilterChainException    If this filter fails to operate
67          */
68         public function execute (Requestable $requestInstance, Responseable $responseInstance) {
69                 // Get both passwords
70                 $pass1 = $requestInstance->getRequestElement('pass1');
71                 $pass2 = $requestInstance->getRequestElement('pass2');
72
73                 // Is only first email set?
74                 if ((!empty($pass1)) && (empty($pass2))) {
75                         // Request is invalid!
76                         $requestInstance->requestIsValid(false);
77
78                         // Email 2 is empty
79                         $responseInstance->addFatalMessage('pass2_empty');
80
81                         // Stop processing here
82                         throw new FilterChainException($this, self::EXCEPTION_FILTER_CHAIN_INTERCEPTED);
83                 } // END - if
84
85                 // Is only second pass set?
86                 if ((empty($pass1)) && (!empty($pass2))) {
87                         // Request is invalid!
88                         $requestInstance->requestIsValid(false);
89
90                         // Email 1 is empty
91                         $responseInstance->addFatalMessage('pass1_empty');
92
93                         // Stop processing here
94                         throw new FilterChainException($this, self::EXCEPTION_FILTER_CHAIN_INTERCEPTED);
95                 } // END - if
96
97                 // Are password and confirmation empty?
98                 if ((empty($pass1)) && (empty($pass2))) {
99                         // Don't change password here
100                         return true;
101                 } // END - if
102
103                 // Do both match?
104                 if ($pass1 != $pass2) {
105                         // Request is invalid!
106                         $requestInstance->requestIsValid(false);
107
108                         // Emails are mismatching
109                         $responseInstance->addFatalMessage('pass_mismatch');
110
111                         // Stop processing here
112                         throw new FilterChainException($this, self::EXCEPTION_FILTER_CHAIN_INTERCEPTED);
113                 } // END - if
114
115                 // Now, get a user instance for comparison
116                 $userInstance = Registry::getRegistry()->getInstance('user');
117
118                 // Update the "password" field
119                 $this->partialStub('Unfinished part.');
120         }
121
122 }