0a8563cd10c5754e8cb3536e65264e0a0e898e73
[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                 // Set part description
59                 $this->setObjectDescription("Ship-Simu registration class");
60
61                 // Create unique ID number
62                 $this->generateUniqueId();
63         }
64
65         /**
66          * Create a new instance
67          *
68          * @return      $registrationInstance   An instance of this registration class
69          */
70         public final static function createShipSimuRegistration () {
71                 // Get a new instance
72                 $registrationInstance = new ShipSimuRegistration();
73
74                 // Initialize the filter chains
75                 $registrationInstance->initFilterChains();
76
77                 // And return it
78                 return $registrationInstance;
79         }
80
81         /**
82          * Encrypt the given request key or throw an exception if the key was not
83          * found in the request
84          *
85          * @param       $requestKey             Key in request class
86          * @return      void
87          */
88         public function encryptPassword ($requestKey) {
89                 // Check if the password is found in the request
90                 if ($this->getRequestInstance()->isRequestElementSet($requestKey)) {
91                         // So encrypt the password and store it for later usage in
92                         // the request:
93                         // 1.: Get the plain password
94                         $plainPassword = $this->getRequestInstance()->getRequestElement($requestKey);
95                         // 2. Get a crypto helper and hash the password
96                         $this->hashedPassword = ObjectFactory::createObjectByConfiguredName('crypto_heler')->hashPassword($plainPassword);
97                         // 3. Store the hash back in the request
98                         $this->getRequestInstance()->setRequestElement('pass_hash', $this->hashedPassword);
99                 }
100         }
101
102         /**
103          * Perform things like informing assigned affilates about new registration
104          * before registration
105          *
106          * @return      void
107          */
108         public function doPreRegistration () {
109                 // First run all pre filters
110                 $this->executePreFilters();
111         }
112
113         /**
114          * Registers the new user account by insterting the request data into the
115          * database and paying some start credits or throw exceptions if this fails
116          *
117          * @return      void
118          */
119         public function registerNewUser () {
120                 // Get a user database wrapper
121                 $wrapperInstance = ObjectFactory::createObjectByConfiguredName('user_db_wrapper');
122
123                 // Use this instance to insert the whole registration instance
124                 $wrapperInstance->insertRegistrationObject($this);
125         }
126
127         /**
128          * Perform things like notifying partner websites after registration is done
129          *
130          * @return      void
131          */
132         public function doPostRegistration () {
133                 // First run all post filters
134                 $this->executePostFilters();
135         }
136
137         /**
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.
141          *
142          * @return      void
143          */
144         public function doPostAction () {
145                 // Get an action instance from our factory
146                 $actionInstance = ObjectFactory::createObjectByConfiguredName('post_registration_action');
147
148                 // Execute the action
149                 $actionInstance->execute($this->getRequestInstance(), $this->getResponseInstance());
150         }
151
152         /**
153          * Adds registration elements to a given dataset instance
154          *
155          * @param       $criteriaInstance       An instance of a storeable criteria
156          * @return      void
157          */
158         public function addElementsToDataSet (StoreableCriteria $criteriaInstance) {
159                 // Add a lot elements to the dataset criteria
160                 foreach ($this->criteriaElements as $alias=>$element) {
161                         // Do we have an alias?
162                         if (is_string($alias)) {
163                                 // Yes, so use it
164                                 $criteriaInstance->addCriteria($alias, $this->getRequestInstance()->getRequestElement($element));
165                         } else {
166                                 // No, default entry
167                                 $criteriaInstance->addCriteria($element, $this->getRequestInstance()->getRequestElement($element));
168                         }
169                 } // END - foreach
170
171                 // Mark the username as unique key
172                 $criteriaInstance->setUniqueKey('username');
173
174                 // Add account status as configured
175                 $criteriaInstance->addConfiguredCriteria('user_status', 'user_status_register');
176         }
177 }
178
179 //
180 ?>