• Main Page
  • Modules
  • Classes
  • Files
  • File List

pages/login/LoginHandler.inc.php

00001 <?php
00002 
00015 import('lib.pkp.pages.login.PKPLoginHandler');
00016 
00017 class LoginHandler extends PKPLoginHandler {
00023    function signInAsUser($args, &$request) {
00024       $this->addCheck(new HandlerValidatorPress($this));
00025       $this->addCheck(new HandlerValidatorRoles($this, true, null, null, array(ROLE_ID_SITE_ADMIN, ROLE_ID_PRESS_MANAGER)));
00026       $this->validate();
00027 
00028       if (isset($args[0]) && !empty($args[0])) {
00029          $userId = (int)$args[0];
00030          $user =& $request->getUser();
00031 
00032          if (!Validation::canAdminister($userId, $user->getId())) {
00033             $this->setupTemplate();
00034             // We don't have administrative rights
00035             // over this user. Display an error.
00036             $templateMgr =& TemplateManager::getManager();
00037             $templateMgr->assign('pageTitle', 'manager.people');
00038             $templateMgr->assign('errorMsg', 'manager.people.noAdministrativeRights');
00039             $templateMgr->assign('backLink', $request->url(null, null, 'people', 'all'));
00040             $templateMgr->assign('backLinkLabel', 'manager.people.allUsers');
00041             return $templateMgr->display('common/error.tpl');
00042          }
00043 
00044          $userDao =& DAORegistry::getDAO('UserDAO');
00045          $newUser =& $userDao->getById($userId);
00046          $session =& $request->getSession();
00047 
00048          // FIXME Support "stack" of signed-in-as user IDs?
00049          if (isset($newUser) && $session->getUserId() != $newUser->getId()) {
00050             $session->setSessionVar('signedInAs', $session->getUserId());
00051             $session->setSessionVar('userId', $userId);
00052             $session->setUserId($userId);
00053             $session->setSessionVar('username', $newUser->getUsername());
00054             $request->redirect(null, 'user');
00055          }
00056       }
00057       $request->redirect(null, $request->getRequestedPage());
00058    }
00059 
00065    function signOutAsUser($args, &$request) {
00066       $this->validate();
00067 
00068       $session =& $request->getSession();
00069       $signedInAs = $session->getSessionVar('signedInAs');
00070 
00071       if (isset($signedInAs) && !empty($signedInAs)) {
00072          $signedInAs = (int)$signedInAs;
00073 
00074          $userDao =& DAORegistry::getDAO('UserDAO');
00075          $oldUser =& $userDao->getById($signedInAs);
00076 
00077          $session->unsetSessionVar('signedInAs');
00078 
00079          if (isset($oldUser)) {
00080             $session->setSessionVar('userId', $signedInAs);
00081             $session->setUserId($signedInAs);
00082             $session->setSessionVar('username', $oldUser->getUsername());
00083          }
00084       }
00085 
00086       $request->redirect(null, 'user');
00087    }
00088 
00093    function _getLoginUrl($request) {
00094       return $request->url(null, 'login', 'signIn');
00095    }
00096 
00102    function _setMailFrom($request, &$mail) {
00103       $site =& $request->getSite();
00104       $press =& $request->getPress();
00105 
00106       // Set the sender based on the current context
00107       if ($press && $press->getSetting('supportEmail')) {
00108          $mail->setFrom($press->getSetting('supportEmail'), $press->getSetting('supportName'));
00109       } else {
00110          $mail->setFrom($site->getLocalizedContactEmail(), $site->getLocalizedContactName());
00111       }
00112    }
00113 
00118    function _redirectAfterLogin($request) {
00119       $press = $this->getTargetPress($request);
00120       // If there's a press, send them to the dashboard after login.
00121       if ($press && $request->getUserVar('source') == '' && array_intersect(
00122          array(ROLE_ID_SITE_ADMIN, ROLE_ID_PRESS_MANAGER, ROLE_ID_SERIES_EDITOR, ROLE_ID_AUTHOR, ROLE_ID_REVIEWER, ROLE_ID_PRESS_ASSISTANT),
00123          (array) $this->getAuthorizedContextObject(ASSOC_TYPE_USER_ROLES)
00124       )) {
00125          return $request->redirect($press->getPath(), 'dashboard');
00126       }
00127       // Fall back on the parent otherwise.
00128       return parent::_redirectAfterLogin($request);
00129    }
00130 
00134    function setupTemplate() {
00135       AppLocale::requireComponents(LOCALE_COMPONENT_OMP_MANAGER, LOCALE_COMPONENT_PKP_MANAGER);
00136       parent::setupTemplate();
00137    }
00138 }
00139 
00140 ?>

Generated on Mon Sep 17 2012 13:58:56 for Open Monograph Press by  doxygen 1.7.1