RegisterController.php
00001 <?php
00017 class User_RegisterController extends Dsao_Controller_Action
00018 {
00022 protected $_namespaceRegister = null;
00023
00027 protected $_userRegister = null;
00028
00034 public function activateAction()
00035 {
00036
00037 $this->_userRegister = null;
00038
00039
00040 if ($this->getRequest()->isPost())
00041 {
00042 $this->getUri()->hash = $this->getRequest()->getPost('activationKey');
00043 $this->getUri()->idUser = $this->getRequest()->getPost('idUser');
00044 }
00045
00046 $activationKey = $this->getUri()->hash;
00047 $idUser = $this->getUri()->idUser;
00048
00049
00050 if (null == $activationKey && null == $idUser)
00051 {
00052 return false;
00053 }
00054
00055
00056 if ($this->_getModel()->activateUser
00057 (Dsao_Hash_User::factory($activationKey, $this->getUri())))
00058 {
00059
00060 $this->getLog()->affirm
00061 ('user_register_activate_affirmation_activated');
00062 $this->getView()->addTemplate(false);
00063
00064 return true;
00065 }
00066
00067
00068 $this->getLog()->err('user_register_activate_error_activation_fail');
00069 }
00070
00081 public function confirmAction()
00082 {
00083
00084
00085 if (!$this->_userRegister->username
00086 || !$this->_userRegister->emailAddress
00087 || !$this->_userRegister->password)
00088 {
00089 $this->_gotoSimple('username', null, null, array(), false);
00090
00091 return false;
00092 }
00093
00094
00095 if ($this->getUri()->confirmed)
00096 {
00097
00098 $this->_userRegister->setReadOnly();
00099
00100 $this->_gotoSimple('insert', null, null, array(), false);
00101
00102 return true;
00103 }
00104
00105
00106 $this->getView()->assign(array
00107 (
00108 'userRegisterEmailAddress' =>
00109 $this->_userRegister->emailAddress,
00110
00111 'userRegisterUsername' =>
00112 $this->_userRegister->username,
00113 ));
00114 }
00115
00116
00125 public function emailAction()
00126 {
00127
00128 if (!$this->getRequest()->isPost())
00129 {
00130
00131 $this->getView()->assign('userRegisterEmailAddress',
00132 $this->_userRegister->emailAddress);
00133
00134 return true;
00135 }
00136
00137
00138 $emailAddress = strtolower($this->getRequest()->getPost('emailAddress'));
00139 $emailAddressVerification = strtolower($this->getRequest()->getPost
00140 ('emailAddressVerification'));
00141
00142
00143 $this->getView()->assign('userRegisterEmailAddress', $emailAddress);
00144
00145
00146 if ($emailAddress != $emailAddressVerification)
00147 {
00148
00149 $this->getLog()->err('user_register_email_error_nonconform');
00150
00151 return false;
00152 }
00153
00154
00155 $validator = new Zend_Validate_EmailAddress();
00156
00157
00158 if ($validator->validateMxSupported())
00159 {
00160 $validator->setValidateMx(true);
00161 }
00162
00163
00164 if (!$validator->isValid($emailAddress))
00165 {
00166 $this->getLog()->err('user_register_email_error_invalid');
00167
00168 return false;
00169 }
00170
00171
00172 if (!$this->_getModel()->isUniqueEmailAddress($emailAddress))
00173 {
00174 $this->getLog()->err('user_register_email_error_not_unique');
00175
00176 return false;
00177 }
00178
00179
00180
00181 $this->_userRegister->emailAddress = $emailAddress;
00182
00183 $this->_gotoSimple('password', null, null, array(), false);
00184
00185 return true;
00186 }
00187
00202 public function insertAction()
00203 {
00204
00205
00206 if (!$this->_userRegister->isReadOnly())
00207 {
00208 $this->_gotoSimple('confirm', null, null, array(), false);
00209
00210 return false;
00211 }
00212
00213 $this->getView()->addTemplate(false);
00214
00215
00216 if ($this->_getModel()->isUniqueUsername($this->_userRegister->username))
00217 {
00218
00219 $this->_userRegister->setReadOnly(false);
00220
00221
00222 $this->_userRegister->layout = $this->getView()->getLayoutDefault();
00223
00224
00225 $this->_getModel()->insertUser($this->_userRegister);
00226
00227
00228 $this->getLog()->affirm
00229 ('user_register_insert_affirmation_inserted');
00230
00231 $this->getLog()->affirm
00232 ('user_register_insert_affirmation_activation_mail_sent');
00233 }
00234 else
00235 {
00236
00237 $this->getLog()->err('user_register_insert_error_user_exists');
00238 }
00239
00240
00241 Zend_Session::namespaceUnset('user_register');
00242 $this->_userRegister = null;
00243
00244 return true;
00245 }
00246
00259 public function passwordAction()
00260 {
00261
00262 if (!$this->getRequest()->isPost())
00263 {
00264
00265 $this->getLog()->info('user_register_password_info_encryption');
00266
00267 return false;
00268 }
00269
00270
00271 $password = $this->getRequest()->getPost('password');
00272 $passwordVerification = $this->getRequest()->getPost('passwordVerification');
00273
00274
00275 if ($password != $passwordVerification)
00276 {
00277
00278 $this->getLog()->err('user_register_password_error_nonconform');
00279
00280 return false;
00281 }
00282
00283
00284 $validator = new Zend_Validate();
00285 $validator->addValidator(new Dsao_Validate_Password());
00286
00287
00288 if (!$validator->isValid($password))
00289 {
00290 $this->getLog()->err('user_register_password_error_invalid');
00291
00292 return false;
00293 }
00294
00295
00296 $this->_userRegister->password = md5($password);
00297
00298 $this->_gotoSimple('confirm', null, null, array(), false);
00299 }
00300
00306 public function postDispatch()
00307 {
00308
00309 if (null != $this->_userRegister)
00310 {
00311
00312 $this->_namespaceRegister->user = serialize($this->_userRegister);
00313 }
00314 }
00315
00316 public function preDispatch()
00317 {
00318 $this->_setDefaultModelClass('User_Register');
00319
00320
00321 if (!Zend_Session::namespaceIsset('user_register'))
00322 {
00323
00324 $this->_namespaceRegister = new Zend_Session_Namespace('user_register');
00325
00326
00327 $this->_namespaceRegister->setExpirationSeconds(24*60*60);
00328
00329
00330 $this->_userRegister = new Dsao_User();
00331 }
00332 else
00333
00334 {
00335 $this->_namespaceRegister = new Zend_Session_Namespace('user_register');
00336
00337
00338 $this->_userRegister = unserialize($this->_namespaceRegister->user);
00339
00340
00341
00342 if ($this->_userRegister->isReadOnly()
00343 && $this->getRequest()->getActionName() != 'insert')
00344 {
00345 $this->_gotoSimple('insert', null, null, array(), false);
00346 }
00347 }
00348 }
00349
00359 public function usernameAction()
00360 {
00361
00362 $this->getView()->assign
00363 ('userRegisterUsername', $this->_userRegister->username);
00364
00365
00366 if (!$this->getRequest()->isPost())
00367 {
00368 return true;
00369 }
00370
00371
00372 $username = $this->getRequest()->getPost('username');
00373 $usernameSelection = $this->getRequest()->getPost('usernameSelection');
00374
00375
00376 if (null !== $usernameSelection && $this->_namespaceRegister->suggestions)
00377 {
00378
00379 if (!$this->_namespaceRegister->suggestions->offsetExists
00380 ($usernameSelection))
00381 {
00382 $usernameSelection = 0;
00383 }
00384
00385
00386 $username = $this->_namespaceRegister->suggestions->offsetGet
00387 ($usernameSelection);
00388
00389
00390 $this->_namespaceRegister->suggestions = null;
00391 }
00392
00393
00394 $validator = new Zend_Validate();
00395 $validator->addValidator(new Dsao_Validate_Username());
00396
00397
00398 if (!$validator->isValid($username))
00399 {
00400
00401 $this->getLog()->err('user_register_username_error_invalid');
00402
00403 return false;
00404 }
00405
00406
00407 if (!$this->_getModel()->isUniqueUsername($username))
00408 {
00409
00410 $suggestions = $this->_getModel()->getUsernameSuggestions($username);
00411
00412
00413 $this->_namespaceRegister->suggestions = $suggestions;
00414
00415 $this->getView()->assign(
00416 array(
00417 'userRegisterSuggestions' => $suggestions,
00418 'userRegisterUsername' => $username,
00419 ));
00420
00421 $this->getLog()->info('user_register_username_info_not_unique');
00422
00423 return false;
00424 }
00425
00426
00427 $this->_userRegister->username = $username;
00428
00429
00430 $this->_gotoSimple('email', null, null, array(), false);
00431
00432 return true;
00433 }
00434 }