[Catalyst-commits] r7642 - / trunk/examples/NewAuthApp
trunk/examples/NewAuthApp/lib/NewAuthApp/Controller
trunk/examples/NewAuthApp/root trunk/examples/NewAuthApp/t
zarquon at dev.catalyst.perl.org
zarquon at dev.catalyst.perl.org
Tue Apr 29 13:58:17 BST 2008
Author: zarquon
Date: 2008-04-29 13:58:16 +0100 (Tue, 29 Apr 2008)
New Revision: 7642
Added:
trunk/examples/NewAuthApp/root/login.tt
trunk/examples/NewAuthApp/root/page.tt
Modified:
/
trunk/examples/NewAuthApp/lib/NewAuthApp/Controller/Auth.pm
trunk/examples/NewAuthApp/lib/NewAuthApp/Controller/Root.pm
trunk/examples/NewAuthApp/newauthapp.conf
trunk/examples/NewAuthApp/t/controller_Auth.t
Log:
r12991 at zaphod: kd | 2008-04-29 22:56:43 +1000
very simple working auth. next up, add realms and roles
Property changes on:
___________________________________________________________________
Name: svk:merge
- 1b129c88-ebf4-0310-add9-f09427935aba:/local/catalyst:4278
1c72fc7c-9ce4-42af-bf25-3bfe470ff1e8:/local/Catalyst:12990
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:12991
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-29 12:57:31 UTC (rev 7641)
+++ trunk/examples/NewAuthApp/lib/NewAuthApp/Controller/Auth.pm 2008-04-29 12:58:16 UTC (rev 7642)
@@ -4,20 +4,39 @@
use warnings;
use base 'Catalyst::Controller';
+sub get_login : Local {
+ my ($self, $c) = @_;
+ $c->stash->{destination} = $c->req->path;
+ $c->stash->{template} = 'login.tt';
+}
+
+sub logout : Local {
+ my ( $self, $c ) = @_;
+ $c->logout;
+}
+
sub login : Local {
my ( $self, $c ) = @_;
-
- if ( my $user = $c->req->params->{user}
- and my $password = $c->req->params->{password} ) {
- if ( $c->authenticate( { username => $user,
+ 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};
+ if ( $user && $password ) {
+ if ( $c->authenticate( { username => $user,
password => $password } ) ) {
+ warn "hit correct user";
$c->res->body( "hello " . $c->user->get("name") );
}
else {
+ warn "hit incorrect user";
+ $c->res->body( "login incorrect" );
# login incorrect
}
}
else {
+ $c->flash->{message} = 'invalid form input';
+ $c->stash->{template} = 'login.tt';
# invalid form input
}
}
Modified: trunk/examples/NewAuthApp/lib/NewAuthApp/Controller/Root.pm
===================================================================
--- trunk/examples/NewAuthApp/lib/NewAuthApp/Controller/Root.pm 2008-04-29 12:57:31 UTC (rev 7641)
+++ trunk/examples/NewAuthApp/lib/NewAuthApp/Controller/Root.pm 2008-04-29 12:58:16 UTC (rev 7642)
@@ -6,6 +6,12 @@
__PACKAGE__->config->{namespace} = '';
+sub auto : Private {
+ my ( $self, $c) = @_;
+ $c->forward('NewAuthApp::Controller::Auth', 'get_login') if (! $c->user && $c->req->path !~ /^auth.*?login/);
+ return 1;
+}
+
sub default : Private {
my ( $self, $c ) = @_;
Modified: trunk/examples/NewAuthApp/newauthapp.conf
===================================================================
--- trunk/examples/NewAuthApp/newauthapp.conf 2008-04-29 12:57:31 UTC (rev 7641)
+++ trunk/examples/NewAuthApp/newauthapp.conf 2008-04-29 12:58:16 UTC (rev 7642)
@@ -8,13 +8,13 @@
<bob>
roles edit
roles delete
- password s00p3r
+ password bob
editor yes
</bob>
- <william>
+ <bill>
roles comment
- password s3cr3t
- </william>
+ password bill
+ </bill>
</users>
</store>
<credential>
Added: trunk/examples/NewAuthApp/root/login.tt
===================================================================
--- trunk/examples/NewAuthApp/root/login.tt (rev 0)
+++ trunk/examples/NewAuthApp/root/login.tt 2008-04-29 12:58:16 UTC (rev 7642)
@@ -0,0 +1,11 @@
+[% 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 %]
Added: trunk/examples/NewAuthApp/root/page.tt
===================================================================
--- trunk/examples/NewAuthApp/root/page.tt (rev 0)
+++ trunk/examples/NewAuthApp/root/page.tt 2008-04-29 12:58:16 UTC (rev 7642)
@@ -0,0 +1,7 @@
+<html>
+<head>
+<title> [% c.config.name %]</title>
+</head>
+<body>
+[% content %]
+</body>
\ No newline at end of file
Property changes on: trunk/examples/NewAuthApp/root/page.tt
___________________________________________________________________
Name: svn:mime-type
+ text/html
Modified: trunk/examples/NewAuthApp/t/controller_Auth.t
===================================================================
--- trunk/examples/NewAuthApp/t/controller_Auth.t 2008-04-29 12:57:31 UTC (rev 7641)
+++ trunk/examples/NewAuthApp/t/controller_Auth.t 2008-04-29 12:58:16 UTC (rev 7642)
@@ -1,10 +1,21 @@
use strict;
use warnings;
-use Test::More tests => 3;
+use Test::More qw/no_plan/;
-BEGIN { use_ok 'Catalyst::Test', 'NewAuthApp' }
+BEGIN { use_ok 'Test::WWW::Mechanize::Catalyst', 'NewAuthApp' }
BEGIN { use_ok 'NewAuthApp::Controller::Auth' }
-ok( request('/auth')->is_success, 'Request should succeed' );
+my $mech = Test::WWW::Mechanize::Catalyst->new;
+$mech->get_ok('http://localhost/auth/get_login');
+$DB::single=1;
+$mech->submit_form( form_number => 1,
+ fields => {
+ user => 'bob',
+ password => 'bob',
+ },
+ );
+warn "here now";
+
+
More information about the Catalyst-commits
mailing list