Skip to content

Keep sessions and clear Redis #109

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jun 7, 2018
Merged
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
13 changes: 10 additions & 3 deletions Bootstraps/Laravel.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,15 @@ public function getApplication()
$auth->extend('session', function($app, $name, $config) {
$provider = $app['auth']->createUserProvider($config['provider']);
$guard = new \PHPPM\Laravel\SessionGuard($name, $provider, $app['session.store'], null, $app);
$guard->setCookieJar($app['cookie']);
$guard->setDispatcher($app['events']);
$guard->setRequest($app->refresh('request', $guard, 'setRequest'));
if (method_exists($guard, 'setCookieJar')) {
$guard->setCookieJar($this->app['cookie']);
}
if (method_exists($guard, 'setDispatcher')) {
$guard->setDispatcher($this->app['events']);
}
if (method_exists($guard, 'setRequest')) {
$guard->setRequest($this->app->refresh('request', $guard, 'setRequest'));
}

return $guard;
});
Expand Down Expand Up @@ -118,6 +124,7 @@ public function postHandle($app)
//note that lumen does not have the getProvider method
if (method_exists($this->app, 'getProvider')) {
//reset debugbar if available
$this->resetProvider('\Illuminate\Redis\RedisServiceProvider');
$this->resetProvider('\Illuminate\Cookie\CookieServiceProvider');
$this->resetProvider('\Illuminate\Session\SessionServiceProvider');
}
Expand Down
21 changes: 21 additions & 0 deletions Laravel/SessionGuard.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,27 @@ public function setRequest(Request $request)

return parent::setRequest($request);
}

/**
* Get a unique identifier for the auth session value.
*
* @return string
*/
public function getName()
{
return 'login_'.$this->name.'_'.sha1(parent::class);
}

/**
* Get the name of the cookie used to store the "recaller".
*
* @return string
*/
public function getRecallerName()
{
return 'remember_'.$this->name.'_'.sha1(parent::class);
}

/**
* Reset the state of current class instance.
*
Expand All @@ -69,5 +89,6 @@ protected function reset()
$this->viaRemember = false;
$this->loggedOut = false;
$this->tokenRetrievalAttempted = false;
$this->recallAttempted = false;
}
}