Constants PATH and _DB_TYPE replaced
[shipsimu.git] / application / ship-simu / main / registration / class_ShipSimuRegistration.php
1 <?php
2 /**
3  * A user registration specially for Ship-Simu
4  *
5  * @author              Roland Haeder <webmaster@ship-simu.org>
6  * @version             0.0.0
7  * @copyright   Copyright (c) 2007, 2008 Roland Haeder, this is free software
8  * @license             GNU GPL 3.0 or any newer version
9  * @link                http://www.ship-simu.org
10  *
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.
15  *
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.
20  *
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/>.
23  */
24 class ShipSimuRegistration extends BaseRegistration {
25         /**
26          * Hashed password
27          */
28         private $hashedPassword = "";
29
30         /**
31          * Elements for criteria
32          */
33         private $criteriaElements = array(
34                 'username',
35                 'pass_hash',
36                 'email' => 'email1',
37                 'surname',
38                 'family',
39                 'street',
40                 'zip',
41                 'city',
42                 'icq',
43                 'jabber',
44                 'yahoo',
45                 'aol',
46                 'msn'
47         );
48
49         /**
50          * Protected constructor
51          *
52          * @return      void
53          */
54         protected function __construct () {
55                 // Call parent constructor
56                 parent::__construct(__CLASS__);
57         }
58
59         /**
60          * Create a new instance
61          *
62          * @return      $registrationInstance   An instance of this registration class
63          */
64         public final static function createShipSimuRegistration () {
65                 // Get a new instance
66                 $registrationInstance = new ShipSimuRegistration();
67
68                 // Initialize the filter chains
69                 $registrationInstance->initFilterChains();
70
71                 // And return it
72                 return $registrationInstance;
73         }
74
75         /**
76          * Encrypt the given request key or throw an exception if the key was not
77          * found in the request
78          *
79          * @param       $requestKey             Key in request class
80          * @return      void
81          */
82         public function encryptPassword ($requestKey) {
83                 // Check if the password is found in the request
84                 if ($this->getRequestInstance()->isRequestElementSet($requestKey)) {
85                         // So encrypt the password and store it for later usage in
86                         // the request:
87
88                         // 1.: Get the plain password
89                         $plainPassword = $this->getRequestInstance()->getRequestElement($requestKey);
90
91                         // 2. Get a crypto helper and hash the password
92                         $this->hashedPassword = ObjectFactory::createObjectByConfiguredName('crypto_class')->hashString($plainPassword);
93
94                         // 3. Store the hash back in the request
95                         $this->getRequestInstance()->setRequestElement('pass_hash', $this->hashedPassword);
96                 }
97         }
98
99         /**
100          * Perform things like informing assigned affilates about new registration
101          * before registration
102          *
103          * @return      void
104          */
105         public function doPreRegistration () {
106                 // First run all pre filters
107                 $this->executePreFilters();
108         }
109
110         /**
111          * Registers the new user account by insterting the request data into the
112          * database and paying some start credits or throw exceptions if this fails
113          *
114          * @return      void
115          */
116         public function registerNewUser () {
117                 // Get a user database wrapper
118                 $wrapperInstance = ObjectFactory::createObjectByConfiguredName('user_db_wrapper_class');
119
120                 // Use this instance to insert the whole registration instance
121                 $wrapperInstance->insertRegistrationObject($this);
122         }
123
124         /**
125          * Perform things like notifying partner websites after registration is done
126          *
127          * @return      void
128          */
129         public function doPostRegistration () {
130                 // First run all post filters
131                 $this->executePostFilters();
132         }
133
134         /**
135          * Do the action which is required after all registration steps are done.
136          * This can be a simple redirect to another webpage or displaying a message
137          * to the user. Or this can be a login step into the newly created account.
138          *
139          * @return      void
140          */
141         public function doPostAction () {
142                 // Get an action instance from our factory
143                 $actionInstance = ObjectFactory::createObjectByConfiguredName('post_registration_class');
144
145                 // Execute the action
146                 $actionInstance->execute($this->getRequestInstance(), $this->getResponseInstance());
147         }
148
149         /**
150          * Adds registration elements to a given dataset instance
151          *
152          * @param       $criteriaInstance       An instance of a storeable criteria
153          * @return      void
154          */
155         public function addElementsToDataSet (StoreableCriteria $criteriaInstance) {
156                 // Default is unconfirmed!
157                 $configEntry = 'user_status_unconfirmed';
158
159                 // Is the confirmation process entirely disabled?
160                 if ($this->getConfigInstance()->readConfig('confirm_email_enabled') === "N") {
161                         // No confirmation of email needed
162                         $configEntry = 'user_status_confirmed';
163                 } // END - if
164
165                 // Add a lot elements to the dataset criteria
166                 foreach ($this->criteriaElements as $alias=>$element) {
167                         // Do we have an alias?
168                         if (is_string($alias)) {
169                                 // Yes, so use it
170                                 $criteriaInstance->addCriteria($alias, $this->getRequestInstance()->getRequestElement($element));
171                         } else {
172                                 // No, default entry
173                                 $criteriaInstance->addCriteria($element, $this->getRequestInstance()->getRequestElement($element));
174                         }
175
176                         // Is this a guest account?
177                         if ((($element == "username") || ($alias == "username")) && ($this->getRequestInstance()->getRequestElement($element) == $this->getConfigInstance()->readConfig('guest_login_user'))) {
178                                 // Yes, then set the config entry to guest status
179                                 $configEntry = 'user_status_guest';
180                         } // END - if
181                 } // END - foreach
182
183                 // Mark the username as unique key
184                 $criteriaInstance->setUniqueKey('username');
185
186                 // Add account status as configured
187                 $criteriaInstance->addConfiguredCriteria(UserDatabaseWrapper::DB_COLUMN_USER_STATUS, $configEntry);
188
189                 // Include registration timestamp
190                 $criteriaInstance->addCriteria('registered', date("Y-m-d H:i:s", time()));
191         }
192 }
193
194 //
195 ?>