ChangeSet ID: 31207 CVSROOT: /opt/cvs-commit Module name: appdb Changes by: wineowner@winehq.org 2007/06/15 18:40:21
Modified files: . : account.php index.php include : form_login.php sidebar_login.php util.php
Log message: Alexander Nicolaysen Sørnes alex@thehandofagony.com Preserve current url when logging in. Pass the current url as part of the url to the login form so we can return the user to the starting url after login.
Patch: http://cvs.winehq.org/patch.py?id=31207
Old revision New revision Changes Path 1.35 1.36 +4 -1 appdb/account.php 1.48 1.49 +1 -1 appdb/index.php 1.10 1.11 +4 -1 appdb/include/form_login.php 1.28 1.29 +1 -1 appdb/include/sidebar_login.php 1.92 1.93 +16 -0 appdb/include/util.php
Index: appdb/account.php diff -u -p appdb/account.php:1.35 appdb/account.php:1.36 --- appdb/account.php:1.35 15 Jun 2007 23:40:21 -0000 +++ appdb/account.php 15 Jun 2007 23:40:21 -0000 @@ -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); Index: appdb/index.php diff -u -p appdb/index.php:1.48 appdb/index.php:1.49 --- appdb/index.php:1.48 15 Jun 2007 23:40:21 -0000 +++ appdb/index.php 15 Jun 2007 23:40:21 -0000 @@ -39,7 +39,7 @@ if(!$_SESSION['current']->isLoggedIn())
$str_benefits
- <p>So what are you waiting for, [<a href="account.php?sCmd=login">log in</a>] + <p>So what are you waiting for, [<a href="".login_url()."">log in</a>] or [<a href="account.php?sCmd=new">register</a>] now! Your help in stomping out Wine issues will be greatly appreciated.</p>"; } else Index: appdb/include/form_login.php diff -u -p appdb/include/form_login.php:1.10 appdb/include/form_login.php:1.11 --- appdb/include/form_login.php:1.10 15 Jun 2007 23:40:21 -0000 +++ appdb/include/form_login.php 15 Jun 2007 23:40:21 -0000 @@ -6,7 +6,10 @@ require_once(BASE."include/util.php"); /**************/ echo "<div class='default_container'>\n"; echo '<form method="post" name="sFlogin" action="account.php">',"\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 '<input type="hidden" name="sReturnTo" value="'.$aClean['sReturnTo'].'" />'; ?>
<!-- start of login form --> Index: appdb/include/sidebar_login.php diff -u -p appdb/include/sidebar_login.php:1.28 appdb/include/sidebar_login.php:1.29 --- appdb/include/sidebar_login.php:1.28 15 Jun 2007 23:40:21 -0000 +++ appdb/include/sidebar_login.php 15 Jun 2007 23:40:21 -0000 @@ -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"); }
Index: appdb/include/util.php diff -u -p appdb/include/util.php:1.92 appdb/include/util.php:1.93 --- appdb/include/util.php:1.92 15 Jun 2007 23:40:21 -0000 +++ appdb/include/util.php 15 Jun 2007 23:40:21 -0000 @@ -903,4 +903,20 @@ function util_trim_description($sDescrip 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; +} + ?>