Ok. First of all I don’t intend to alter the core, I just tried to solve my problem
I have tried to use the Login snippet but somehow it didn’t worked as I expected so I decided to write my own snippet to handle logins.
So:
- I am using MODx Revolution 2.0.4-pl2.
- I am writing a plugin that listen for OnWebLogin.
The problem:
- Inside the plugin, the reference $modx->event->user is not of expected type modUser but of type modUser_mysql and I thought that might be because of the way I am loging in my users.
My login snippet code:
<?php
//get current url
$url = $modx->makeUrl($modx->resource->get('id'));
//check if logout is requested
if($modx->user->isAuthenticated('web') && isset($_REQUEST['logout']))
{
$modx->executeProcessor(array(
'action' => 'logout',
'location' => 'security'
));
$modx->sendRedirect($url);
return;
}
//check if login is requested
if (!$modx->user->isAuthenticated('web') && isset($_REQUEST['login']) ) {
$response = $modx->executeProcessor(array(
'action' => 'login',
'location' => 'security'
,
'username' => $_REQUEST['username'],
'password' => $_REQUEST['password'],
'login_context' => 'web'
));
if( $response['success'] ) $modx->sendRedirect($url);
return;
}
?>
Another problem is that inside the plugin, OnWebLogin, even after the user entered the correct details and it is logged in, the $modx->user is (anonymous) and will be set to the correct reference just after browser redirects to the other url (so after session ends and restarts).
I hope I was clearer this time. Thank you.