<?php
namespace App\UserAccess; class UserAccess extends UserAccessAbstract { protected $idUser = null; public function __construct($idUser) { $this->idUser = $idUser; } public function hasAccessToSection($section) { $sectionsList = \Entity\User::select($this->idUser)->accessSectionsList; return $sectionsList[$section]??false; } public function hasAccessToOption($option) { $optionsList = \Entity\User::select($this->idUser)->accessOptionsList; return !empty($optionsList[$option]); } public function getAccessOptionValue($option) { $optionsList = \Entity\User::select($this->idUser)->accessOptionsList; return $optionsList[$option]??false; } public function isAuthenticated() { $CFG = \Engine\Loader_Cfg::getInstance()->getGlobal(); if ($CFG['auth']['authType']!='databaseCheck') { return null; } $userLoginEnt = \Entity\UserLoginSession::select($this->idUser); if ( (TIMESTAMP - $userLoginEnt->lastClick) > $this->getUserSessionLifetime() ) { return false; } return true; } protected function getUserSessionLifetime() { return \App\Config\PasswordSecurity::getInstance()->getUserSessionLifetimeCached(); } public function refreshDbLoginSession() { try { $userLoginSessEnt = \Entity\UserLoginSession::update($this->idUser); $userLoginSessEnt->lastClick = TIMESTAMP; $userLoginSessEnt->save(); } catch (\App\Entity\Exception $e) { \Log::getInstance()->critical( sprintf( "Could not update login sessions `lastClick` into database for user id %s. Some other error messages might have been logged.", $this->idUser ) ); } } } 