Set action after successfully first login #588
-
In my application, after the first login with AD credentials, the user is saved in the database with data imported from AD. Where can I set additional actions to be performed after registering a user with ID = 1, e.g. give him the Adminstrator role by writing user_id to the table with roles? |
Beta Was this translation helpful? Give feedback.
Answered by
stevebauman
Oct 9, 2023
Replies: 1 comment
-
Hi @sskwodgik, You could create a listener on the // App\Ldap\Listeners\AssociateRole.php
use LdapRecord\Laravel\Events\Import\Saved;
class AssociateRole
{
public function handle(Saved $event): void
{
// Determine if the LDAP user is an admin in your own way.
$userIsAdmin = $event->object->...
if ($userIsAdmin) {
$event->eloquent->roles()->syncWithoutDetaching(Role::admin());
}
}
} // App\Providers\EventServiceProvider.php
protected $listen = [
\LdapRecord\Laravel\Events\Import\Saved::class => [
\App\Ldap\Listeners\AssociateRole::class
]
]; |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
sskwodgik
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi @sskwodgik,
You could create a listener on the
Saved
import event and associate the user to that role anytime the user logs in: