Index: branches/5.2.x/core/units/helpers/user_helper.php =================================================================== diff -u -N -r15519 -r15545 --- branches/5.2.x/core/units/helpers/user_helper.php (.../user_helper.php) (revision 15519) +++ branches/5.2.x/core/units/helpers/user_helper.php (.../user_helper.php) (revision 15545) @@ -1,6 +1,6 @@ _processLoginRedirect('root', $password); $this->_processInterfaceLanguage(); + $this->_fixNextTemplate(); } return LoginResult::OK; @@ -116,6 +117,7 @@ $this->_processLoginRedirect($username, $password); $this->_processInterfaceLanguage(); + $this->_fixNextTemplate(); } } @@ -177,7 +179,9 @@ $this->Application->StorePersistentVar('ThisLogin', adodb_mktime()); } - $this->Application->HandleEvent(new kEvent('u:OnAfterLogin')); + $hook_event = new kEvent('u:OnAfterLogin'); + $hook_event->MasterEvent = $this->event; + $this->Application->HandleEvent($hook_event); } /** @@ -273,13 +277,12 @@ $this->event = new kEvent('u:OnLogout'); } - $sync_manager = $this->Application->recallObject('UsersSyncronizeManager', null, Array(), Array ('InPortalSyncronize')); - /* @var $sync_manager UsersSyncronizeManager */ + $hook_event = new kEvent('u:OnBeforeLogout'); + $hook_event->MasterEvent = $this->event; + $this->Application->HandleEvent($hook_event); - $sync_manager->performAction('LogoutUser'); + $this->_processLoginRedirect(); - $this->Application->HandleEvent(new kEvent('u:OnBeforeLogout')); - $user_id = USER_GUEST; $this->Application->SetVar('u.current_id', $user_id); @@ -306,6 +309,8 @@ // don't pass user prefix on logout, since resulting url will have broken "env" $this->event->SetRedirectParam('pass', MOD_REWRITE ? 'm' : 'all'); + + $this->_fixNextTemplate(); } /** @@ -335,26 +340,32 @@ * * @param string $username * @param string $password + * @return void */ - function _processLoginRedirect($username, $password) + protected function _processLoginRedirect($username = null, $password = null) { // set next template $next_template = $this->Application->GetVar('next_template'); - if ($next_template) { + if ( $next_template ) { $this->event->redirect = $next_template; } // process IIS redirect - if ($this->Application->ConfigValue('UseJSRedirect')) { + if ( $this->Application->ConfigValue('UseJSRedirect') ) { $this->event->SetRedirectParam('js_redirect', 1); } // synchronize login - $sync_manager = $this->Application->recallObject('UsersSyncronizeManager', null, Array(), Array ('InPortalSyncronize')); + $sync_manager = $this->Application->recallObject('UsersSyncronizeManager', null, Array (), Array ('InPortalSyncronize')); /* @var $sync_manager UsersSyncronizeManager */ - $sync_manager->performAction('LoginUser', $username, $password); + if ( isset($username) && isset($password) ) { + $sync_manager->performAction('LoginUser', $username, $password); + } + else { + $sync_manager->performAction('LogoutUser'); + } } /** @@ -402,29 +413,30 @@ // set language for Admin Console & Front-End with disabled Mod-Rewrite $this->event->SetRedirectParam('m_lang', $language_id); // data $this->Application->Session->SetField('Language', $language_id); // interface - - // set language for Front-End with enabled Mod-Rewrite - if ( MOD_REWRITE ) { - $this->_injectLanguageIntoUrl($language_id); - } } /** - * Inject language into whatever page user wants to go after login + * Injects redirect params into next template, which doesn't happen if next template starts with "external:" * - * @param int $language_id * @return void * @access protected */ - protected function _injectLanguageIntoUrl($language_id) + protected function _fixNextTemplate() { + if ( !MOD_REWRITE || !is_object($this->event) ) { + return; + } + // solve problem, when template is "true" instead of actual template name $template = is_string($this->event->redirect) ? $this->event->redirect : ''; $url = $this->Application->HREF($template, '', $this->event->getRedirectParams(), $this->event->redirectScript); $vars = $this->Application->parseRewriteUrl($url, 'pass'); + unset($vars['login'], $vars['logout']); + // merge back url params, because they were ignored if this was "external:" url $vars['pass'] = implode(',', $vars['pass']); - $vars['m_lang'] = $language_id; + $vars = array_merge($vars, $this->event->getRedirectParams()); + $template = $vars['t']; unset($vars['is_virtual'], $vars['t']);