pages/user/CreateAccountHandler.inc.php

Go to the documentation of this file.
00001 <?php
00002 
00015 //$Id$
00016 
00017 import('pages.user.UserHandler');
00018 
00019 class CreateAccountHandler extends UserHandler {
00023    function CreateAccountHandler() {
00024       parent::UserHandler();
00025    }
00026 
00030    function account() {
00031       $this->validate();
00032       $this->setupTemplate(true);
00033       
00034       $conference =& Request::getConference();
00035       $schedConf =& Request::getSchedConf();
00036 
00037       if ($conference != null && $schedConf != null) {
00038 
00039          // We're trying to create an account for a specific scheduled conference
00040          import('user.form.CreateAccountForm');
00041 
00042          if (checkPhpVersion('5.0.0')) { // WARNING: This form needs $this in constructor
00043             $regForm = new CreateAccountForm();
00044          } else {
00045             $regForm =& new CreateAccountForm();
00046          }
00047          if ($regForm->isLocaleResubmit()) {
00048             $regForm->readInputData();
00049          } else {
00050             $regForm->initData();
00051          }
00052          $regForm->display();
00053 
00054       } elseif ($conference != null) {
00055 
00056          // We have the conference, but need to select a scheduled conference
00057          $schedConfDao =& DAORegistry::getDAO('SchedConfDAO');
00058          $schedConfs =& $schedConfDao->getEnabledSchedConfs($conference->getId());
00059 
00060          $templateMgr =& TemplateManager::getManager();
00061          $templateMgr->assign('pageHierarchy', array(
00062             array(Request::url(null, 'index', 'index'), $conference->getConferenceTitle(), true)));
00063          $templateMgr->assign('source', Request::getUserVar('source'));
00064          $templateMgr->assign_by_ref('schedConfs', $schedConfs);
00065          $templateMgr->display('user/createAccountConference.tpl');
00066 
00067       } else {
00068 
00069          // We have neither conference nor scheduled conference; start by selecting a
00070          // conference and we'll end up above after a redirect.
00071 
00072          $conferencesDao =& DAORegistry::getDAO('ConferenceDAO');
00073          $conferences =& $conferencesDao->getEnabledConferences();
00074 
00075          $templateMgr =& TemplateManager::getManager();
00076          $templateMgr->assign('source', Request::getUserVar('source'));
00077          $templateMgr->assign_by_ref('conferences', $conferences);
00078          $templateMgr->display('user/createAccountSite.tpl');
00079       }
00080    }
00081 
00085    function createAccount() {
00086       $this->validate();
00087       $this->setupTemplate(true);
00088       import('user.form.CreateAccountForm');
00089 
00090       if (checkPhpVersion('5.0.0')) { // WARNING: This form needs $this in constructor
00091          $regForm = new CreateAccountForm();
00092       } else {
00093          $regForm =& new CreateAccountForm();
00094       }
00095       $regForm->readInputData();
00096 
00097       if ($regForm->validate()) {
00098          $regForm->execute();
00099          if (Config::getVar('email', 'require_validation')) {
00100             // Send them home; they need to deal with the
00101             // registration email.
00102             Request::redirect(null, 'index');
00103          }
00104          Validation::login($regForm->getData('username'), $regForm->getData('password'), $reason);
00105          if ($reason !== null) {
00106             $templateMgr =& TemplateManager::getManager();
00107             $templateMgr->assign('pageTitle', 'user.login');
00108             $templateMgr->assign('errorMsg', $reason==''?'user.login.accountDisabled':'user.login.accountDisabledWithReason');
00109             $templateMgr->assign('errorParams', array('reason' => $reason));
00110             $templateMgr->assign('backLink', Request::url(null, null, null, 'login'));
00111             $templateMgr->assign('backLinkLabel', 'user.login');
00112             return $templateMgr->display('common/error.tpl');
00113          }
00114          if($source = Request::getUserVar('source'))
00115             Request::redirectUrl($source);
00116 
00117          else Request::redirect(null, null, 'login');
00118 
00119       } else {
00120          $regForm->display();
00121       }
00122    }
00123 
00127    function createAccountDisabled() {
00128       $this->setupTemplate(true);
00129       $templateMgr =& TemplateManager::getManager();
00130       $templateMgr->assign('pageTitle', 'navigation.account');
00131       $templateMgr->assign('errorMsg', 'user.account.createAccountDisabled');
00132       $templateMgr->assign('backLink', Request::url(null, null, null, 'login'));
00133       $templateMgr->assign('backLinkLabel', 'user.login');
00134       $templateMgr->display('common/error.tpl');
00135    }
00136 
00141    function activateUser($args) {
00142       $username = array_shift($args);
00143       $accessKeyCode = array_shift($args);
00144 
00145       $userDao =& DAORegistry::getDAO('UserDAO');
00146       $user =& $userDao->getUserByUsername($username);
00147       if (!$user) Request::redirect(null, 'login');
00148 
00149       // Checks user & token
00150       import('security.AccessKeyManager');
00151       $accessKeyManager = new AccessKeyManager();
00152       $accessKeyHash = AccessKeyManager::generateKeyHash($accessKeyCode);
00153       $accessKey =& $accessKeyManager->validateKey(
00154          'RegisterContext',
00155          $user->getId(),
00156          $accessKeyHash
00157       );
00158 
00159       if ($accessKey != null && $user->getDateValidated() === null) {
00160          // Activate user
00161          $user->setDisabled(false);
00162          $user->setDisabledReason('');
00163          $user->setDateValidated(Core::getCurrentDate());
00164          $userDao->updateObject($user);
00165 
00166          $templateMgr =& TemplateManager::getManager();
00167          $templateMgr->assign('message', 'user.login.activated');
00168          return $templateMgr->display('common/message.tpl');
00169       }
00170       Request::redirect(null, 'login');
00171    }
00172 
00177    function validate() {
00178       parent::validate(false);
00179       $conference =& Request::getConference();
00180 
00181       if ($conference != null) {
00182          $conferenceSettingsDao =& DAORegistry::getDAO('ConferenceSettingsDAO');
00183          if ($conferenceSettingsDao->getSetting($conference->getId(), 'disableUserReg')) {
00184             // Users cannot create accounts for this conference
00185             $this->createAccountDisabled();
00186             exit;
00187          }
00188       }
00189 
00190       return true;
00191    }
00192 
00193 }
00194 
00195 ?>

Generated on 25 Jul 2013 for Open Conference Systems by  doxygen 1.4.7