Welcome Guest, Not a member yet? Register   Sign In
Shield how to set up user environment after login
#1

Hello guys,
Where do you put logic you want to execute once, at login, for each user ?
I tried put it in App\Filters\????.php ,
linked to : $globals = ["before" ... of App\Config\filters.php
but it fires at every request.
There might be a better way, but which one ?
Thanks
Eric
Reply
#2

(This post was last modified: 10-13-2022, 09:19 AM by foxbille.)

(10-13-2022, 03:47 AM)foxbille Wrote: Hello guys,
Where do you put logic you want to execute once, at login, for each user ?
I tried put it in App\Filters\????.php ,
linked to : $globals = ["before" ... of App\Config\filters.php
but it fires at every request.
There might be a better way, but which one ?
Thanks
Eric

So I reply to myself.
In App\Config\Filters.php
public $filters = [
'uservars' => ['after' => 'login*']
];
And in App\Filters\Uservars.php

public function after(RequestInterface $request, ResponseInterface $response, $arguments = null)
{
if (auth()->loggedIn()) {
...
It works!
Eric
Reply
#3

Hi @foxbille , I'm not sure I understand what you mean.
But if you want an action to be performed after the user login, it is enough to use events.
Here is a list of available Shield events:

https://github.com/datamweb/shield/blob/...s.md#login
Reply
#4

(10-13-2022, 12:06 PM)datamweb Wrote: Hi @foxbille , I'm not sure I understand what you mean.
But if you want an action to be performed after the user login, it is enough to use events.
Here is a list of available Shield events:

https://github.com/datamweb/shield/blob/...s.md#login
This works for me to add additional session data. How about for the register event to add a DB entry for the user that was just created. Basic info like first and last name. How could I get the userid?
Reply




Theme © iAndrew 2016 - Forum software by © MyBB