Ticket #245 (closed enhancement: fixed)
Implement "go back" functionality from login page
| Reported by: | Brian Koontz (brian@… | Owned by: | DotMG |
|---|---|---|---|
| Priority: | normal | Milestone: | 1.1.6.6 |
| Component: | actions | Version: | |
| Severity: | normal | Keywords: | |
| Cc: |
Description (last modified by DotMG) (diff)
This was a hack originally designed to facilitate entry into a Wikka installation from an external source and require a valid login for some particular action. Basic operation: Immediately prior to a Redirect to the UserPreferences page from another Wikka page, the page needs to set a session var called "go_back" with a valid link to the referring page. After a user is successful in logging in, they are redirected back to the calling page. This would be useful for actions or handlers that are linked to from the outside world, but that require a user to be logged in.
Here is a patch that implements this:
=================================================================== RCS file: RCS/usersettings.php,v retrieving revision 1.1 diff -u -r1.1 usersettings.php --- usersettings.php 2006/06/18 06:03:03 1.1 +++ usersettings.php 2006/06/24 06:40:13 @@ -1,5 +1,7 @@ <?php /** + * $Id: usersettings.php,v 1.5 2006/06/24 06:40:07 brian Exp brian $ + * * Display a form to register, login and change user settings. * * @package Actions @@ -334,6 +336,13 @@ // is user trying to log in or register? if (isset($_POST['action']) && ($_POST['action'] == 'login')) { + // Login request was redirected from elsewhere...let's make + // sure to go back if requested by setting $referrer + $referrer = null; + if(isset($_SESSION['go_back'])) { + $referrer = $_SESSION['go_back']; + } + // if user name already exists, check password if (isset($_POST['name']) && $existingUser = $this->LoadUser($_POST['name'])) { @@ -349,7 +358,11 @@ break; default: $this->SetUser($existingUser); - $this->Redirect($this->href()); + if($referrer == null) + $this->Redirect($this->href()); + else { + $this->Redirect($referrer); + } } } else // otherwise, proceed to registration @@ -417,7 +430,11 @@ // log in $this->SetUser($this->LoadUser($name)); - $this->Redirect($this->href('', '', 'registered=true')); + if($referrer == null) + $this->Redirect($this->href('', '', 'registered=true')); + else { + $this->Redirect($referrer); + } } } } @@ -542,4 +559,4 @@ <?php print($this->FormClose()); }
Implement option 3 (see comments).
Related tickets #396