Skip to content

Commit 04c902a

Browse files
committedFeb 25, 2012
Add feature, redirect after logout.
1 parent 476b14f commit 04c902a

File tree

7 files changed

+73
-6
lines changed

7 files changed

+73
-6
lines changed
 

‎docs/changelog/8.x.x.txt

+1
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,5 @@
66
- Added Facebook Auth and FacebookLogin macro.
77
- Removed the WebGUI statistics program and code.
88
- Prevent Env Macro from being used to access objects in the environment - Thanks to Haarg
9+
- added: Redirect on Logout setting
910

‎lib/WebGUI/Auth.pm

+8-3
Original file line numberDiff line numberDiff line change
@@ -1001,12 +1001,12 @@ sub www_createAccountSave {
10011001
return $self->showMessageOnLogin;
10021002
}
10031003
elsif ($self->session->form->get('returnUrl')) {
1004-
$self->session->response->setRedirect( $self->session->form->get('returnUrl') );
1004+
$self->session->response->redirect( $self->session->form->get('returnUrl') );
10051005
$self->session->scratch->delete("redirectAfterLogin");
10061006
}
10071007
elsif ($self->session->scratch->get("redirectAfterLogin")) {
10081008
my $url = $self->session->scratch->delete("redirectAfterLogin");
1009-
$self->session->response->setRedirect($url);
1009+
$self->session->response->redirect($url);
10101010
return undef;
10111011
}
10121012
else {
@@ -1283,7 +1283,12 @@ sub www_logout {
12831283

12841284
# Do not allow caching of the logout page (to ensure the page gets requested)
12851285
$self->session->response->setCacheControl( "none" );
1286-
1286+
1287+
if ( $self->session->setting->get("redirectAfterLogoutUrl") ) {
1288+
$self->session->log->warn("redirecting to: ".$self->session->setting->get("redirectAfterLogoutUrl"));
1289+
$self->session->response->setRedirect($self->session->setting->get("redirectAfterLogoutUrl"));
1290+
}
1291+
12871292
return undef;
12881293
}
12891294

‎lib/WebGUI/Operation/Settings.pm

+8
Original file line numberDiff line numberDiff line change
@@ -495,6 +495,14 @@ sub definition {
495495
label => $i18n->get( 'redirectAfterLoginUrl label' ),
496496
hoverHelp => $i18n->get( 'redirectAfterLoginUrl description' ),
497497
};
498+
push @fields, {
499+
tab => "user",
500+
name => "redirectAfterLogoutUrl",
501+
fieldType => "url",
502+
defaultValue => $setting->get('redirectAfterLogoutUrl'),
503+
label => $i18n->get( 'redirectAfterLogoutUrl label' ),
504+
hoverHelp => $i18n->get( 'redirectAfterLogoutUrl description' ),
505+
};
498506
push @fields, {
499507
tab => "user",
500508
name => "showMessageOnLogin",

‎lib/WebGUI/Session/Response.pm

+1-2
Original file line numberDiff line numberDiff line change
@@ -176,8 +176,7 @@ sub setRedirect {
176176
my @params = $self->session->form->param;
177177
return undef if ($url eq $self->session->url->page() && scalar(@params) < 1); # prevent redirecting to self
178178
$self->session->log->info("Redirecting to $url");
179-
$self->location($url);
180-
$self->status($type);
179+
$self->redirect($url, $type);
181180
$self->session->style->setMeta({"http-equiv"=>"refresh",content=>"0; URL=".$url});
182181
}
183182

‎lib/WebGUI/i18n/English/WebGUI.pm

+13-1
Original file line numberDiff line numberDiff line change
@@ -4214,12 +4214,24 @@ LongTruncOk=1</p>
42144214
context => q{Label for site setting},
42154215
},
42164216

4217-
'showMessageOnLogin description' => {
4217+
'redirectAfterLoginUrl description' => {
42184218
message => q{Users will be redirected to this url after logging in.},
42194219
lastUpdated => 0,
42204220
context => q{Description for site setting},
42214221
},
42224222

4223+
'redirectAfterLogoutUrl label' => {
4224+
message => q{Redirect After Logout Url},
4225+
lastUpdated => 0,
4226+
context => q{Label for site setting},
4227+
},
4228+
4229+
'redirectAfterLogoutUrl description' => {
4230+
message => q{Users will be redirected to this url after logging out.},
4231+
lastUpdated => 0,
4232+
context => q{Description for site setting},
4233+
},
4234+
42234235
'showMessageOnLogin label' => {
42244236
message => q{Show Message On Login?},
42254237
lastUpdated => 0,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
use WebGUI::Upgrade::Script;
2+
start_step "Adding Redirect After Logout setting";
3+
session->setting->add('redirectAfterLogoutUrl');
4+
done;

‎t/Auth/RedirectAfterLogoutUrl.t

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# vim:syntax=perl
2+
#-------------------------------------------------------------------
3+
# WebGUI is Copyright 2001-2009 Plain Black Corporation.
4+
#-------------------------------------------------------------------
5+
# Please read the legal notices (docs/legal.txt) and the license
6+
# (docs/license.txt) that came with this distribution before using
7+
# this software.
8+
#------------------------------------------------------------------
9+
# http://www.plainblack.com info@plainblack.com
10+
#------------------------------------------------------------------
11+
12+
# Test Auth::LDAP to make sure it works with both ldap and ldaps
13+
#
14+
#
15+
16+
use FindBin;
17+
use strict;
18+
use lib "$FindBin::Bin/../lib";
19+
use Test::More;
20+
use WebGUI::Test; # Must use this before any other WebGUI modules
21+
use WebGUI::Session;
22+
23+
#----------------------------------------------------------------------------
24+
# Init
25+
my $session = WebGUI::Test->session;
26+
27+
my $user = WebGUI::User->create($session);
28+
WebGUI::Test->addToCleanup($user);
29+
30+
$session->setting->set('redirectAfterLogoutUrl');
31+
$user->authInstance->www_logout;
32+
is $session->response->redirect, undef, 'no redirect set on logout';
33+
34+
$session->setting->set('redirectAfterLogoutUrl', '/other_page');
35+
$user->authInstance->www_logout;
36+
is $session->response->redirect, '/other_page', 'redirect set on logout';
37+
38+
done_testing;

0 commit comments

Comments
 (0)
Please sign in to comment.