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