Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 15 additions & 7 deletions src/Data/Repositories/Session.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);
}
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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']);
}
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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)
Expand Down
17 changes: 11 additions & 6 deletions src/Services/Authentication.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}
}
Expand Down
20 changes: 17 additions & 3 deletions src/Tracker.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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;
}
}
3 changes: 1 addition & 2 deletions src/Vendor/Laravel/ServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down