3 namespace Org\Mxchange\City\Registration;
5 // Import framework stuff
6 use Org\Mxchange\CoreFramework\Bootstrap\FrameworkBootstrap;
7 use Org\Mxchange\CoreFramework\Criteria\Storing\StoreableCriteria;
8 use Org\Mxchange\CoreFramework\Database\Frontend\User\UserDatabaseFrontend;
9 use Org\Mxchange\CoreFramework\Factory\Database\Frontend\DatabaseFrontendFactory;
10 use Org\Mxchange\CoreFramework\Factory\Object\ObjectFactory;
11 use Org\Mxchange\CoreFramework\Registration\BaseRegistration;
12 use Org\Mxchange\CoreFramework\Registration\User\UserRegister;
13 use Org\Mxchange\CoreFramework\Request\Requestable;
16 * A user registration class specially for City
18 * @author Roland Haeder <webmaster@shipsimu.org>
20 * @copyright Copyright (c) 2015, 2016 City Developer Team
21 * @license GNU GPL 3.0 or any newer version
22 * @link http://www.shipsimu.org
24 * This program is free software: you can redistribute it and/or modify
25 * it under the terms of the GNU General Public License as published by
26 * the Free Software Foundation, either version 3 of the License, or
27 * (at your option) any later version.
29 * This program is distributed in the hope that it will be useful,
30 * but WITHOUT ANY WARRANTY; without even the implied warranty of
31 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
32 * GNU General Public License for more details.
34 * You should have received a copy of the GNU General Public License
35 * along with this program. If not, see <http://www.gnu.org/licenses/>.
37 class CityRegistration extends BaseRegistration implements UserRegister {
41 private $hashedPassword = '';
44 * Elements for criteria
46 private $criteriaElements = array(
66 * Protected constructor
70 protected function __construct () {
71 // Call parent constructor
72 parent::__construct(__CLASS__);
76 * Create a new instance
78 * @return $registrationInstance An instance of this registration class
80 public static final function createCityRegistration () {
82 $registrationInstance = new CityRegistration();
84 // Initialize the filter chains
85 $registrationInstance->initFilterChains();
88 return $registrationInstance;
92 * Encrypt given request key or throw an exception if key was not found in
95 * @param $requestKey Key in request class
98 public function encryptPassword ($requestKey) {
99 // Check if password is found in request
100 if (FrameworkBootstrap::getRequestInstance()->isRequestElementSet($requestKey)) {
101 // So encrypt the password and store it for later usage in
104 // 1.: Get the plain password
105 $plainPassword = FrameworkBootstrap::getRequestInstance()->getRequestElement($requestKey);
107 // 2. Get a crypto helper and hash the password
108 $this->hashedPassword = ObjectFactory::createObjectByConfiguredName('crypto_class')->hashString($plainPassword);
110 // 3. Store the hash back in request
111 FrameworkBootstrap::getRequestInstance()->setRequestElement('pass_hash', $this->hashedPassword);
116 * Perform things like informing assigned affilates about new registration
117 * before registration
120 * @todo Maybe add more things to perform
122 public function doPreRegistration () {
123 // First run all pre filters
124 $this->executePreFilters();
128 * Registers the new user account by insterting the request data into the
129 * database and paying some start credits or throw exceptions if this fails
132 * @todo Maybe add more things to perform
134 public function registerNewUser () {
135 // Get a user database frontend
136 $frontendInstance = DatabaseFrontendFactory::createFrontendByConfiguredName('user_db_frontend_class');
138 // Use this instance to insert the whole registration instance
139 $frontendInstance->insertRegistrationObject($this);
143 * Perform things like notifying partner websites after registration is done
146 * @todo Maybe add more things to perform
148 public function doPostRegistration () {
149 // First run all post filters
150 $this->executePostFilters();
154 * Do the action which is required after all registration steps are done.
155 * This can be a simple redirect to another webpage or displaying a message
156 * to the user. Or this can be a login step into the newly created account.
160 public function doPostAction () {
161 // Get an action instance from our factory
162 $actionInstance = ObjectFactory::createObjectByConfiguredName('post_registration_class');
164 // Execute the action
165 $actionInstance->execute(FrameworkBootstrap::getRequestInstance(), FrameworkBootstrap::getResponseInstance());
169 * Adds registration elements to a given dataset instance
171 * @param $criteriaInstance An instance of a StoreableCriteria class
172 * @param $requestInstance An instance of a Requestable class
175 public function addElementsToDataSet (StoreableCriteria $criteriaInstance, Requestable $requestInstance = NULL) {
176 // Default is unconfirmed!
177 $configEntry = 'user_status_unconfirmed';
179 // Is the confirmation process entirely disabled?
180 if (FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('confirm_email_enabled') === 'N') {
181 // No confirmation of email needed
182 $configEntry = 'user_status_confirmed';
185 // Add a lot elements to the dataset criteria
186 foreach ($this->criteriaElements as $alias => $element) {
187 // Do we have an alias?
188 if (is_string($alias)) {
190 $criteriaInstance->addCriteria($alias, FrameworkBootstrap::getRequestInstance()->getRequestElement($element));
193 //* DEBUG: */ $this->debugOutput('ALIAS: alias='.$alias.',element='.$element.'='.FrameworkBootstrap::getRequestInstance()->getRequestElement($element));
196 $criteriaInstance->addCriteria($element, FrameworkBootstrap::getRequestInstance()->getRequestElement($element));
199 //* DEBUG: */ $this->debugOutput('DEFAULT: element='.$element.'='.FrameworkBootstrap::getRequestInstance()->getRequestElement($element));
202 // Is this a guest account?
203 if ((($element == 'username') || ($alias == 'username')) && (FrameworkBootstrap::getRequestInstance()->getRequestElement($element) == FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('guest_login_user'))) {
204 // Yes, then set the config entry to guest status
205 $configEntry = 'user_status_guest';
209 // Mark the username as unique key
210 $criteriaInstance->setUniqueKey(UserDatabaseFrontend::DB_COLUMN_USERNAME);
212 // Add account status as configured
213 $criteriaInstance->addConfiguredCriteria(UserDatabaseFrontend::DB_COLUMN_USER_STATUS, $configEntry);
215 // Include registration timestamp
216 $criteriaInstance->addCriteria('registered', date('Y-m-d H:i:s', time()));