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