示例#1
0
 /**
  * Метод выполняет логаут пользователя
  */
 public static function logout()
 {
     if (self::isAuthorized()) {
         //Оповещаем слушатель о разлогинивании пользователя.
         //ApplicationListener::beforeLogout(PsUser::inst());
         //Сбросим код пользователя в сессии
         SessionArrayHelper::reset(SESSION_USER_PARAM);
     }
 }
 public function __construct()
 {
     $this->loggedIn = SessionArrayHelper::hasInt(SESSION_USER_PARAM);
     $this->userId = $this->loggedIn ? SessionArrayHelper::getInt(SESSION_USER_PARAM) : null;
     $this->loggedInAsAdmin = $this->loggedIn ? UserBean::inst()->isAdmin($this->userId) : false;
 }
示例#3
0
 protected function doAudit($action, $userId = null, $data = null, $saveToSession = false, $parentAction = null, $auditIfNoParent = true, $clearParent = true)
 {
     try {
         $action = $this->validateAction($action);
         $parentAction = $this->validateAction($parentAction, true);
         $actionSessionKey = $this->sessionCode($action);
         $parentActionSessionKey = $parentAction ? $this->sessionCode($parentAction) : null;
         $parentId = $parentActionSessionKey ? SessionArrayHelper::getInt($parentActionSessionKey) : null;
         $hasParentIdInSession = is_integer($parentId);
         $userId = AuthManager::validateUserIdOrNull($userId);
         $userIdAuthed = AuthManager::getUserIdOrNull();
         if ($this->LOGGER->isEnabled()) {
             $this->LOGGER->info();
             $this->LOGGER->info("<Запись #{}>", ++$this->NUM);
             $this->LOGGER->info('Действие: {}', $this->decodeAction($action));
             $this->LOGGER->info('Пользователь: {}', is_inumeric($userId) ? $userId : 'НЕТ');
             $this->LOGGER->info('Авторизованный пользователь: {}', is_inumeric($userIdAuthed) ? $userIdAuthed : 'НЕТ');
             $this->LOGGER->info('Данные: {}', $data === null ? 'НЕТ' : print_r($data, true));
             $this->LOGGER->info('Сохранять в сессию: {}', $saveToSession ? 'ДА' : 'НЕТ');
             $this->LOGGER->info('Родительское действие: {}', $this->decodeAction($parentAction));
             if ($parentAction) {
                 $this->LOGGER->info('Родительское действие есть в сессии: {}', $hasParentIdInSession ? "ДА ({$parentActionSessionKey}={$parentId})" : 'НЕТ');
                 if ($hasParentIdInSession) {
                     $this->LOGGER->info('Очищать родительское действие в сессии: {}', $clearParent ? 'ДА' : 'НЕТ');
                 } else {
                     $this->LOGGER->info('Производить аудит при отсутствии родит. действия: {}', $auditIfNoParent ? 'ДА' : 'НЕТ');
                 }
             }
         }
         if (!$hasParentIdInSession && !$auditIfNoParent) {
             $this->LOGGER->info('АУДИТ НЕ ПРОИЗВЕДЁН!');
             return;
             //--- Нужен предок, но его нет
         }
         $encoded = 0;
         if (is_array($data)) {
             if (count($data) == 0) {
                 $data = null;
             } else {
                 $data = self::encodeData($data);
                 $encoded = 1;
             }
         }
         check_condition($data === null || is_string($data) || is_numeric($data), 'Illegal audit data type: ' . gettype($data) . ' for ' . $this);
         $recId = UtilsBean::inst()->saveAudit($parentId, $userId, $userIdAuthed, $this->PROCESS_CODE, $action, $data, $encoded);
         if ($this->LOGGER->isEnabled()) {
             if ($data !== null) {
                 $this->LOGGER->info('Данные кодированы: {}', $encoded ? "ДА ({$data})" : 'НЕТ');
             }
             $this->LOGGER->info('Информация сохранена в базу, id={}', $recId);
         }
         if ($saveToSession) {
             SessionArrayHelper::setInt($actionSessionKey, $recId);
             $this->LOGGER->info("Данные о действии сохранены в сессию ({$actionSessionKey}={$recId})");
         }
         if ($hasParentIdInSession && $clearParent) {
             SessionArrayHelper::reset($parentActionSessionKey);
             $this->LOGGER->info('Данные о родительском действии удалены из сессии');
         }
         $this->LOGGER->info('АУДИТ ПРОИЗВЕДЁН.');
     } catch (Exception $ex) {
         //Не удалось записть аудит, но работа должна быть продолжена!
         ExceptionHandler::dumpError($ex);
     }
 }