mirror of
https://github.com/flarum/core.git
synced 2025-08-02 14:37:49 +02:00
Allow accessing the session via the actor
This is a bit sloppy (might come up with a better solution yet), but since most events provide access to the actor but not the request, this was the easiest/quickest way to allow extensions to access the session.
This commit is contained in:
@@ -30,6 +30,7 @@ use Flarum\Event\UserWasRegistered;
|
|||||||
use Flarum\Event\UserWasRenamed;
|
use Flarum\Event\UserWasRenamed;
|
||||||
use Flarum\Foundation\Application;
|
use Flarum\Foundation\Application;
|
||||||
use Illuminate\Contracts\Hashing\Hasher;
|
use Illuminate\Contracts\Hashing\Hasher;
|
||||||
|
use Symfony\Component\HttpFoundation\Session\SessionInterface;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @property int $id
|
* @property int $id
|
||||||
@@ -76,6 +77,11 @@ class User extends AbstractModel
|
|||||||
*/
|
*/
|
||||||
protected $permissions = null;
|
protected $permissions = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var SessionInterface
|
||||||
|
*/
|
||||||
|
protected $session;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An array of registered user preferences. Each preference is defined with
|
* An array of registered user preferences. Each preference is defined with
|
||||||
* a key, and its value is an array containing the following keys:.
|
* a key, and its value is an array containing the following keys:.
|
||||||
@@ -689,6 +695,22 @@ class User extends AbstractModel
|
|||||||
return ! $this->can($ability, $arguments);
|
return ! $this->can($ability, $arguments);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return SessionInterface
|
||||||
|
*/
|
||||||
|
public function getSession()
|
||||||
|
{
|
||||||
|
return $this->session;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param SessionInterface $session
|
||||||
|
*/
|
||||||
|
public function setSession(SessionInterface $session)
|
||||||
|
{
|
||||||
|
$this->session = $session;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the hasher with which to hash passwords.
|
* Set the hasher with which to hash passwords.
|
||||||
*
|
*
|
||||||
|
@@ -28,6 +28,8 @@ class AuthenticateWithSession implements MiddlewareInterface
|
|||||||
|
|
||||||
$actor = $this->getActor($session);
|
$actor = $this->getActor($session);
|
||||||
|
|
||||||
|
$actor->setSession($session);
|
||||||
|
|
||||||
$request = $request->withAttribute('actor', $actor);
|
$request = $request->withAttribute('actor', $actor);
|
||||||
|
|
||||||
return $out ? $out($request, $response) : $response;
|
return $out ? $out($request, $response) : $response;
|
||||||
|
Reference in New Issue
Block a user