[Catalyst-commits] r7650 - /
trunk/examples/NewAuthApp/lib/NewAuthApp/Controller
trunk/examples/NewAuthApp/root trunk/examples/NewAuthApp/root/auth
trunk/examples/NewAuthApp/t
zarquon at dev.catalyst.perl.org
zarquon at dev.catalyst.perl.org
Wed Apr 30 11:40:13 BST 2008
Author: zarquon
Date: 2008-04-30 11:40:12 +0100 (Wed, 30 Apr 2008)
New Revision: 7650
Added:
trunk/examples/NewAuthApp/root/auth/
trunk/examples/NewAuthApp/root/auth/login.tt
Removed:
trunk/examples/NewAuthApp/root/login.tt
Modified:
/
trunk/examples/NewAuthApp/lib/NewAuthApp/Controller/Auth.pm
trunk/examples/NewAuthApp/lib/NewAuthApp/Controller/Root.pm
trunk/examples/NewAuthApp/t/controller_Auth.t
Log:
r12995 at zaphod: kd | 2008-04-30 12:08:03 +1000
basic example now working with decent www::mech test coverage
Property changes on:
___________________________________________________________________
Name: svk:merge
- 1b129c88-ebf4-0310-add9-f09427935aba:/local/catalyst:4278
1c72fc7c-9ce4-42af-bf25-3bfe470ff1e8:/local/Catalyst:12991
3b9770f9-e80c-0410-a7de-cd203d167417:/local/catalyst:3514
dd8ad9ea-0304-0410-a433-df5f223e7bc0:/local/Catalyst:6909
+ 1b129c88-ebf4-0310-add9-f09427935aba:/local/catalyst:4278
1c72fc7c-9ce4-42af-bf25-3bfe470ff1e8:/local/Catalyst:12995
3b9770f9-e80c-0410-a7de-cd203d167417:/local/catalyst:3514
dd8ad9ea-0304-0410-a433-df5f223e7bc0:/local/Catalyst:6909
Modified: trunk/examples/NewAuthApp/lib/NewAuthApp/Controller/Auth.pm
===================================================================
--- trunk/examples/NewAuthApp/lib/NewAuthApp/Controller/Auth.pm 2008-04-30 10:28:17 UTC (rev 7649)
+++ trunk/examples/NewAuthApp/lib/NewAuthApp/Controller/Auth.pm 2008-04-30 10:40:12 UTC (rev 7650)
@@ -7,37 +7,38 @@
sub get_login : Local {
my ($self, $c) = @_;
$c->stash->{destination} = $c->req->path;
- $c->stash->{template} = 'login.tt';
+ $c->stash->{template} = 'auth/login.tt';
}
sub logout : Local {
my ( $self, $c ) = @_;
$c->logout;
+ $c->stash->{template} = 'auth/logout.tt';
}
sub login : Local {
my ( $self, $c ) = @_;
my $user = $c->req->params->{user};
my $password = $c->req->params->{password};
- $DB::single=1;
$c->flash->{destination} = $c->req->params->{destination} || $c->req->path;
- $c->flash->{remember} = $c->req->params->{remember};
+ $c->stash->{remember} = $c->req->params->{remember};
if ( $user && $password ) {
if ( $c->authenticate( { username => $user,
password => $password } ) ) {
- warn "hit correct user";
- $c->res->body( "hello " . $c->user->get("name") );
+ $c->{session}{expires} = 999999999999 if $c->req->params->{remember};
+ $c->res->redirect($c->uri_for($c->flash->{destination}));
}
else {
- warn "hit incorrect user";
- $c->res->body( "login incorrect" );
# login incorrect
+ $DB::single=1;
+ $c->stash->{message} = 'Invalid user and/or password';
+ $c->stash->{template} = 'auth/login.tt';
}
}
else {
- $c->flash->{message} = 'invalid form input';
- $c->stash->{template} = 'login.tt';
# invalid form input
+ $c->stash->{message} = 'invalid form input';
+ $c->stash->{template} = 'auth/login.tt';
}
}
Modified: trunk/examples/NewAuthApp/lib/NewAuthApp/Controller/Root.pm
===================================================================
--- trunk/examples/NewAuthApp/lib/NewAuthApp/Controller/Root.pm 2008-04-30 10:28:17 UTC (rev 7649)
+++ trunk/examples/NewAuthApp/lib/NewAuthApp/Controller/Root.pm 2008-04-30 10:40:12 UTC (rev 7650)
@@ -8,15 +8,16 @@
sub auto : Private {
my ( $self, $c) = @_;
- $c->forward('NewAuthApp::Controller::Auth', 'get_login') if (! $c->user && $c->req->path !~ /^auth.*?login/);
+ if ( !$c->user && $c->req->path !~ /^auth.*?login/) {
+ $c->forward('NewAuthApp::Controller::Auth', 'get_login');
+ return 0;
+ }
return 1;
}
sub default : Private {
my ( $self, $c ) = @_;
-
- # Hello World
- $c->response->body( 'you made it' );
+ $c->stash->{template} = 'success.tt'
}
sub end : ActionClass('RenderView') {}
Added: trunk/examples/NewAuthApp/root/auth/login.tt
===================================================================
--- trunk/examples/NewAuthApp/root/auth/login.tt (rev 0)
+++ trunk/examples/NewAuthApp/root/auth/login.tt 2008-04-30 10:40:12 UTC (rev 7650)
@@ -0,0 +1,11 @@
+[% WRAPPER page.tt title = c.config.name %]
+<h1> Please login</h1>
+[% IF c.stash.message != '' %] <h2> style='color:red'> [% c.stash.message %] </h2> [% END %]
+<form name="login" method='post' action='[% c.uri_for('/auth/login') %]'>
+User: <input name='user' type='text' /><br />
+Password: <input name='password' type='password' /><br />
+<input type='checkbox' name='remember' >Remember me</input> <br />
+<input type='hidden' value='[% c.flash.destination %]' />
+<input type='submit' name='Log In' /> <input type='reset' name='Reset' />
+</form>
+[% END %]
Deleted: trunk/examples/NewAuthApp/root/login.tt
===================================================================
--- trunk/examples/NewAuthApp/root/login.tt 2008-04-30 10:28:17 UTC (rev 7649)
+++ trunk/examples/NewAuthApp/root/login.tt 2008-04-30 10:40:12 UTC (rev 7650)
@@ -1,11 +0,0 @@
-[% WRAPPER page.tt title = c.config.name %]
-<h1> Please login</h1>
-[% IF c.flash.mesage %] <h2 style='color:red'> [% c.flash.message %] </h2> [% END %]
-<form name="login" method='post' action='[% c.uri_for('/auth/login') %]'>
-User: <input name='user' type='text' /><br />
-Password: <input name='password' type='password' /><br />
-<input type='checkbox' name='remember' >Remember me</input> <br />
-<input type='hidden' value='[% c.flash.destination %]' />
-<input type='submit' name='Log In' /> <input type='reset' name='Reset' />
-</form>
-[% END %]
Modified: trunk/examples/NewAuthApp/t/controller_Auth.t
===================================================================
--- trunk/examples/NewAuthApp/t/controller_Auth.t 2008-04-30 10:28:17 UTC (rev 7649)
+++ trunk/examples/NewAuthApp/t/controller_Auth.t 2008-04-30 10:40:12 UTC (rev 7650)
@@ -6,16 +6,22 @@
BEGIN { use_ok 'NewAuthApp::Controller::Auth' }
my $mech = Test::WWW::Mechanize::Catalyst->new;
-$mech->get_ok('http://localhost/auth/get_login');
-$DB::single=1;
+$mech->get_ok('http://localhost/');
$mech->submit_form( form_number => 1,
fields => {
user => 'bob',
password => 'bob',
},
);
-warn "here now";
+$mech->content_contains('Login successful', 'logged in');
+$mech->follow_link_ok( {text => 'logout'}, 'logging out');
+$mech->content_contains('Logout successful', 'logged out');
+$mech->follow_link_ok( {text => 'Return to home page'}, 'back home');
+$mech->submit_form( form_number => 1,
+ fields => {
+ user => 'notbob',
+ password => 'notbob',
+ },
+ );
+$mech->content_contains('Invalid user and/or password', 'not logged in');
-
-
-
More information about the Catalyst-commits
mailing list