mirror of
https://github.com/flarum/core.git
synced 2025-10-18 18:26:07 +02:00
Use Illuminate Session component instead of Symfony
Symfony's component relies on PHP's native session functionality, which is not ideal. It automatically sets its own cookie headers, resulting in this issue: https://github.com/flarum/core/issues/1084#issuecomment-364569953 The Illuminate component is more powerful and has a simpler API for extension with other drivers and such, and fits in nicely with other components we use (the majority of which are from Illuminate).
This commit is contained in:
committed by
Franz Liedke
parent
b4e093ab8a
commit
5672819549
@@ -12,15 +12,29 @@
|
||||
namespace Flarum\Http\Middleware;
|
||||
|
||||
use Flarum\Http\AccessToken;
|
||||
use Flarum\Http\CookieFactory;
|
||||
use Interop\Http\ServerMiddleware\DelegateInterface;
|
||||
use Interop\Http\ServerMiddleware\MiddlewareInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface as Request;
|
||||
|
||||
class RememberFromCookie implements MiddlewareInterface
|
||||
{
|
||||
/**
|
||||
* @var CookieFactory
|
||||
*/
|
||||
protected $cookie;
|
||||
|
||||
/**
|
||||
* @param CookieFactory $cookie
|
||||
*/
|
||||
public function __construct(CookieFactory $cookie)
|
||||
{
|
||||
$this->cookie = $cookie;
|
||||
}
|
||||
|
||||
public function process(Request $request, DelegateInterface $delegate)
|
||||
{
|
||||
$id = array_get($request->getCookieParams(), 'flarum_remember');
|
||||
$id = array_get($request->getCookieParams(), $this->cookie->getName('remember'));
|
||||
|
||||
if ($id) {
|
||||
$token = AccessToken::find($id);
|
||||
@@ -28,8 +42,9 @@ class RememberFromCookie implements MiddlewareInterface
|
||||
if ($token) {
|
||||
$token->touch();
|
||||
|
||||
/** @var \Illuminate\Contracts\Session\Session $session */
|
||||
$session = $request->getAttribute('session');
|
||||
$session->set('user_id', $token->user_id);
|
||||
$session->put('user_id', $token->user_id);
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user