diff --git a/account.php b/account.php index 6dfae1a..aa23a3d 100644 --- a/account.php +++ b/account.php @@ -209,8 +209,11 @@ function cmd_do_login() if($iResult == SUCCESS) { + $sReturnUrl = $aClean['sReturnTo']; + if(!$sReturnUrl) + $sReturnUrl = apidb_fullurl("index.php"); addmsg("You are successfully logged in as '$oUser->sRealname'.", "green"); - util_redirect_and_exit(apidb_fullurl("index.php")); + util_redirect_and_exit($sReturnUrl); } else { retry("login","Login failed ".$shNote); diff --git a/include/form_login.php b/include/form_login.php index 5f3cfee..169ec2f 100644 --- a/include/form_login.php +++ b/include/form_login.php @@ -6,7 +6,10 @@ require_once(BASE."include/util.php"); /**************/ echo "
\n"; echo '
',"\n"; -echo html_frame_start("Login to Application DB","400","",0) +echo html_frame_start("Login to Application DB","400","",0); +/* Pass on the URL we should return to after log-in */ +global $aClean; +echo ''; ?> diff --git a/include/sidebar_login.php b/include/sidebar_login.php index 6cd2be2..1521646 100644 --- a/include/sidebar_login.php +++ b/include/sidebar_login.php @@ -88,7 +88,7 @@ function global_sidebar_login() { } else { - $g->add("Log in", BASE."account.php?sCmd=login"); + $g->add("Log in", login_url()); $g->add("Register", BASE."account.php?sCmd=new"); } diff --git a/include/util.php b/include/util.php index d3ad00f..a81e581 100644 --- a/include/util.php +++ b/include/util.php @@ -903,4 +903,20 @@ function util_trim_description($sDescription) return trim(strip_tags($aDesc[0])); } +/* This allows us to pass on the current URL to the login form so that the user is returned + to the current page once he has logged in */ +function login_url() +{ + $sCurrentUrl = $_SERVER['REQUEST_URI']; + $sLoginUrl = BASE."account.php?sCmd=login"; + + /* If we are on the login page that means the URL already contains an sReturnTo value, + and we don't want two. Besides, there is little point in redirecting to the login page + after login. */ + if(!strpos($sCurrentUrl, "sReturnTo") && !strpos($sCurrentUrl, "account.php")) + $sLoginUrl .= "&sReturnTo=".$sCurrentUrl; + + return $sLoginUrl; +} + ?> diff --git a/index.php b/index.php index a003f56..2f0f015 100644 --- a/index.php +++ b/index.php @@ -39,7 +39,7 @@ if(!$_SESSION['current']->isLoggedIn()) $str_benefits -

So what are you waiting for, [log in] +

So what are you waiting for, [log in] or [register] now! Your help in stomping out Wine issues will be greatly appreciated.

"; } else