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