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