Index: branches/RC/core/units/users/users_config.php
===================================================================
diff -u -N -r10080 -r10433
--- branches/RC/core/units/users/users_config.php (.../users_config.php) (revision 10080)
+++ branches/RC/core/units/users/users_config.php (.../users_config.php) (revision 10433)
@@ -45,6 +45,17 @@
'DoSpecial' => '*',
'DoEvent' => 'OnDefineCustomFields',
),
+
+ Array (
+ 'Mode' => hAFTER,
+ 'Conditional' => false,
+ 'HookToPrefix' => 'adm',
+ 'HookToSpecial' => '*',
+ 'HookToEvent' => Array('OnStartup'),
+ 'DoPrefix' => '',
+ 'DoSpecial' => '*',
+ 'DoEvent' => 'OnAutoLoginUser',
+ ),
),
'QueryString' => Array(
Index: branches/RC/core/units/users/users_event_handler.php
===================================================================
diff -u -N -r10294 -r10433
--- branches/RC/core/units/users/users_event_handler.php (.../users_event_handler.php) (revision 10294)
+++ branches/RC/core/units/users/users_event_handler.php (.../users_event_handler.php) (revision 10433)
@@ -157,6 +157,9 @@
/**
* Checks user data and logs it in if allowed
*
+ * OnLogin is called from u:autoLoginUser and password is supplied
+ * OnLogin is called from u:checkLoginCookie supplying cookie with encoded username & password
+ *
* @param kEvent $event
*/
function OnLogin(&$event)
@@ -167,16 +170,16 @@
$password = $this->Application->GetVar('password');
$invalid_pseudo = $this->Application->IsAdmin() ? 'la_invalid_password' : 'lu_invalid_password';
+ $remember_login_cookie = $this->Application->GetVar('remember_login');
- if(!$password)
- {
+ if (!$password && !$remember_login_cookie) {
$object->SetError('ValidateLogin', 'invalid_password', $invalid_pseudo);
$event->status = erFAIL;
return false;
}
$email_as_login = $this->Application->ConfigValue('Email_As_Login');
- list($login_field, $submit_field) = $email_as_login && !$this->Application->IsAdmin() ? Array('Email', 'email') : Array('Login', 'login');
+ list ($login_field, $submit_field) = $email_as_login && !$this->Application->IsAdmin() ? Array('Email', 'email') : Array('Login', 'login');
$login_value = $this->Application->GetVar($submit_field);
// process "Save Username" checkbox
@@ -215,7 +218,6 @@
$this->Application->StoreVar('super_admin', 1);
}
- $this->Application->HandleEvent($dummy, 'session-log:OnStartSession');
$this->processLoginRedirect($event, $password);
return true;
}
@@ -229,9 +231,20 @@
/*$sql = 'SELECT PortalUserId FROM '.$object->TableName.' WHERE (%s = %s) AND (Password = MD5(%s))';
$user_id = $this->Conn->GetOne( sprintf($sql, $login_field, $this->Conn->qstr($login_value), $this->Conn->qstr($password) ) );*/
- $sql = 'SELECT PortalUserId FROM '.$object->TableName.' WHERE (Email = %1$s OR Login = %1$s) AND (Password = MD5(%2$s))';
- $user_id = $this->Conn->GetOne( sprintf($sql, $this->Conn->qstr($login_value), $this->Conn->qstr($password) ) );
+ if ($remember_login_cookie) {
+ $user_info = explode('|', $remember_login_cookie); // 0 - username, 1 - md5(password)
+ $sql = 'SELECT PortalUserId
+ FROM '.$object->TableName.'
+ WHERE (Email = %1$s OR Login = %1$s) AND (Password = %2$s)';
+ $user_id = $this->Conn->GetOne( sprintf($sql, $this->Conn->qstr($user_info[0]), $this->Conn->qstr($user_info[1]) ) );
+ } else {
+ $sql = 'SELECT PortalUserId
+ FROM '.$object->TableName.'
+ WHERE (Email = %1$s OR Login = %1$s) AND (Password = MD5(%2$s))';
+ $user_id = $this->Conn->GetOne( sprintf($sql, $this->Conn->qstr($login_value), $this->Conn->qstr($password) ) );
+ }
+
if ($user_id) {
$object->Load($user_id);
if ($object->GetDBField('Status') == STATUS_ACTIVE) {
@@ -249,19 +262,28 @@
$this->Application->LoadPersistentVars();
- $this_login = (int)$this->Application->RecallPersistentVar('ThisLogin');
- $this->Application->StorePersistentVar('LastLogin', $this_login);
- $this->Application->StorePersistentVar('ThisLogin', adodb_mktime());
+ if (!$remember_login_cookie) {
+ // don't change last login time when auto-login is used
+ $this_login = (int)$this->Application->RecallPersistentVar('ThisLogin');
+ $this->Application->StorePersistentVar('LastLogin', $this_login);
+ $this->Application->StorePersistentVar('ThisLogin', adodb_mktime());
+ }
- $this->Application->HandleEvent($dummy, 'session-log:OnStartSession');
+ if ($this->Application->GetVar('cb_remember_login') == 1) {
+ // remember username & password when "Remember Login" checkbox us checked (when user is using login form on Front-End)
+ $remember_login_cookie = $login_value . '|' . md5($password);
+ $this->Application->Session->SetCookie('remember_login', $remember_login_cookie, adodb_mktime() + 2592000);
+ }
}
else {
$object->Load(-2);
$object->SetError('ValidateLogin', 'no_permission', 'lu_no_permissions');
$event->status = erFAIL;
}
- $this->processLoginRedirect($event, $password);
+ if (!$remember_login_cookie) {
+ $this->processLoginRedirect($event, $password);
+ }
}
else {
$event->redirect = $this->Application->GetVar('pending_disabled_template');
@@ -279,6 +301,22 @@
}
/**
+ * [HOOK] Auto-Logins Front-End user when "Remember Login" cookie is found
+ *
+ * @param kEvent $event
+ */
+ function OnAutoLoginUser(&$event)
+ {
+ $remember_login_cookie = $this->Application->GetVar('remember_login');
+
+ if (!$remember_login_cookie || $this->Application->IsAdmin() || $this->Application->LoggedIn()) {
+ return ;
+ }
+
+ $event->CallSubEvent('OnLogin');
+ }
+
+ /**
* Checks that user is allowed to use super admin mode
*
* @return bool
@@ -384,8 +422,6 @@
$sync_manager =& $this->Application->recallObjectP('UsersSyncronizeManager', null, Array(), 'InPortalSyncronize');
$sync_manager->performAction('LogoutUser');
- $this->Application->HandleEvent($dummy, 'session-log:OnEndSession');
-
$session =& $this->Application->recallObject('Session');
$session->SetField('PortalUserId', -2);
$this->Application->SetVar('u.current_id', -2);
@@ -404,6 +440,7 @@
}
$this->Application->resetCounters('UserSession');
+ $this->Application->Session->SetCookie('login', '', adodb_mktime() - 3600);
$event->SetRedirectParam('pass', 'all');
}
Index: branches/RC/themes/default2007/platform/elements/side_boxes/login.tpl
===================================================================
diff -u -N -r10274 -r10433
--- branches/RC/themes/default2007/platform/elements/side_boxes/login.tpl (.../login.tpl) (revision 10274)
+++ branches/RC/themes/default2007/platform/elements/side_boxes/login.tpl (.../login.tpl) (revision 10433)
@@ -103,7 +103,7 @@
" />