public function sign_in_as_user($uID, $token = null) { try { $u = new User(); $tp = new TaskPermission(); if (!$tp->canSudo()) { throw new Exception(t('You do not have permission to perform this action.')); } $ui = UserInfo::getByID($uID); if (!$ui instanceof UserInfo) { throw new Exception(t('Invalid user ID.')); } $valt = Loader::helper('validation/token'); if (!$valt->validate('sudo', $token)) { throw new Exception($valt->getErrorMessage()); } User::loginByUserID($uID); $this->redirect('/'); } catch (Exception $e) { $this->set('error', $e); $this->view(); } }
<? } ?> <? if ($uo->getUserID() != USER_SUPER_ID && $tp->canActivateUser()) { ?> <? if ($uo->isActive()) { ?> <? print $ih->button(t('Deactivate User'), $this->url('/dashboard/users/search?uID=' . intval($uID) . '&task=deactivate&ccm_token='.$valt->generate('user_deactivate')), 'left');?> <? } else { ?> <? print $ih->button(t('Activate User'), $this->url('/dashboard/users/search?uID=' . intval($uID) . '&task=activate&ccm_token='.$valt->generate('user_activate')), 'left');?> <? } ?> <? } ?> <? } ?> <? $tp = new TaskPermission(); if ($uo->getUserID() != $u->getUserID()) { if ($tp->canSudo()) { $loginAsUserConfirm = t('This will end your current session and sign you in as %s', $uo->getUserName()); print $ih->button_js(t('Sign In as User'), 'loginAsUser()', 'left');?> <script type="text/javascript"> loginAsUser = function() { if (confirm('<?=$loginAsUserConfirm?>')) { location.href = "<?=$this->url('/dashboard/users/search', 'sign_in_as_user', $uo->getUserID(), $valt->generate('sudo'))?>"; } } </script> <? } /*else { ?> <? print $ih->button_js(t('Sign In as User'), 'alert(\'' . t('You do not have permission to sign in as other users.') . '\')', 'left', 'ccm-button-inactive');?>