mirror of
https://github.com/flarum/framework.git
synced 2024-11-25 17:57:04 +08:00
Drop session from user class (#2790)
This was originally introduced in d87583d0ef
, but has not seen usage, since usually when the session needs to be modified, the request is available.
It causes issues with certain queue drivers, as it can't be serialized.
It's also not entirely accurate, as a user can have multiple sessions at once. Therefore, a given session is a property of the request, not of the user.
The reason this causes issues in the Queue is that when a Job has payload that consists User(s), the Queue will try to serialize that. Serializing the User object will require serializing the session too; this causes a Serialization of Closure is not allowed error, see image.
One can circumvent that in many ways, the most obvious one is adding a __sleep and __wakeup implementation in the User class (or the session handler). But as we aren't really using the session on the User model anywhere in core, bundled or most community extensions it is best to simply detach this from the user.
This commit is contained in:
parent
72c7d3f49b
commit
6ae880b214
|
@ -26,8 +26,6 @@ class AuthenticateWithSession implements Middleware
|
|||
|
||||
$actor = $this->getActor($session, $request);
|
||||
|
||||
$actor->setSession($session);
|
||||
|
||||
$request = RequestUtil::withActor($request, $actor);
|
||||
|
||||
return $handler->handle($request);
|
||||
|
|
|
@ -33,7 +33,6 @@ use Flarum\User\Event\Renamed;
|
|||
use Flarum\User\Exception\NotAuthenticatedException;
|
||||
use Flarum\User\Exception\PermissionDeniedException;
|
||||
use Illuminate\Contracts\Hashing\Hasher;
|
||||
use Illuminate\Contracts\Session\Session;
|
||||
use Illuminate\Support\Arr;
|
||||
|
||||
/**
|
||||
|
@ -76,11 +75,6 @@ class User extends AbstractModel
|
|||
*/
|
||||
protected $permissions = null;
|
||||
|
||||
/**
|
||||
* @var Session
|
||||
*/
|
||||
protected $session;
|
||||
|
||||
/**
|
||||
* An array of callables, through each of which the user's list of groups is passed
|
||||
* before being returned.
|
||||
|
@ -786,22 +780,6 @@ class User extends AbstractModel
|
|||
return ! $this->can($ability, $arguments);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Session
|
||||
*/
|
||||
public function getSession()
|
||||
{
|
||||
return $this->session;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Session $session
|
||||
*/
|
||||
public function setSession(Session $session)
|
||||
{
|
||||
$this->session = $session;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the hasher with which to hash passwords.
|
||||
*
|
||||
|
|
Loading…
Reference in New Issue
Block a user