mirror of
https://github.com/flarum/framework.git
synced 2025-01-20 16:58:32 +08:00
646bd40bca
Starting with version 5.9, the global funtions will be deprecated. * https://laravel-news.com/laravel-5-8-deprecates-string-and-array-helpers * https://github.com/laravel/framework/pull/26898
56 lines
1.4 KiB
PHP
56 lines
1.4 KiB
PHP
<?php
|
|
|
|
/*
|
|
* This file is part of Flarum.
|
|
*
|
|
* (c) Toby Zerner <toby.zerner@gmail.com>
|
|
*
|
|
* For the full copyright and license information, please view the LICENSE
|
|
* file that was distributed with this source code.
|
|
*/
|
|
|
|
namespace Flarum\Http\Middleware;
|
|
|
|
use Flarum\Http\AccessToken;
|
|
use Flarum\Http\CookieFactory;
|
|
use Illuminate\Support\Arr;
|
|
use Psr\Http\Message\ResponseInterface as Response;
|
|
use Psr\Http\Message\ServerRequestInterface as Request;
|
|
use Psr\Http\Server\MiddlewareInterface as Middleware;
|
|
use Psr\Http\Server\RequestHandlerInterface as Handler;
|
|
|
|
class RememberFromCookie implements Middleware
|
|
{
|
|
/**
|
|
* @var CookieFactory
|
|
*/
|
|
protected $cookie;
|
|
|
|
/**
|
|
* @param CookieFactory $cookie
|
|
*/
|
|
public function __construct(CookieFactory $cookie)
|
|
{
|
|
$this->cookie = $cookie;
|
|
}
|
|
|
|
public function process(Request $request, Handler $handler): Response
|
|
{
|
|
$id = Arr::get($request->getCookieParams(), $this->cookie->getName('remember'));
|
|
|
|
if ($id) {
|
|
$token = AccessToken::find($id);
|
|
|
|
if ($token) {
|
|
$token->touch();
|
|
|
|
/** @var \Illuminate\Contracts\Session\Session $session */
|
|
$session = $request->getAttribute('session');
|
|
$session->put('user_id', $token->user_id);
|
|
}
|
|
}
|
|
|
|
return $handler->handle($request);
|
|
}
|
|
}
|