]> git.mxchange.org Git - city.git/blob - application/city/classes/registration/class_CityRegistration.php
Continued:
[city.git] / application / city / classes / registration / class_CityRegistration.php
1 <?php
2 // Own namespace
3 namespace Org\Mxchange\City\Registration;
4
5 // Import framework stuff
6 use Org\Mxchange\CoreFramework\Bootstrap\FrameworkBootstrap;
7 use Org\Mxchange\CoreFramework\Criteria\Storing\StoreableCriteria;
8 use Org\Mxchange\CoreFramework\Database\Frontend\User\UserDatabaseFrontend;
9 use Org\Mxchange\CoreFramework\Factory\Database\Frontend\DatabaseFrontendFactory;
10 use Org\Mxchange\CoreFramework\Factory\Object\ObjectFactory;
11 use Org\Mxchange\CoreFramework\Registration\BaseRegistration;
12 use Org\Mxchange\CoreFramework\Registration\User\UserRegister;
13 use Org\Mxchange\CoreFramework\Request\Requestable;
14
15 /**
16  * A user registration class specially for City
17  *
18  * @author              Roland Haeder <webmaster@shipsimu.org>
19  * @version             0.0.0
20  * @copyright   Copyright (c) 2015 - 2023 City Developer Team
21  * @license             GNU GPL 3.0 or any newer version
22  * @link                http://www.shipsimu.org
23  *
24  * This program is free software: you can redistribute it and/or modify
25  * it under the terms of the GNU General Public License as published by
26  * the Free Software Foundation, either version 3 of the License, or
27  * (at your option) any later version.
28  *
29  * This program is distributed in the hope that it will be useful,
30  * but WITHOUT ANY WARRANTY; without even the implied warranty of
31  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
32  * GNU General Public License for more details.
33  *
34  * You should have received a copy of the GNU General Public License
35  * along with this program. If not, see <http://www.gnu.org/licenses/>.
36  */
37 class CityRegistration extends BaseRegistration implements UserRegister {
38         /**
39          * Hashed password
40          */
41         private $hashedPassword = '';
42
43         /**
44          * Elements for criteria
45          */
46         private $criteriaElements = array(
47                 'username',
48                 'pass_hash',
49                 'email' => 'email1',
50                 'surname',
51                 'family',
52                 'street',
53                 'zip',
54                 'city',
55                 'icq',
56                 'jabber',
57                 'yahoo',
58                 'aol',
59                 'msn',
60                 'birth_day',
61                 'birth_month',
62                 'birth_year'
63         );
64
65         /**
66          * Protected constructor
67          *
68          * @return      void
69          */
70         protected function __construct () {
71                 // Call parent constructor
72                 parent::__construct(__CLASS__);
73         }
74
75         /**
76          * Create a new instance
77          *
78          * @return      $registrationInstance   An instance of this registration class
79          */
80         public static final function createCityRegistration () {
81                 // Get a new instance
82                 $registrationInstance = new CityRegistration();
83
84                 // Initialize the filter chains
85                 $registrationInstance->initFilterChains();
86
87                 // And return it
88                 return $registrationInstance;
89         }
90
91         /**
92          * Encrypt given request key or throw an exception if key was not found in
93          * request
94          *
95          * @param       $requestKey             Key in request class
96          * @return      void
97          */
98         public function encryptPassword ($requestKey) {
99                 // Check if password is found in request
100                 if (FrameworkBootstrap::getRequestInstance()->isRequestElementSet($requestKey)) {
101                         // So encrypt the password and store it for later usage in
102                         // the request:
103
104                         // 1.: Get the plain password
105                         $plainPassword = FrameworkBootstrap::getRequestInstance()->getRequestElement($requestKey);
106
107                         // 2. Get a crypto helper and hash the password
108                         $this->hashedPassword = ObjectFactory::createObjectByConfiguredName('crypto_class')->hashString($plainPassword);
109
110                         // 3. Store the hash back in request
111                         FrameworkBootstrap::getRequestInstance()->setRequestElement('pass_hash', $this->hashedPassword);
112                 }
113         }
114
115         /**
116          * Perform things like informing assigned affilates about new registration
117          * before registration
118          *
119          * @return      void
120          * @todo        Maybe add more things to perform
121          */
122         public function doPreRegistration () {
123                 // First run all pre filters
124                 $this->executePreFilters();
125         }
126
127         /**
128          * Registers the new user account by insterting the request data into the
129          * database and paying some start credits or throw exceptions if this fails
130          *
131          * @return      void
132          * @todo        Maybe add more things to perform
133          */
134         public function registerNewUser () {
135                 // Get a user database frontend
136                 $frontendInstance = DatabaseFrontendFactory::createFrontendByConfiguredName('user_db_frontend_class');
137
138                 // Use this instance to insert the whole registration instance
139                 $frontendInstance->insertRegistrationObject($this);
140         }
141
142         /**
143          * Perform things like notifying partner websites after registration is done
144          *
145          * @return      void
146          * @todo        Maybe add more things to perform
147          */
148         public function doPostRegistration () {
149                 // First run all post filters
150                 $this->executePostFilters();
151         }
152
153         /**
154          * Do the action which is required after all registration steps are done.
155          * This can be a simple redirect to another webpage or displaying a message
156          * to the user. Or this can be a login step into the newly created account.
157          *
158          * @return      void
159          */
160         public function doPostAction () {
161                 // Get an action instance from our factory
162                 $actionInstance = ObjectFactory::createObjectByConfiguredName('post_registration_class');
163
164                 // Execute the action
165                 $actionInstance->execute(FrameworkBootstrap::getRequestInstance(), FrameworkBootstrap::getResponseInstance());
166         }
167
168         /**
169          * Adds registration elements to a given dataset instance
170          *
171          * @param       $criteriaInstance       An instance of a StoreableCriteria class
172          * @param       $requestInstance        An instance of a Requestable class
173          * @return      void
174          */
175         public function addElementsToDataSet (StoreableCriteria $criteriaInstance, Requestable $requestInstance = NULL) {
176                 // Default is unconfirmed!
177                 $configEntry = 'user_status_unconfirmed';
178
179                 // Is the confirmation process entirely disabled?
180                 if (FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('confirm_email_enabled') === 'N') {
181                         // No confirmation of email needed
182                         $configEntry = 'user_status_confirmed';
183                 }
184
185                 // Add a lot elements to the dataset criteria
186                 foreach ($this->criteriaElements as $alias => $element) {
187                         // Do we have an alias?
188                         if (is_string($alias)) {
189                                 // Yes, so use it
190                                 $criteriaInstance->addCriteria($alias, FrameworkBootstrap::getRequestInstance()->getRequestElement($element));
191
192                                 // Debug message
193                                 //* DEBUG: */ $this->debugOutput('ALIAS: alias='.$alias.',element='.$element.'='.FrameworkBootstrap::getRequestInstance()->getRequestElement($element));
194                         } else {
195                                 // No, default entry
196                                 $criteriaInstance->addCriteria($element, FrameworkBootstrap::getRequestInstance()->getRequestElement($element));
197
198                                 // Debug message
199                                 //* DEBUG: */ $this->debugOutput('DEFAULT: element='.$element.'='.FrameworkBootstrap::getRequestInstance()->getRequestElement($element));
200                         }
201
202                         // Is this a guest account?
203                         if ((($element == 'username') || ($alias == 'username')) && (FrameworkBootstrap::getRequestInstance()->getRequestElement($element) == FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('guest_login_user'))) {
204                                 // Yes, then set the config entry to guest status
205                                 $configEntry = 'user_status_guest';
206                         }
207                 }
208
209                 // Mark the username as unique key
210                 $criteriaInstance->setUniqueKey(UserDatabaseFrontend::DB_COLUMN_USERNAME);
211
212                 // Add account status as configured
213                 $criteriaInstance->addConfiguredCriteria(UserDatabaseFrontend::DB_COLUMN_USER_STATUS, $configEntry);
214
215                 // Include registration timestamp
216                 $criteriaInstance->addCriteria('registered', date('Y-m-d H:i:s', time()));
217         }
218 }