Index: branches/5.1.x/core/units/helpers/user_helper.php =================================================================== diff -u -N -r13581 -r13869 --- branches/5.1.x/core/units/helpers/user_helper.php (.../user_helper.php) (revision 13581) +++ branches/5.1.x/core/units/helpers/user_helper.php (.../user_helper.php) (revision 13869) @@ -1,6 +1,6 @@ Load($user_id); $object->SetDBField('Login', 'root'); - $this->Application->StoreVar('user_id', $user_id); - $this->Application->SetVar('u.current_id', $user_id); - $this->Application->Session->SetField('PortalUserId', $user_id); - $this->Application->LoadPersistentVars(); + $this->loginUserById($user_id, $remember_login_cookie); if ($super_admin) { $this->Application->StoreVar('super_admin', 1); } - $this->Application->HandleEvent($dummy, 'session-log:OnStartSession'); + // reset counters + $this->Application->resetCounters('UserSession'); + $this->_processLoginRedirect('root', $password); $this->_processInterfaceLanguage(); } @@ -97,43 +96,23 @@ } if ($object->GetDBField('Status') == STATUS_ACTIVE) { - $groups = $object->getMembershipGroups(true); - if (!$groups) { - $groups = Array(); - } - - // store groups, because kApplication::CheckPermission will use them! - array_push($groups, $this->Application->ConfigValue('User_LoggedInGroup') ); - $this->Application->StoreVar( 'UserGroups', implode(',', $groups) ); - - if (!$this->Application->CheckPermission($this->Application->isAdmin ? 'ADMIN' : 'LOGIN', 1)) { + if ( !$this->checkLoginPermission() ) { return LOGIN_RESULT_NO_PERMISSION; } if (!$dry_run) { - $this->Application->StoreVar('user_id', $user_id); - $this->Application->SetVar('u.current_id', $user_id); - $this->Application->Session->SetField('PortalUserId', $user_id); - $this->Application->Session->SetField('GroupList', implode(',', $groups)); + $this->loginUserById($user_id, $remember_login_cookie); - $this->Application->LoadPersistentVars(); - - 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()); - } - if ($remeber_login) { // remember username & password when "Remember Login" checkbox us checked (when user is using login form on Front-End) $remember_login_cookie = $username . '|' . md5($password); $this->Application->Session->SetCookie('remember_login', $remember_login_cookie, strtotime('+1 month')); } - $this->Application->HandleEvent($dummy, 'session-log:OnStartSession'); - if (!$remember_login_cookie) { + // reset counters + $this->Application->resetCounters('UserSession'); + $this->_processLoginRedirect($username, $password); $this->_processInterfaceLanguage(); } @@ -164,6 +143,57 @@ } /** + * Login username by it's PortalUserId + * + * @param int $user_id + * @param bool $remember_login_cookie + */ + function loginUserById($user_id, $remember_login_cookie = false) + { + $object =& $this->getUserObject(); + + $this->Application->StoreVar('user_id', $user_id); + $this->Application->SetVar('u.current_id', $user_id); + $this->Application->Session->SetField('PortalUserId', $user_id); + + if ($user_id != USER_ROOT) { + $this->Application->Session->SetField('GroupList', $this->Application->RecallVar('UserGroups')); + } + + $this->Application->LoadPersistentVars(); + + 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'); + } + + /** + * Checks login permission + * + * @return bool + */ + function checkLoginPermission() + { + $object =& $this->getUserObject(); + + $groups = $object->getMembershipGroups(true); + if (!$groups) { + $groups = Array(); + } + + // store groups, because kApplication::CheckPermission will use them! + array_push($groups, $this->Application->ConfigValue('User_LoggedInGroup') ); + $this->Application->StoreVar( 'UserGroups', implode(',', $groups) ); + + return $this->Application->CheckPermission($this->Application->isAdmin ? 'ADMIN' : 'LOGIN', 1); + } + + /** * Performs user logout * */ @@ -247,9 +277,6 @@ // syncronize login $sync_manager =& $this->Application->recallObjectP('UsersSyncronizeManager', null, Array(), 'InPortalSyncronize'); $sync_manager->performAction('LoginUser', $username, $password); - - // reset counters - $this->Application->resetCounters('UserSession'); } /**