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