diff --git a/src/Data/Repositories/Session.php b/src/Data/Repositories/Session.php index c4f05db2..91883d2f 100644 --- a/src/Data/Repositories/Session.php +++ b/src/Data/Repositories/Session.php @@ -4,7 +4,6 @@ use Carbon\Carbon; use PragmaRX\Support\Config; -use PragmaRX\Support\PhpSession; use Ramsey\Uuid\Uuid as UUID; class Session extends Repository @@ -17,11 +16,11 @@ class Session extends Repository protected $relations = ['device', 'user', 'log', 'language', 'agent', 'referer', 'geoIp', 'cookie']; - public function __construct($model, Config $config, PhpSession $session) + public function __construct($model, Config $config) { $this->config = $config; - $this->session = $session; + $this->session = session(); parent::__construct($model); } @@ -70,6 +69,10 @@ private function sessionIsReliable() { $data = $this->getSessionData(); + if(!isset($data['is_active']) || $data['is_active'] === false){ + return false; + } + if (isset($data['user_id']) && isset($data['user_type'])) { if ($data['user_id'] !== $this->sessionInfo['user_id'] && $data['user_type'] !== $this->sessionInfo['user_type']) { return false; @@ -137,7 +140,7 @@ private function ensureSessionDataIsComplete() if (in_array($key, ['user_agent', 'impersonation_id'])) { continue; } - if ($sessionData[$key] !== $value) { + if (!isset($sessionData[$key]) || $sessionData[$key] !== $value) { if (!isset($model)) { $model = $this->find($this->sessionInfo['id']); } @@ -172,6 +175,12 @@ private function storeSession() $this->putSessionData($this->sessionInfo); } + public function updateSessionOnCacheByUuid($uuid, $data){ + list($model, $cacheKey) = $this->cache->findCached($uuid, 'uuid', app()->make('tracker.config')->get('session_model')); + + $this->cache->cachePut($cacheKey, $data); + } + private function getSystemSessionId() { $sessionData = $this->getSessionData(); @@ -280,9 +289,8 @@ public function users($minutes, $results) return $this->getModel()->users($minutes, $results); } - public function getCurrent() - { - return $this->getModel(); + public function getCurrent(){ + return $this->newQuery()->find($this->getModel()['id']); } public function updateSessionData($data) diff --git a/src/Services/Authentication.php b/src/Services/Authentication.php index f62514d2..e509668f 100644 --- a/src/Services/Authentication.php +++ b/src/Services/Authentication.php @@ -33,16 +33,21 @@ private function executeAuthMethod($method) $guards[] = null; } - foreach ($this->getAuthentication() as $auth) { + foreach ($this->getAuthentication() as $authIoc) { foreach ($guards as $guard) { // Call guard() if not null if ($guard && $guard != 'null') { - $auth = $auth->guard($guard); + $auth = $authIoc->guard($guard); } - } - if (is_callable([$auth, $method], true, $callable_name)) { - if ($data = $auth->$method()) { - return $data; + + if (!isset($auth)) { + $auth = $authIoc->guard(); + } + + if (is_callable([$auth, $method], true, $callable_name)) { + if ($data = $auth->$method()) { + return $data; + } } } } diff --git a/src/Tracker.php b/src/Tracker.php index 8f36b96d..b478944b 100644 --- a/src/Tracker.php +++ b/src/Tracker.php @@ -250,11 +250,12 @@ protected function makeSessionData() 'language_id' => $this->getLanguageId(), 'is_robot' => $this->isRobot(), 'impersonation_id' => null, - + // The key user_agent is not present in the sessions table, but // it's internally used to check if the user agent changed // during a session. 'user_agent' => $this->dataRepositoryManager->getCurrentUserAgent(), + 'is_active' => true, ]; $authSessionPrefix = $this->config->get('auth_session_prefix'); @@ -443,8 +444,7 @@ public function pageViewsByCountry($minutes, $results = true) public function allowConsole() { - return - (!$this->laravel->runningInConsole()) || + return (!$this->laravel->runningInConsole()) || $this->config->get('console_log_enabled', false); } @@ -581,4 +581,18 @@ public function updateGeoIp() return $success; } + + /** + * @return Session + */ + public function updateSessionStatus($session, bool $status) + { + $session = $this->dataRepositoryManager->sessionRepository->find($session['_id']); + $session->setAttribute('is_active', $status); + $session->save(); + + $this->dataRepositoryManager->sessionRepository->updateSessionOnCacheByUuid($session['uuid'], $session); + + return $session; + } } diff --git a/src/Vendor/Laravel/ServiceProvider.php b/src/Vendor/Laravel/ServiceProvider.php index b9d62bf5..c9689b6d 100644 --- a/src/Vendor/Laravel/ServiceProvider.php +++ b/src/Vendor/Laravel/ServiceProvider.php @@ -280,8 +280,7 @@ public function registerRepositories() $app['tracker.config'], new Session( $sessionModel, - $app['tracker.config'], - new PhpSession() + $app['tracker.config'] ), $logRepository, new Path($pathModel),