3 namespace Org\Mxchange\CoreFramework\Filter\Change\Email;
5 // Import framework stuff
6 use Org\Mxchange\CoreFramework\Filter\BaseFilter;
7 use Org\Mxchange\CoreFramework\Filter\Chain\FilterChainException;
8 use Org\Mxchange\CoreFramework\Filter\Filterable;
9 use Org\Mxchange\CoreFramework\Middleware\Debug\DebugMiddleware;
10 use Org\Mxchange\CoreFramework\Registry\Object\ObjectRegistry;
11 use Org\Mxchange\CoreFramework\Request\Requestable;
12 use Org\Mxchange\CoreFramework\Response\Responseable;
15 * A filter for detecting email changes
17 * @author Roland Haeder <webmaster@shipsimu.org>
19 * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2023 Core Developer Team
20 * @license GNU GPL 3.0 or any newer version
21 * @link http://www.shipsimu.org
23 * This program is free software: you can redistribute it and/or modify
24 * it under the terms of the GNU General Public License as published by
25 * the Free Software Foundation, either version 3 of the License, or
26 * (at your option) any later version.
28 * This program is distributed in the hope that it will be useful,
29 * but WITHOUT ANY WARRANTY; without even the implied warranty of
30 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31 * GNU General Public License for more details.
33 * You should have received a copy of the GNU General Public License
34 * along with this program. If not, see <http://www.gnu.org/licenses/>.
36 class EmailChangeFilter extends BaseFilter implements Filterable {
38 * Protected constructor
42 private function __construct () {
43 // Call parent constructor
44 parent::__construct(__CLASS__);
48 * Creates an instance of this filter class
50 * @return $filterInstance An instance of this filter class
52 public static final function createEmailChangeFilter () {
54 $filterInstance = new EmailChangeFilter();
56 // Return the instance
57 return $filterInstance;
61 * Executes the filter with given request and response objects
63 * @param $requestInstance An instance of a class with an Requestable interface
64 * @param $responseInstance An instance of a class with an Responseable interface
66 * @throws FilterChainException If this filter fails to operate
67 * @todo Implement email change of the user here. HINT: Use the User class!
69 public function execute (Requestable $requestInstance, Responseable $responseInstance) {
71 $email1 = $requestInstance->getRequestElement('email1');
72 $email2 = $requestInstance->getRequestElement('email2');
74 // Is only first email set?
75 if ((!empty($email1)) && (empty($email2))) {
76 // Request is invalid!
77 $requestInstance->setIsRequestValid(FALSE);
80 $responseInstance->addFatalMessage('email2_empty');
82 // Stop processing here
83 throw new FilterChainException($this, self::EXCEPTION_FILTER_CHAIN_INTERCEPTED);
86 // Is only second email set?
87 if ((empty($email1)) && (!empty($email2))) {
88 // Request is invalid!
89 $requestInstance->setIsRequestValid(FALSE);
92 $responseInstance->addFatalMessage('email1_empty');
94 // Stop processing here
95 throw new FilterChainException($this, self::EXCEPTION_FILTER_CHAIN_INTERCEPTED);
99 if ($email1 != $email2) {
100 // Request is invalid!
101 $requestInstance->setIsRequestValid(FALSE);
103 // Emails are mismatching
104 $responseInstance->addFatalMessage('emails_mismatch');
106 // Stop processing here
107 throw new FilterChainException($this, self::EXCEPTION_FILTER_CHAIN_INTERCEPTED);
110 // Are email and confirmation empty?
111 if ((empty($email1)) && (empty($email2))) {
112 // No email change required!
116 // Now, get a user instance for comparison
117 $userInstance = ObjectRegistry::getRegistry('generic')->getInstance('user');
119 // Get the email field
120 $userEmail = $userInstance->getField('email');
122 // Are they different?
123 if ($userEmail == $email1) {
124 // Nothing has been changed is fine...
128 // Update the "new_email" field
129 DebugMiddleware::getSelfInstance()->partialStub('Unfinished part.');