From 6d28cf5925bdb86d4b26e1ce866d3f1d01aa3948 Mon Sep 17 00:00:00 2001
From: Lapinkiller <lapinkiller@hotmail.fr>
Date: Fri, 10 Jun 2011 13:23:41 +0200
Subject: [PATCH] login_page.php return parameter is ignored, when already logged in mantis#13065 ; mantis#13060

---
 login_page.php |   16 ++++++++++++----
 1 files changed, 12 insertions(+), 4 deletions(-)

diff --git a/login_page.php b/login_page.php
index cb7db04..0efa988 100644
--- a/login_page.php
+++ b/login_page.php
@@ -28,10 +28,6 @@
 	  */
 	require_once( 'core.php' );
 
-	if ( auth_is_user_authenticated() && !current_user_is_anonymous() ) {
-		print_header_redirect( config_get( 'default_home_page' ) );
-	}
-
 	$f_error		= gpc_get_bool( 'error' );
 	$f_cookie_error	= gpc_get_bool( 'cookie_error' );
 	$f_return		= string_sanitize_url( gpc_get_string( 'return', '' ) );
@@ -42,6 +38,18 @@
 
 	$t_session_validation = ( ON == config_get_global( 'session_validation' ) );
 
+	//If user is already authenticated and if it isn't anonymous
+	if ( auth_is_user_authenticated() && !current_user_is_anonymous() ) {
+		
+		if($f_return !== ''){//If return URL is specified
+			print_header_redirect( $f_return );
+		}else{
+			print_header_redirect( config_get( 'default_home_page' ) );
+		}
+	}
+	
+	
+	
 	# Check for automatic logon methods where we want the logon to just be handled by login.php
 	if ( auth_automatic_logon_bypass_form() ) {
 		$t_uri = "login.php";
-- 
1.7.4.msysgit.0

