Requests | Blesta

Requests

Add Portal to params of Users.login Event

T. Chance Vecchitto shared this idea 3 months ago
Under Consideration

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.

Comments (3)

photo
1

/**

* 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!

photo
1

Appologies should be:

if ($staffLogin) {

// Handle admin login

} else {

// Handle client login

}

photo
2

Appreciate the comment Beav. That is what we do now. Your sample code illustrates the reason for the request. We must go to the DB to determine who logged in, and we have to load the Staff model to do that. While that is not hard to do, Blesta has already done that when they validated the login to begin with. Why repeat that? When Blesta triggers the Users.login event, it would be very easy for them to pass the user type (staff or client), or the portal value within the event params.

photo