Skip to content

Commit

Permalink
Add feature, redirect after logout.
Browse files Browse the repository at this point in the history
  • Loading branch information
perlDreamer committed Feb 25, 2012
1 parent 476b14f commit 04c902a
Show file tree
Hide file tree
Showing 7 changed files with 73 additions and 6 deletions.
1 change: 1 addition & 0 deletions docs/changelog/8.x.x.txt
Expand Up @@ -6,4 +6,5 @@
- Added Facebook Auth and FacebookLogin macro.
- Removed the WebGUI statistics program and code.
- Prevent Env Macro from being used to access objects in the environment - Thanks to Haarg
- added: Redirect on Logout setting

11 changes: 8 additions & 3 deletions lib/WebGUI/Auth.pm
Expand Up @@ -1001,12 +1001,12 @@ sub www_createAccountSave {
return $self->showMessageOnLogin;
}
elsif ($self->session->form->get('returnUrl')) {
$self->session->response->setRedirect( $self->session->form->get('returnUrl') );
$self->session->response->redirect( $self->session->form->get('returnUrl') );
$self->session->scratch->delete("redirectAfterLogin");
}
elsif ($self->session->scratch->get("redirectAfterLogin")) {
my $url = $self->session->scratch->delete("redirectAfterLogin");
$self->session->response->setRedirect($url);
$self->session->response->redirect($url);
return undef;
}
else {
Expand Down Expand Up @@ -1283,7 +1283,12 @@ sub www_logout {

# Do not allow caching of the logout page (to ensure the page gets requested)
$self->session->response->setCacheControl( "none" );


if ( $self->session->setting->get("redirectAfterLogoutUrl") ) {
$self->session->log->warn("redirecting to: ".$self->session->setting->get("redirectAfterLogoutUrl"));
$self->session->response->setRedirect($self->session->setting->get("redirectAfterLogoutUrl"));
}

return undef;
}

Expand Down
8 changes: 8 additions & 0 deletions lib/WebGUI/Operation/Settings.pm
Expand Up @@ -495,6 +495,14 @@ sub definition {
label => $i18n->get( 'redirectAfterLoginUrl label' ),
hoverHelp => $i18n->get( 'redirectAfterLoginUrl description' ),
};
push @fields, {
tab => "user",
name => "redirectAfterLogoutUrl",
fieldType => "url",
defaultValue => $setting->get('redirectAfterLogoutUrl'),
label => $i18n->get( 'redirectAfterLogoutUrl label' ),
hoverHelp => $i18n->get( 'redirectAfterLogoutUrl description' ),
};
push @fields, {
tab => "user",
name => "showMessageOnLogin",
Expand Down
3 changes: 1 addition & 2 deletions lib/WebGUI/Session/Response.pm
Expand Up @@ -176,8 +176,7 @@ sub setRedirect {
my @params = $self->session->form->param;
return undef if ($url eq $self->session->url->page() && scalar(@params) < 1); # prevent redirecting to self
$self->session->log->info("Redirecting to $url");
$self->location($url);
$self->status($type);
$self->redirect($url, $type);
$self->session->style->setMeta({"http-equiv"=>"refresh",content=>"0; URL=".$url});
}

Expand Down
14 changes: 13 additions & 1 deletion lib/WebGUI/i18n/English/WebGUI.pm
Expand Up @@ -4214,12 +4214,24 @@ LongTruncOk=1</p>
context => q{Label for site setting},
},

'showMessageOnLogin description' => {
'redirectAfterLoginUrl description' => {
message => q{Users will be redirected to this url after logging in.},
lastUpdated => 0,
context => q{Description for site setting},
},

'redirectAfterLogoutUrl label' => {
message => q{Redirect After Logout Url},
lastUpdated => 0,
context => q{Label for site setting},
},

'redirectAfterLogoutUrl description' => {
message => q{Users will be redirected to this url after logging out.},
lastUpdated => 0,
context => q{Description for site setting},
},

'showMessageOnLogin label' => {
message => q{Show Message On Login?},
lastUpdated => 0,
Expand Down
4 changes: 4 additions & 0 deletions share/upgrades/7.10.24-8.0.0/redirectOnLogout.pl
@@ -0,0 +1,4 @@
use WebGUI::Upgrade::Script;
start_step "Adding Redirect After Logout setting";
session->setting->add('redirectAfterLogoutUrl');
done;
38 changes: 38 additions & 0 deletions t/Auth/RedirectAfterLogoutUrl.t
@@ -0,0 +1,38 @@
# vim:syntax=perl
#-------------------------------------------------------------------
# WebGUI is Copyright 2001-2009 Plain Black Corporation.
#-------------------------------------------------------------------
# Please read the legal notices (docs/legal.txt) and the license
# (docs/license.txt) that came with this distribution before using
# this software.
#------------------------------------------------------------------
# http://www.plainblack.com info@plainblack.com
#------------------------------------------------------------------

# Test Auth::LDAP to make sure it works with both ldap and ldaps
#
#

use FindBin;
use strict;
use lib "$FindBin::Bin/../lib";
use Test::More;
use WebGUI::Test; # Must use this before any other WebGUI modules
use WebGUI::Session;

#----------------------------------------------------------------------------
# Init
my $session = WebGUI::Test->session;

my $user = WebGUI::User->create($session);
WebGUI::Test->addToCleanup($user);

$session->setting->set('redirectAfterLogoutUrl');
$user->authInstance->www_logout;
is $session->response->redirect, undef, 'no redirect set on logout';

$session->setting->set('redirectAfterLogoutUrl', '/other_page');
$user->authInstance->www_logout;
is $session->response->redirect, '/other_page', 'redirect set on logout';

done_testing;

0 comments on commit 04c902a

Please sign in to comment.