3 namespace Org\Mxchange\City\Registration;
5 // Import framework stuff
6 use Org\Mxchange\CoreFramework\Factory\ObjectFactory;
7 use Org\Mxchange\CoreFramework\Request\Requestable;
10 * A user registration class specially for City
12 * @author Roland Haeder <webmaster@shipsimu.org>
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
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.
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.
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/>.
31 class CityRegistration extends BaseRegistration implements UserRegister {
35 private $hashedPassword = '';
38 * Elements for criteria
40 private $criteriaElements = array(
60 * Protected constructor
64 protected function __construct () {
65 // Call parent constructor
66 parent::__construct(__CLASS__);
70 * Create a new instance
72 * @return $registrationInstance An instance of this registration class
74 public static final function createCityRegistration () {
76 $registrationInstance = new CityRegistration();
78 // Initialize the filter chains
79 $registrationInstance->initFilterChains();
82 return $registrationInstance;
86 * Encrypt given request key or throw an exception if key was not found in
89 * @param $requestKey Key in request class
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
98 // 1.: Get the plain password
99 $plainPassword = $this->getRequestInstance()->getRequestElement($requestKey);
101 // 2. Get a crypto helper and hash the password
102 $this->hashedPassword = ObjectFactory::createObjectByConfiguredName('crypto_class')->hashString($plainPassword);
104 // 3. Store the hash back in request
105 $this->getRequestInstance()->setRequestElement('pass_hash', $this->hashedPassword);
110 * Perform things like informing assigned affilates about new registration
111 * before registration
114 * @todo Maybe add more things to perform
116 public function doPreRegistration () {
117 // First run all pre filters
118 $this->executePreFilters();
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
126 * @todo Maybe add more things to perform
128 public function registerNewUser () {
129 // Get a user database wrapper
130 $wrapperInstance = DatabaseWrapperFactory::createWrapperByConfiguredName('user_db_wrapper_class');
132 // Use this instance to insert the whole registration instance
133 $wrapperInstance->insertRegistrationObject($this);
137 * Perform things like notifying partner websites after registration is done
140 * @todo Maybe add more things to perform
142 public function doPostRegistration () {
143 // First run all post filters
144 $this->executePostFilters();
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.
154 public function doPostAction () {
155 // Get an action instance from our factory
156 $actionInstance = ObjectFactory::createObjectByConfiguredName('post_registration_class');
158 // Execute the action
159 $actionInstance->execute($this->getRequestInstance(), $this->getResponseInstance());
163 * Adds registration elements to a given dataset instance
165 * @param $criteriaInstance An instance of a StoreableCriteria class
166 * @param $requestInstance An instance of a Requestable class
169 public function addElementsToDataSet (StoreableCriteria $criteriaInstance, Requestable $requestInstance = NULL) {
170 // Default is unconfirmed!
171 $configEntry = 'user_status_unconfirmed';
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';
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)) {
184 $criteriaInstance->addCriteria($alias, $this->getRequestInstance()->getRequestElement($element));
187 //* DEBUG: */ $this->debugOutput('ALIAS: alias='.$alias.',element='.$element.'='.$this->getRequestInstance()->getRequestElement($element));
190 $criteriaInstance->addCriteria($element, $this->getRequestInstance()->getRequestElement($element));
193 //* DEBUG: */ $this->debugOutput('DEFAULT: element='.$element.'='.$this->getRequestInstance()->getRequestElement($element));
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';
203 // Mark the username as unique key
204 $criteriaInstance->setUniqueKey(UserDatabaseWrapper::DB_COLUMN_USERNAME);
206 // Add account status as configured
207 $criteriaInstance->addConfiguredCriteria(UserDatabaseWrapper::DB_COLUMN_USER_STATUS, $configEntry);
209 // Include registration timestamp
210 $criteriaInstance->addCriteria('registered', date('Y-m-d H:i:s', time()));