3 * A user registration class specially for City
5 * @author Roland Haeder <webmaster@shipsimu.org>
7 * @copyright Copyright (c) 2015 City Developer Team
8 * @license GNU GPL 3.0 or any newer version
9 * @link http://www.shipsimu.org
11 * This program is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation, either version 3 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program. If not, see <http://www.gnu.org/licenses/>.
24 class CityRegistration extends BaseRegistration implements UserRegister {
28 private $hashedPassword = '';
31 * Elements for criteria
33 private $criteriaElements = array(
53 * Protected constructor
57 protected function __construct () {
58 // Call parent constructor
59 parent::__construct(__CLASS__);
63 * Create a new instance
65 * @return $registrationInstance An instance of this registration class
67 public static final function createCityRegistration () {
69 $registrationInstance = new CityRegistration();
71 // Initialize the filter chains
72 $registrationInstance->initFilterChains();
75 return $registrationInstance;
79 * Encrypt given request key or throw an exception if key was not found in
82 * @param $requestKey Key in request class
85 public function encryptPassword ($requestKey) {
86 // Check if password is found in request
87 if ($this->getRequestInstance()->isRequestElementSet($requestKey)) {
88 // So encrypt the password and store it for later usage in
91 // 1.: Get the plain password
92 $plainPassword = $this->getRequestInstance()->getRequestElement($requestKey);
94 // 2. Get a crypto helper and hash the password
95 $this->hashedPassword = ObjectFactory::createObjectByConfiguredName('crypto_class')->hashString($plainPassword);
97 // 3. Store the hash back in request
98 $this->getRequestInstance()->setRequestElement('pass_hash', $this->hashedPassword);
103 * Perform things like informing assigned affilates about new registration
104 * before registration
107 * @todo Maybe add more things to perform
109 public function doPreRegistration () {
110 // First run all pre filters
111 $this->executePreFilters();
115 * Registers the new user account by insterting the request data into the
116 * database and paying some start credits or throw exceptions if this fails
119 * @todo Maybe add more things to perform
121 public function registerNewUser () {
122 // Get a user database wrapper
123 $wrapperInstance = DatabaseWrapperFactory::createWrapperByConfiguredName('user_db_wrapper_class');
125 // Use this instance to insert the whole registration instance
126 $wrapperInstance->insertRegistrationObject($this);
130 * Perform things like notifying partner websites after registration is done
133 * @todo Maybe add more things to perform
135 public function doPostRegistration () {
136 // First run all post filters
137 $this->executePostFilters();
141 * Do the action which is required after all registration steps are done.
142 * This can be a simple redirect to another webpage or displaying a message
143 * to the user. Or this can be a login step into the newly created account.
147 public function doPostAction () {
148 // Get an action instance from our factory
149 $actionInstance = ObjectFactory::createObjectByConfiguredName('post_registration_class');
151 // Execute the action
152 $actionInstance->execute($this->getRequestInstance(), $this->getResponseInstance());
156 * Adds registration elements to a given dataset instance
158 * @param $criteriaInstance An instance of a StoreableCriteria class
159 * @param $requestInstance An instance of a Requestable class
162 public function addElementsToDataSet (StoreableCriteria $criteriaInstance, Requestable $requestInstance = NULL) {
163 // Default is unconfirmed!
164 $configEntry = 'user_status_unconfirmed';
166 // Is the confirmation process entirely disabled?
167 if ($this->getConfigInstance()->getConfigEntry('confirm_email_enabled') === 'N') {
168 // No confirmation of email needed
169 $configEntry = 'user_status_confirmed';
172 // Add a lot elements to the dataset criteria
173 foreach ($this->criteriaElements as $alias => $element) {
174 // Do we have an alias?
175 if (is_string($alias)) {
177 $criteriaInstance->addCriteria($alias, $this->getRequestInstance()->getRequestElement($element));
180 //* DEBUG: */ $this->debugOutput('ALIAS: alias='.$alias.',element='.$element.'='.$this->getRequestInstance()->getRequestElement($element));
183 $criteriaInstance->addCriteria($element, $this->getRequestInstance()->getRequestElement($element));
186 //* DEBUG: */ $this->debugOutput('DEFAULT: element='.$element.'='.$this->getRequestInstance()->getRequestElement($element));
189 // Is this a guest account?
190 if ((($element == 'username') || ($alias == 'username')) && ($this->getRequestInstance()->getRequestElement($element) == $this->getConfigInstance()->getConfigEntry('guest_login_user'))) {
191 // Yes, then set the config entry to guest status
192 $configEntry = 'user_status_guest';
196 // Mark the username as unique key
197 $criteriaInstance->setUniqueKey(UserDatabaseWrapper::DB_COLUMN_USERNAME);
199 // Add account status as configured
200 $criteriaInstance->addConfiguredCriteria(UserDatabaseWrapper::DB_COLUMN_USER_STATUS, $configEntry);
202 // Include registration timestamp
203 $criteriaInstance->addCriteria('registered', date('Y-m-d H:i:s', time()));