add: Auth modules now accept a "returnUrl" form parameter when logging in or creating a new account. User will be redirected to the value in "returnUrl" after login / create account is complete.
add: L_LoginBox macro has a form.returnUrl template var that returns a user to the exact page they logged in from
This commit is contained in:
parent
04da356822
commit
1f10f07338
8 changed files with 163 additions and 9 deletions
105
t/Auth.t
Normal file
105
t/Auth.t
Normal file
|
|
@ -0,0 +1,105 @@
|
|||
# vim:syntax=perl
|
||||
#-------------------------------------------------------------------
|
||||
# WebGUI is Copyright 2001-2008 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
|
||||
#------------------------------------------------------------------
|
||||
|
||||
# Write a little about what this script tests.
|
||||
#
|
||||
#
|
||||
|
||||
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::Auth;
|
||||
use WebGUI::Session;
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
# Init
|
||||
my $session = WebGUI::Test->session;
|
||||
|
||||
my @cleanupUsernames = (); # Will be cleaned up when we're done
|
||||
my $AUTH_METHOD = "TEST"; # Used as second argument to WebGUI::Auth->new
|
||||
my $auth; # will be used to create auth instances
|
||||
my ($request, $oldRequest, $output);
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
# Tests
|
||||
|
||||
plan tests => 2; # Increment this number for each test you create
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
# Test createAccountSave and returnUrl together
|
||||
# Set up request
|
||||
$oldRequest = $session->request;
|
||||
$request = WebGUI::PseudoRequest->new;
|
||||
$request->setup_param({
|
||||
returnUrl => 'REDIRECT_URL',
|
||||
});
|
||||
$session->{_request} = $request;
|
||||
|
||||
$auth = WebGUI::Auth->new( $session, $AUTH_METHOD );
|
||||
my $username = $session->id->generate;
|
||||
push @cleanupUsernames, $username;
|
||||
$output = $auth->createAccountSave( $username, { }, "PASSWORD" );
|
||||
|
||||
is(
|
||||
$session->http->getRedirectLocation, 'REDIRECT_URL',
|
||||
"returnUrl field is used to set redirect after createAccountSave",
|
||||
);
|
||||
|
||||
# Session Cleanup
|
||||
$session->{_request} = $oldRequest;
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
# Test login and returnUrl together
|
||||
# Set up request
|
||||
$oldRequest = $session->request;
|
||||
$request = WebGUI::PseudoRequest->new;
|
||||
$request->setup_param({
|
||||
returnUrl => 'REDIRECT_LOGIN_URL',
|
||||
});
|
||||
$session->{_request} = $request;
|
||||
|
||||
$auth = WebGUI::Auth->new( $session, $AUTH_METHOD, 3 );
|
||||
my $username = $session->id->generate;
|
||||
push @cleanupUsernames, $username;
|
||||
$output = $auth->login;
|
||||
|
||||
is(
|
||||
$session->http->getRedirectLocation, 'REDIRECT_LOGIN_URL',
|
||||
"returnUrl field is used to set redirect after login",
|
||||
);
|
||||
|
||||
# Session Cleanup
|
||||
$session->{_request} = $oldRequest;
|
||||
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
# Cleanup
|
||||
END {
|
||||
for my $username ( @cleanupUsernames ) {
|
||||
# We don't create actual, real users, so we have to cleanup by hand
|
||||
my $userId = $session->db->quickScalar(
|
||||
"SELECT userId FROM users WHERE username=?",
|
||||
[ $username ]
|
||||
);
|
||||
|
||||
my @tableList
|
||||
= qw{authentication users userProfileData groupings inbox userLoginLog};
|
||||
|
||||
for my $table ( @tableList ) {
|
||||
$session->db->write(
|
||||
"DELETE FROM $table WHERE userId=?",
|
||||
[ $userId ]
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -29,13 +29,16 @@ $session->user({userId=>1});
|
|||
##known user agent. Since it usually contains a reference to %ENV,
|
||||
##you can't just modify that hash since it's protected
|
||||
my $origEnv = $session->{_env};
|
||||
my %newEnvHash = ('HTTP_USER_AGENT', 'mozilla');
|
||||
my %newEnvHash = (
|
||||
'HTTP_USER_AGENT' => 'mozilla',
|
||||
'QUERY_STRING' => 'func=search',
|
||||
);
|
||||
$session->{_env}->{_env} = \%newEnvHash;
|
||||
|
||||
my $i18n = WebGUI::International->new($session,'Macro_L_loginBox');
|
||||
|
||||
my $numTests = 1; #Module loading test
|
||||
$numTests += 29; #Static tests
|
||||
$numTests += 30; #Static tests
|
||||
|
||||
plan tests => $numTests;
|
||||
|
||||
|
|
@ -110,6 +113,14 @@ is(
|
|||
|
||||
is($vars{'form.footer'}, WebGUI::Form::formFooter($session), 'form.footer');
|
||||
|
||||
is( $vars{'form.returnUrl'},
|
||||
WebGUI::Form::hidden( $session, {
|
||||
name => 'returnUrl',
|
||||
value => $session->url->page($session->env->get("QUERY_STRING")),
|
||||
}),
|
||||
'form.returnUrl'
|
||||
);
|
||||
|
||||
##Now, test variations on user input, browser type and config settings
|
||||
|
||||
##Set non-default boxSize
|
||||
|
|
@ -223,7 +234,7 @@ sub setupTest {
|
|||
qw/user.isVisitor customText hello.label logout.url account.display.url
|
||||
logout.label form.header username.label username.form
|
||||
password.label password.form form.login account.create.url
|
||||
account.create.label form.footer/;
|
||||
account.create.label form.footer form.returnUrl/;
|
||||
#$properties->{template} .= "\n";
|
||||
my $template = $defaultNode->addChild($properties, $properties->{id});
|
||||
$versionTag->commit;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue