3 namespace Org\Mxchange\City\Registration;
5 // Import framework stuff
6 use Org\Mxchange\CoreFramework\Request\Requestable;
9 * A user registration class specially for City
11 * @author Roland Haeder <webmaster@shipsimu.org>
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
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.
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.
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/>.
30 class CityRegistration extends BaseRegistration implements UserRegister {
34 private $hashedPassword = '';
37 * Elements for criteria
39 private $criteriaElements = array(
59 * Protected constructor
63 protected function __construct () {
64 // Call parent constructor
65 parent::__construct(__CLASS__);
69 * Create a new instance
71 * @return $registrationInstance An instance of this registration class
73 public static final function createCityRegistration () {
75 $registrationInstance = new CityRegistration();
77 // Initialize the filter chains
78 $registrationInstance->initFilterChains();
81 return $registrationInstance;
85 * Encrypt given request key or throw an exception if key was not found in
88 * @param $requestKey Key in request class
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
97 // 1.: Get the plain password
98 $plainPassword = $this->getRequestInstance()->getRequestElement($requestKey);
100 // 2. Get a crypto helper and hash the password
101 $this->hashedPassword = ObjectFactory::createObjectByConfiguredName('crypto_class')->hashString($plainPassword);
103 // 3. Store the hash back in request
104 $this->getRequestInstance()->setRequestElement('pass_hash', $this->hashedPassword);
109 * Perform things like informing assigned affilates about new registration
110 * before registration
113 * @todo Maybe add more things to perform
115 public function doPreRegistration () {
116 // First run all pre filters
117 $this->executePreFilters();
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
125 * @todo Maybe add more things to perform
127 public function registerNewUser () {
128 // Get a user database wrapper
129 $wrapperInstance = DatabaseWrapperFactory::createWrapperByConfiguredName('user_db_wrapper_class');
131 // Use this instance to insert the whole registration instance
132 $wrapperInstance->insertRegistrationObject($this);
136 * Perform things like notifying partner websites after registration is done
139 * @todo Maybe add more things to perform
141 public function doPostRegistration () {
142 // First run all post filters
143 $this->executePostFilters();
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.
153 public function doPostAction () {
154 // Get an action instance from our factory
155 $actionInstance = ObjectFactory::createObjectByConfiguredName('post_registration_class');
157 // Execute the action
158 $actionInstance->execute($this->getRequestInstance(), $this->getResponseInstance());
162 * Adds registration elements to a given dataset instance
164 * @param $criteriaInstance An instance of a StoreableCriteria class
165 * @param $requestInstance An instance of a Requestable class
168 public function addElementsToDataSet (StoreableCriteria $criteriaInstance, Requestable $requestInstance = NULL) {
169 // Default is unconfirmed!
170 $configEntry = 'user_status_unconfirmed';
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';
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)) {
183 $criteriaInstance->addCriteria($alias, $this->getRequestInstance()->getRequestElement($element));
186 //* DEBUG: */ $this->debugOutput('ALIAS: alias='.$alias.',element='.$element.'='.$this->getRequestInstance()->getRequestElement($element));
189 $criteriaInstance->addCriteria($element, $this->getRequestInstance()->getRequestElement($element));
192 //* DEBUG: */ $this->debugOutput('DEFAULT: element='.$element.'='.$this->getRequestInstance()->getRequestElement($element));
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';
202 // Mark the username as unique key
203 $criteriaInstance->setUniqueKey(UserDatabaseWrapper::DB_COLUMN_USERNAME);
205 // Add account status as configured
206 $criteriaInstance->addConfiguredCriteria(UserDatabaseWrapper::DB_COLUMN_USER_STATUS, $configEntry);
208 // Include registration timestamp
209 $criteriaInstance->addCriteria('registered', date('Y-m-d H:i:s', time()));