Open Monograph Press  1.1
 All Classes Namespaces Functions Variables Groups Pages
RegistrationHandler.inc.php
1 <?php
2 
17 import('pages.user.UserHandler');
18 
23  function RegistrationHandler() {
24  parent::UserHandler();
25  }
26 
32  function register($args, $request) {
33  $this->validate($request);
34  $this->setupTemplate($request, true);
35 
36  $context = $request->getContext();
37  $site = $request->getSite();
38 
39  if ($context != null) {
40  import('classes.user.form.RegistrationForm');
41 
42  $existingUser = $request->getUserVar('existingUser') ? 1 : 0;
43 
44  $regForm = new RegistrationForm($site, $existingUser);
45 
46  $regForm->initData();
47  $regForm->display($request);
48  } else {
49  $contextDao = Application::getContextDAO();
50  $contexts = $contextDao->getAll(true);
51 
52  $templateMgr = TemplateManager::getManager($request);
53  $templateMgr->assign('source', $request->getUserVar('source'));
54  $templateMgr->assign('contexts', $contexts);
55  $templateMgr->display('user/registerSite.tpl');
56  }
57  }
58 
64  function registerUser($args, $request) {
65  $this->validate($request);
66  $this->setupTemplate($request, true);
67  import('classes.user.form.RegistrationForm');
68 
69  $existingUser = $request->getUserVar('existingUser') ? 1 : 0;
70  $site = $request->getSite();
71 
72  $regForm = new RegistrationForm($site, $existingUser);
73  $regForm->readInputData();
74 
75  if ($regForm->validate()) {
76  $regForm->execute($request);
77  if (Config::getVar('email', 'require_validation')) {
78  // Send them home; they need to deal with the
79  // registration email.
80  $request->redirect(null, 'index');
81  }
82 
83  $reason = null;
84 
85  if (Config::getVar('security', 'implicit_auth')) {
86  Validation::login('', '', $reason);
87  } else {
88  Validation::login($regForm->getData('username'), $regForm->getData('password'), $reason);
89  }
90 
91  if ($reason !== null) {
92  $this->setupTemplate($request, true);
93  $templateMgr = TemplateManager::getManager($request);
94  $templateMgr->assign('pageTitle', 'user.login');
95  $templateMgr->assign('errorMsg', $reason==''?'user.login.accountDisabled':'user.login.accountDisabledWithReason');
96  $templateMgr->assign('errorParams', array('reason' => $reason));
97  $templateMgr->assign('backLink', $request->url(null, 'login'));
98  $templateMgr->assign('backLinkLabel', 'user.login');
99  return $templateMgr->display('common/error.tpl');
100  }
101  if($source = $request->getUserVar('source'))
102  $request->redirectUrl($source);
103 
104  else $request->redirect(null, 'login');
105 
106  } else {
107  $regForm->display($request);
108  }
109  }
110 
116  function registrationDisabled($args, $request) {
117  $this->setupTemplate($request, true);
118  $templateMgr = TemplateManager::getManager($request);
119  $templateMgr->assign('pageTitle', 'user.register');
120  $templateMgr->assign('errorMsg', 'user.register.registrationDisabled');
121  $templateMgr->assign('backLink', $request->url(null, 'login'));
122  $templateMgr->assign('backLinkLabel', 'user.login');
123  $templateMgr->display('common/error.tpl');
124  }
125 
130  function activateUser($args, $request) {
131  $username = array_shift($args);
132  $accessKeyCode = array_shift($args);
133 
134  $context = $request->getContext();
135  $userDao = DAORegistry::getDAO('UserDAO');
136  $user = $userDao->getByUsername($username);
137  if (!$user) $request->redirect(null, 'login');
138 
139  // Checks user and token
140  import('lib.pkp.classes.security.AccessKeyManager');
141  $accessKeyManager = new AccessKeyManager();
142  $accessKeyHash = AccessKeyManager::generateKeyHash($accessKeyCode);
143  $accessKey = $accessKeyManager->validateKey(
144  'RegisterContext',
145  $user->getId(),
146  $accessKeyHash
147  );
148 
149  if ($accessKey != null && $user->getDateValidated() === null) {
150  // Activate user
151  $user->setDisabled(false);
152  $user->setDisabledReason('');
153  $user->setDateValidated(Core::getCurrentDate());
154  $userDao->updateObject($user);
155 
156  $templateMgr = TemplateManager::getManager($request);
157  $templateMgr->assign('message', 'user.login.activated');
158  return $templateMgr->display('common/message.tpl');
159  }
160  $request->redirect(null, 'login');
161  }
162 
167  function validate($request) {
168  $context = $request->getContext();
169  if ($context != null) {
170  $contextSettingsDao = $context->getSettingsDAO();
171  if ($contextSettingsDao->getSetting($context->getId(), 'disableUserReg')) {
172  // Users cannot register themselves for this context
173  $this->registrationDisabled();
174  exit;
175  }
176  }
177  }
178 }
179 
180 ?>
static & getDAO($name, $dbconn=null)
static & login($username, $password, &$reason, $remember=false)
setupTemplate($request)
Handle requests for user registration.
static getVar($section, $key, $default=null)
Definition: Config.inc.php:35
Class defining operations for AccessKey management.
Handle requests for user functions.
Form for user registration.
registrationDisabled($args, $request)
static getContextDAO()
static getCurrentDate($ts=null)
Definition: Core.inc.php:95