3 * A user registration class specially for Ship-Simu
5 * @author Roland Haeder <webmaster@ship-simu.org>
7 * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 Ship-Simu Developer Team
8 * @license GNU GPL 3.0 or any newer version
9 * @link http://www.ship-simu.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 ShipSimuRegistration extends BaseRegistration implements UserRegister {
28 private $hashedPassword = '';
31 * Elements for criteria
33 private $criteriaElements = array(
50 * Protected constructor
54 protected function __construct () {
55 // Call parent constructor
56 parent::__construct(__CLASS__);
60 * Create a new instance
62 * @return $registrationInstance An instance of this registration class
64 public final static function createShipSimuRegistration () {
66 $registrationInstance = new ShipSimuRegistration();
68 // Initialize the filter chains
69 $registrationInstance->initFilterChains();
72 return $registrationInstance;
76 * Encrypt given request key or throw an exception if key was not found in
79 * @param $requestKey Key in request class
82 public function encryptPassword ($requestKey) {
83 // Check if password is found in request
84 if ($this->getRequestInstance()->isRequestElementSet($requestKey)) {
85 // So encrypt the password and store it for later usage in
88 // 1.: Get the plain password
89 $plainPassword = $this->getRequestInstance()->getRequestElement($requestKey);
91 // 2. Get a crypto helper and hash the password
92 $this->hashedPassword = ObjectFactory::createObjectByConfiguredName('crypto_class')->hashString($plainPassword);
94 // 3. Store the hash back in request
95 $this->getRequestInstance()->setRequestElement('pass_hash', $this->hashedPassword);
100 * Perform things like informing assigned affilates about new registration
101 * before registration
104 * @todo Maybe add more things to perform
106 public function doPreRegistration () {
107 // First run all pre filters
108 $this->executePreFilters();
112 * Registers the new user account by insterting the request data into the
113 * database and paying some start credits or throw exceptions if this fails
116 * @todo Maybe add more things to perform
118 public function registerNewUser () {
119 // Get a user database wrapper
120 $wrapperInstance = ObjectFactory::createObjectByConfiguredName('user_db_wrapper_class');
122 // Use this instance to insert the whole registration instance
123 $wrapperInstance->insertRegistrationObject($this);
127 * Perform things like notifying partner websites after registration is done
130 * @todo Maybe add more things to perform
132 public function doPostRegistration () {
133 // First run all post filters
134 $this->executePostFilters();
138 * Do the action which is required after all registration steps are done.
139 * This can be a simple redirect to another webpage or displaying a message
140 * to the user. Or this can be a login step into the newly created account.
144 public function doPostAction () {
145 // Get an action instance from our factory
146 $actionInstance = ObjectFactory::createObjectByConfiguredName('post_registration_class');
148 // Execute the action
149 $actionInstance->execute($this->getRequestInstance(), $this->getResponseInstance());
153 * Adds registration elements to a given dataset instance
155 * @param $criteriaInstance An instance of a storeable criteria
158 public function addElementsToDataSet (StoreableCriteria $criteriaInstance) {
159 // Default is unconfirmed!
160 $configEntry = 'user_status_unconfirmed';
162 // Is the confirmation process entirely disabled?
163 if ($this->getConfigInstance()->getConfigEntry('confirm_email_enabled') === 'N') {
164 // No confirmation of email needed
165 $configEntry = 'user_status_confirmed';
168 // Add a lot elements to the dataset criteria
169 foreach ($this->criteriaElements as $alias => $element) {
170 // Do we have an alias?
171 if (is_string($alias)) {
173 $criteriaInstance->addCriteria($alias, $this->getRequestInstance()->getRequestElement($element));
176 $criteriaInstance->addCriteria($element, $this->getRequestInstance()->getRequestElement($element));
179 // Is this a guest account?
180 if ((($element == 'username') || ($alias == 'username')) && ($this->getRequestInstance()->getRequestElement($element) == $this->getConfigInstance()->getConfigEntry('guest_login_user'))) {
181 // Yes, then set the config entry to guest status
182 $configEntry = 'user_status_guest';
186 // Mark the username as unique key
187 $criteriaInstance->setUniqueKey(UserDatabaseWrapper::DB_COLUMN_USERNAME);
189 // Add account status as configured
190 $criteriaInstance->addConfiguredCriteria(UserDatabaseWrapper::DB_COLUMN_USER_STATUS, $configEntry);
192 // Include registration timestamp
193 $criteriaInstance->addCriteria('registered', date('Y-m-d H:i:s', time()));