Open Monograph Press  1.1
 All Classes Namespaces Functions Variables Groups Pages
LoginHandler.inc.php
1 <?php
2 
16 import('lib.pkp.pages.login.PKPLoginHandler');
17 
24  function signInAsUser($args, $request) {
25  $this->addCheck(new HandlerValidatorPress($this));
26  $this->addCheck(new HandlerValidatorRoles($this, true, null, null, array(ROLE_ID_SITE_ADMIN, ROLE_ID_MANAGER)));
27  $this->validate();
28 
29  if (isset($args[0]) && !empty($args[0])) {
30  $userId = (int)$args[0];
31  $user = $request->getUser();
32 
33  if (!Validation::canAdminister($userId, $user->getId())) {
34  $this->setupTemplate($request);
35  // We don't have administrative rights
36  // over this user. Display an error.
37  $templateMgr = TemplateManager::getManager($request);
38  $templateMgr->assign('pageTitle', 'manager.people');
39  $templateMgr->assign('errorMsg', 'manager.people.noAdministrativeRights');
40  $templateMgr->assign('backLink', $request->url(null, null, 'people', 'all'));
41  $templateMgr->assign('backLinkLabel', 'manager.people.allUsers');
42  return $templateMgr->display('common/error.tpl');
43  }
44 
45  $userDao = DAORegistry::getDAO('UserDAO');
46  $newUser = $userDao->getById($userId);
47  $session =& $request->getSession();
48 
49  // FIXME Support "stack" of signed-in-as user IDs?
50  if (isset($newUser) && $session->getUserId() != $newUser->getId()) {
51  $session->setSessionVar('signedInAs', $session->getUserId());
52  $session->setSessionVar('userId', $userId);
53  $session->setUserId($userId);
54  $session->setSessionVar('username', $newUser->getUsername());
55  $request->redirect(null, 'user');
56  }
57  }
58  $request->redirect(null, $request->getRequestedPage());
59  }
60 
66  function signOutAsUser($args, $request) {
67  $this->validate();
68 
69  $session = $request->getSession();
70  $signedInAs = $session->getSessionVar('signedInAs');
71 
72  if (isset($signedInAs) && !empty($signedInAs)) {
73  $signedInAs = (int)$signedInAs;
74 
75  $userDao = DAORegistry::getDAO('UserDAO');
76  $oldUser = $userDao->getById($signedInAs);
77 
78  $session->unsetSessionVar('signedInAs');
79 
80  if (isset($oldUser)) {
81  $session->setSessionVar('userId', $signedInAs);
82  $session->setUserId($signedInAs);
83  $session->setSessionVar('username', $oldUser->getUsername());
84  }
85  }
86 
87  $request->redirect(null, 'user');
88  }
89 
94  function _getLoginUrl($request) {
95  return $request->url(null, 'login', 'signIn');
96  }
97 
103  function _setMailFrom($request, &$mail) {
104  $site = $request->getSite();
105  $press = $request->getPress();
106 
107  // Set the sender based on the current context
108  if ($press && $press->getSetting('supportEmail')) {
109  $mail->setReplyTo($press->getSetting('supportEmail'), $press->getSetting('supportName'));
110  } else {
111  $mail->setReplyTo($site->getLocalizedContactEmail(), $site->getLocalizedContactName());
112  }
113  }
114 
119  function _redirectAfterLogin($request) {
120  $press = $this->getTargetContext($request);
121  // If there's a press, send them to the dashboard after login.
122  if ($press && $request->getUserVar('source') == '' && array_intersect(
123  array(ROLE_ID_SITE_ADMIN, ROLE_ID_MANAGER, ROLE_ID_SUB_EDITOR, ROLE_ID_AUTHOR, ROLE_ID_REVIEWER, ROLE_ID_ASSISTANT),
124  (array) $this->getAuthorizedContextObject(ASSOC_TYPE_USER_ROLES)
125  )) {
126  return $request->redirect($press->getPath(), 'dashboard');
127  }
128  // Fall back on the parent otherwise.
129  return parent::_redirectAfterLogin($request);
130  }
131 
135  function setupTemplate($request) {
136  AppLocale::requireComponents(LOCALE_COMPONENT_APP_MANAGER, LOCALE_COMPONENT_PKP_MANAGER);
137  parent::setupTemplate($request);
138  }
139 }
140 
141 ?>
static & getDAO($name, $dbconn=null)
Handle login/logout requests.
getTargetContext($request, $bestGuess=true)
Definition: Handler.inc.php:58
static requireComponents()
signInAsUser($args, $request)
static canAdminister($administeredUserId, $administratorUserId)
_getLoginUrl($request)
_setMailFrom($request, &$mail)
signOutAsUser($args, $request)
validate($requiredContexts=null, $request=null)
addCheck(&$handlerValidator)
_redirectAfterLogin($request)
Handle login/logout requests.
setupTemplate($request)
& getAuthorizedContextObject($assocType)