/** * Constructor * * @param $template \SP\Template con instancia de plantilla */ public function __construct(\SP\Template $template = null) { parent::__construct($template); $this->view->assign('tabs', array()); $this->view->assign('sk', SessionUtil::getSessionKey(true)); $this->_userId = Session::getUserId(); $this->_userPrefs = UserPreferences::getPreferences($this->_userId); }
/** * Inicializar la vista de cambio de clave de usuario */ public function getUserPass() { $this->setAction(self::ACTION_USR_USERS_EDITPASS); // Comprobar si el usuario a modificar es distinto al de la sesión if ($this->view->userId != Session::getUserId() && !$this->checkAccess()) { return; } $this->view->addTemplate('userspass'); $this->view->assign('actionId', self::ACTION_USR_USERS_EDITPASS); // Obtener de nuevo el token de seguridad por si se habñia regenerado antes $this->view->assign('sk', SessionUtil::getSessionKey()); }
/** * Inicialiar la sesión de usuario */ private static function initSession() { $sessionLifeTime = self::getSessionLifeTime(); // Timeout de sesión if (Session::getLastActivity() && time() - Session::getLastActivity() > $sessionLifeTime) { if (isset($_COOKIE[session_name()])) { setcookie(session_name(), '', time() - 42000, '/'); } self::wrLogoutInfo(); session_unset(); session_destroy(); session_start(); return; } // Regenerar el Id de sesión periódicamente para evitar fijación if (Session::getSidStartTime() === 0) { Session::setSidStartTime(time()); Session::setStartActivity(time()); } else { if (Session::getUserId() && time() - Session::getSidStartTime() > $sessionLifeTime / 2) { $sessionMPass = SessionUtil::getSessionMPass(); session_regenerate_id(true); Session::setSidStartTime(time()); // Recargar los permisos del perfil de usuario Session::setUserProfile(Profile::getProfile(Session::getUserProfileId())); // Regenerar la clave maestra SessionUtil::saveSessionMPass($sessionMPass); } } Session::setLastActivity(time()); }
/** * Obtener los datos para la mostrar la barra de sesión */ private function getSessionBar() { $this->view->addTemplate('sessionbar'); $this->view->assign('adminApp', Session::getUserIsAdminApp() ? '<span title="' . _('Admin Aplicación') . '">(A+)</span>' : ''); $this->view->assign('userId', Session::getUserId()); $this->view->assign('userLogin', strtoupper(Session::getUserLogin())); $this->view->assign('userName', Session::getUserName() ? Session::getUserName() : strtoupper($this->view->userLogin)); $this->view->assign('userGroup', Session::getUserGroupName()); $this->view->assign('showPassIcon', !Session::getUserIsLdap()); }
/** * Actualizar un token * * @throws SPException */ public function updateToken() { $this->checkTokenExist(); if ($this->_refreshToken) { $this->refreshToken(); } $query = 'UPDATE authTokens ' . 'SET authtoken_userId = :userid,' . 'authtoken_actionId = :actionid,' . 'authtoken_createdBy = :createdby,' . 'authtoken_token = :token,' . 'authtoken_startDate = UNIX_TIMESTAMP() ' . 'WHERE authtoken_id = :id LIMIT 1'; $data['id'] = $this->_tokenId; $data['userid'] = $this->_userId; $data['actionid'] = $this->_actionId; $data['createdby'] = Session::getUserId(); $data['token'] = $this->getUserToken() ? $this->_token : sha1(uniqid() . time()); try { DB::getQuery($query, __FUNCTION__, $data); } catch (SPException $e) { throw new SPException(SPException::SP_CRITICAL, _('Error interno')); } $Log = new Log(_('Actualizar Autorización')); $Log->addDescription(sprintf('%s : %s', Html::strongText(_('Usuario')), UserUtil::getUserLoginById($this->_userId))); $Log->writeLog(); Email::sendEmail($Log); }