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\Factory\Database\Wrapper\DatabaseWrapperFactory;
9 use Org\Mxchange\CoreFramework\Factory\ObjectFactory;
10 use Org\Mxchange\CoreFramework\Request\Requestable;
13 * A user registration class specially for City
15 * @author Roland Haeder <webmaster@shipsimu.org>
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
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.
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.
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/>.
34 class CityRegistration extends BaseRegistration implements UserRegister {
38 private $hashedPassword = '';
41 * Elements for criteria
43 private $criteriaElements = array(
63 * Protected constructor
67 protected function __construct () {
68 // Call parent constructor
69 parent::__construct(__CLASS__);
73 * Create a new instance
75 * @return $registrationInstance An instance of this registration class
77 public static final function createCityRegistration () {
79 $registrationInstance = new CityRegistration();
81 // Initialize the filter chains
82 $registrationInstance->initFilterChains();
85 return $registrationInstance;
89 * Encrypt given request key or throw an exception if key was not found in
92 * @param $requestKey Key in request class
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
101 // 1.: Get the plain password
102 $plainPassword = FrameworkBootstrap::getRequestInstance()->getRequestElement($requestKey);
104 // 2. Get a crypto helper and hash the password
105 $this->hashedPassword = ObjectFactory::createObjectByConfiguredName('crypto_class')->hashString($plainPassword);
107 // 3. Store the hash back in request
108 FrameworkBootstrap::getRequestInstance()->setRequestElement('pass_hash', $this->hashedPassword);
113 * Perform things like informing assigned affilates about new registration
114 * before registration
117 * @todo Maybe add more things to perform
119 public function doPreRegistration () {
120 // First run all pre filters
121 $this->executePreFilters();
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
129 * @todo Maybe add more things to perform
131 public function registerNewUser () {
132 // Get a user database wrapper
133 $wrapperInstance = DatabaseWrapperFactory::createWrapperByConfiguredName('user_db_wrapper_class');
135 // Use this instance to insert the whole registration instance
136 $wrapperInstance->insertRegistrationObject($this);
140 * Perform things like notifying partner websites after registration is done
143 * @todo Maybe add more things to perform
145 public function doPostRegistration () {
146 // First run all post filters
147 $this->executePostFilters();
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.
157 public function doPostAction () {
158 // Get an action instance from our factory
159 $actionInstance = ObjectFactory::createObjectByConfiguredName('post_registration_class');
161 // Execute the action
162 $actionInstance->execute(FrameworkBootstrap::getRequestInstance(), $this->getResponseInstance());
166 * Adds registration elements to a given dataset instance
168 * @param $criteriaInstance An instance of a StoreableCriteria class
169 * @param $requestInstance An instance of a Requestable class
172 public function addElementsToDataSet (StoreableCriteria $criteriaInstance, Requestable $requestInstance = NULL) {
173 // Default is unconfirmed!
174 $configEntry = 'user_status_unconfirmed';
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';
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)) {
187 $criteriaInstance->addCriteria($alias, FrameworkBootstrap::getRequestInstance()->getRequestElement($element));
190 //* DEBUG: */ $this->debugOutput('ALIAS: alias='.$alias.',element='.$element.'='.FrameworkBootstrap::getRequestInstance()->getRequestElement($element));
193 $criteriaInstance->addCriteria($element, FrameworkBootstrap::getRequestInstance()->getRequestElement($element));
196 //* DEBUG: */ $this->debugOutput('DEFAULT: element='.$element.'='.FrameworkBootstrap::getRequestInstance()->getRequestElement($element));
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';
206 // Mark the username as unique key
207 $criteriaInstance->setUniqueKey(UserDatabaseWrapper::DB_COLUMN_USERNAME);
209 // Add account status as configured
210 $criteriaInstance->addConfiguredCriteria(UserDatabaseWrapper::DB_COLUMN_USER_STATUS, $configEntry);
212 // Include registration timestamp
213 $criteriaInstance->addCriteria('registered', date('Y-m-d H:i:s', time()));