Requests
Add Portal to params of Users.login Event
Currently only the user_id is passed as a parameter to the Users.login event handler. In most cases, this event would be used for tracking when clients/contacts log in, although some might also want to know when admins log in.
Would be nice if the params passed to this event handler also included the portal with which the user logged into:
$params['user_id'] = id_of_user_tht_just_logged_in
$params['portal'] = the_portal_logged_into ('admin' or 'client')
I do not believe the portal value would need to be the values in Configure::get('Route.admin') or Configure::get('Route.client') as the portal parameter would just tell the even handler where the login occurred.
As it is now, we have to query DB tables to determine if it was an admin login, or standard user login.
/**
* Handler for the Users.login event.
*
* This method is triggered when a user attempts to log in.
*
* @param EventInterface $event The event to process.
*/
public function loginHandler(EventInterface $event)
{
// Get the event parameters (such as user ID) and return value
$params = $event->getParams();
$return = $event->getReturnValue();
// Check if the user is a staff member by looking up their user ID
// If the user is found in the staff table, $staffLogin will be true, otherwise false
$staffLogin = $this->Staff->getByUserId($params['user_id']) ? true : false;
// Handle the staff login response based on the portal
if ($params['portal'] === 'admin') {
// Handle admin login
} else {
// Handle client login
}
}
I think this approach would be better than querying your database tables, as it provides a more direct and efficient way to handle different types of logins. Hope it helps!
Appologies should be:
if ($staffLogin) {
// Handle admin login
} else {
// Handle client login
}
Comments have been locked on this page!