[Catalyst-commits] r13406 - in Catalyst-Helper-AuthDBIC/tags: .
0.14 0.14/lib/Catalyst/Helper 0.14/t
zarquon at dev.catalyst.perl.org
zarquon at dev.catalyst.perl.org
Fri Jul 9 00:25:31 GMT 2010
Author: zarquon
Date: 2010-07-09 01:25:31 +0100 (Fri, 09 Jul 2010)
New Revision: 13406
Added:
Catalyst-Helper-AuthDBIC/tags/0.14/
Catalyst-Helper-AuthDBIC/tags/0.14/Changes
Catalyst-Helper-AuthDBIC/tags/0.14/Makefile.PL
Catalyst-Helper-AuthDBIC/tags/0.14/lib/Catalyst/Helper/AuthDBIC.pm
Catalyst-Helper-AuthDBIC/tags/0.14/t/02-usage.t
Catalyst-Helper-AuthDBIC/tags/0.14/t/live-test.t
Removed:
Catalyst-Helper-AuthDBIC/tags/0.14/Changes
Catalyst-Helper-AuthDBIC/tags/0.14/Makefile.PL
Catalyst-Helper-AuthDBIC/tags/0.14/lib/Catalyst/Helper/AuthDBIC.pm
Catalyst-Helper-AuthDBIC/tags/0.14/t/02-usage.t
Catalyst-Helper-AuthDBIC/tags/0.14/t/live-test.t
Log:
version 0.14
Deleted: Catalyst-Helper-AuthDBIC/tags/0.14/Changes
===================================================================
--- Catalyst-Helper-AuthDBIC/trunk/Changes 2010-02-20 22:38:50 UTC (rev 12955)
+++ Catalyst-Helper-AuthDBIC/tags/0.14/Changes 2010-07-09 00:25:31 UTC (rev 13406)
@@ -1,31 +0,0 @@
- - update for DBIx::Class::Schema::Loader 0.05
-0.11 Jan 31 2010
- - Add parent.pm to dependencies.
- - Make TWMC optional and do not run mech tests if it's not installed.
-0.10 Aug 27 2009
- - Fix RT #49036 (thanks Tsvetozar Penov)
-0.09 Jun 18 2009
- - Fix RT # 47075 (thanks KMX)
-0.08 May 28 2009
- - Fix issue with Directory::Scratch in t/02-usage.t (thanks G.Wade Johnson)
-0.07 September 25 2008
- - Don't want to generate templates unless using password cred.
-0.06 September 24 2008
- - Moved from DBIx::Class::DigestColumns to DBIx::Class::EncodedColumn
- - Added option for password or http credentials.
-0.05 Tue Sep 2 2008
- - Bug fix for Multi::Level::App::Names
- - Addition of model config to .conf file
- - Changed from CatalystX starter to Module::Starter proper (make
- installdeps now works)
-0.04 Mon Sep 1 2008
- - Another stupid bug removed in Schema creation for Multi::Level::AppNames
-0.03 Mon Sep 1 2008
- - Remove the UNIVERSAL::require dep
- - Fix app_name to do the right thing with Multi::Level::AppNames
-0.02 Sun Aug 31 2008
- - Changed Auth::Schema to $appname::Auth::Schema
- - Added user admin scripts to script/myapp_adduser.pl
-0.01 Wed Aug 20
- - Initial very rough release
-
Copied: Catalyst-Helper-AuthDBIC/tags/0.14/Changes (from rev 13405, Catalyst-Helper-AuthDBIC/trunk/Changes)
===================================================================
--- Catalyst-Helper-AuthDBIC/tags/0.14/Changes (rev 0)
+++ Catalyst-Helper-AuthDBIC/tags/0.14/Changes 2010-07-09 00:25:31 UTC (rev 13406)
@@ -0,0 +1,38 @@
+0.14 Jul 9 2010
+ - Added missing dependency to fix cpantesters failure
+0.13 Jul 6 2010
+ - Fixed hard coded / for dir path to make things work in Windows (thanks Curtiss Jewel and rfulbrig RT #57648)
+0.12 Feb 20 2010
+ - applied patch from RT #47226 thanks to kmx
+ - apply patch from RT #54533 thanks to alfston pinto
+ - update for DBIx::Class::Schema::Loader 0.05
+0.11 Jan 31 2010
+ - Add parent.pm to dependencies.
+ - Make TWMC optional and do not run mech tests if it's not installed.
+0.10 Aug 27 2009
+ - Fix RT #49036 (thanks Tsvetozar Penov)
+0.09 Jun 18 2009
+ - Fix RT # 47075 (thanks KMX)
+0.08 May 28 2009
+ - Fix issue with Directory::Scratch in t/02-usage.t (thanks G.Wade Johnson)
+0.07 September 25 2008
+ - Don't want to generate templates unless using password cred.
+0.06 September 24 2008
+ - Moved from DBIx::Class::DigestColumns to DBIx::Class::EncodedColumn
+ - Added option for password or http credentials.
+0.05 Tue Sep 2 2008
+ - Bug fix for Multi::Level::App::Names
+ - Addition of model config to .conf file
+ - Changed from CatalystX starter to Module::Starter proper (make
+ installdeps now works)
+0.04 Mon Sep 1 2008
+ - Another stupid bug removed in Schema creation for Multi::Level::AppNames
+0.03 Mon Sep 1 2008
+ - Remove the UNIVERSAL::require dep
+ - Fix app_name to do the right thing with Multi::Level::AppNames
+0.02 Sun Aug 31 2008
+ - Changed Auth::Schema to $appname::Auth::Schema
+ - Added user admin scripts to script/myapp_adduser.pl
+0.01 Wed Aug 20
+ - Initial very rough release
+
Deleted: Catalyst-Helper-AuthDBIC/tags/0.14/Makefile.PL
===================================================================
--- Catalyst-Helper-AuthDBIC/trunk/Makefile.PL 2010-02-20 22:38:50 UTC (rev 12955)
+++ Catalyst-Helper-AuthDBIC/tags/0.14/Makefile.PL 2010-07-09 00:25:31 UTC (rev 13406)
@@ -1,36 +0,0 @@
-use inc::Module::Install 0.87;
-
-name 'Catalyst-Helper-AuthDBIC';
-all_from 'lib/Catalyst/Helper/AuthDBIC.pm';
-author 'Kieren Diment <zarquon at cpan.org>';
-
-build_requires 'Test::More';
-
-build_requires 'Catalyst::Runtime';
-build_requires 'ok';
-requires 'parent';
-requires 'DBIx::Class::EncodedColumn';
-requires 'PPI';
-requires 'Catalyst::Model::DBIC::Schema' => '0.40';
-requires 'DBIx::Class::Schema::Loader' => '0.05003';
-build_requires 'Directory::Scratch';
-build_requires 'Test::Command';
-
-# not real deps but the generated bits of app need them.
-requires 'Catalyst::Plugin::Authentication';
-requires 'Catalyst::Plugin::Authorization::Roles';
-requires 'Catalyst::Plugin::Session';
-requires 'Catalyst::Plugin::Session::State::Cookie';
-requires 'Catalyst::Plugin::Session::Store::FastMmap';
-requires 'Catalyst::Authentication::Store::DBIx::Class';
-requires 'Catalyst::Authentication::Credential::HTTP';
-
-install_script glob('script/*.pl');
-
-
-auto_install;
-
-resources repository => 'http://dev.catalyst.perl.org/repos/Catalyst/Catalyst-Helper-AuthDBIC/trunk/';
-
-WriteAll;
-
Copied: Catalyst-Helper-AuthDBIC/tags/0.14/Makefile.PL (from rev 13405, Catalyst-Helper-AuthDBIC/trunk/Makefile.PL)
===================================================================
--- Catalyst-Helper-AuthDBIC/tags/0.14/Makefile.PL (rev 0)
+++ Catalyst-Helper-AuthDBIC/tags/0.14/Makefile.PL 2010-07-09 00:25:31 UTC (rev 13406)
@@ -0,0 +1,37 @@
+use inc::Module::Install 0.87;
+
+name 'Catalyst-Helper-AuthDBIC';
+all_from 'lib/Catalyst/Helper/AuthDBIC.pm';
+author 'Kieren Diment <zarquon at cpan.org>';
+
+build_requires 'Test::More';
+
+build_requires 'Catalyst::Runtime';
+build_requires 'ok';
+requires 'parent';
+requires 'Catalyst::Devel';
+requires 'DBIx::Class::EncodedColumn';
+requires 'PPI';
+requires 'Catalyst::Model::DBIC::Schema' => '0.40';
+requires 'DBIx::Class::Schema::Loader' => '0.05003';
+build_requires 'Directory::Scratch';
+build_requires 'Test::Command';
+
+# not real deps but the generated bits of app need them.
+requires 'Catalyst::Plugin::Authentication';
+requires 'Catalyst::Plugin::Authorization::Roles';
+requires 'Catalyst::Plugin::Session';
+requires 'Catalyst::Plugin::Session::State::Cookie';
+requires 'Catalyst::Plugin::Session::Store::FastMmap';
+requires 'Catalyst::Authentication::Store::DBIx::Class';
+requires 'Catalyst::Authentication::Credential::HTTP';
+
+install_script glob('script/*.pl');
+
+
+auto_install;
+
+resources repository => 'http://dev.catalyst.perl.org/repos/Catalyst/Catalyst-Helper-AuthDBIC/trunk/';
+
+WriteAll;
+
Deleted: Catalyst-Helper-AuthDBIC/tags/0.14/lib/Catalyst/Helper/AuthDBIC.pm
===================================================================
--- Catalyst-Helper-AuthDBIC/trunk/lib/Catalyst/Helper/AuthDBIC.pm 2010-02-20 22:38:50 UTC (rev 12955)
+++ Catalyst-Helper-AuthDBIC/tags/0.14/lib/Catalyst/Helper/AuthDBIC.pm 2010-07-09 00:25:31 UTC (rev 13406)
@@ -1,577 +0,0 @@
-package Catalyst::Helper::AuthDBIC;
-use strict;
-use warnings;
-use Catalyst::Helper;
-our $VERSION = '0.11';
-use Carp;
-use DBI;
-use DBIx::Class::Schema::Loader qw/ make_schema_at /;
-use Memoize;
-use PPI;
-use PPI::Find;
-use Catalyst::Utils;
-use File::Spec;
-use Config;
-
-memoize('app_name');
-
-=head1 NAME
-
-Catalyst::Helper::AuthDBIC (EXPERIMENTAL)
-
-=head1 SUMMARY
-
-This is an experimental module to bootstrap the authentication portion
-of a Catalyst application. It creates a Catalyst model,
-DBIx::Class::Schema classes, basic templates adjusts the required
-plugins for you, and configures authentication. There are no options,
-and it doesn't do much inthe way of error checking for you, so you are
-recommended to back up your application before using this module.
-
-=head2 USAGE
-
-Run the auth_bootstrap.pl in your application's root dir.
-
-The helper also creates a script in the script dir. To add a user
-(with an optional role) do:
-
- myapp_auth_admin.pl -user username -passwd password [-role role] [-email me at example.com]
-
-=head2 sub app_name()
-
-Get the name of the application from Makefile.PL
-
-=cut
-
-sub app_name {
- my $app_name;
- my $file = "Makefile.PL";
- open my ($FH), "<", $file or croak "Makefile.PL not found, run this script from your application root dir\n";
- while (<$FH>) {
- next unless /^name '(.*?)';/;
- $app_name=$1;
- $app_name =~ s/-/::/g; # only unsafe if you are already insane
- # because everything else in
- # Catalyst::Helper will also be broken
- # for you.
- croak "Makefile.PL appears to have no name for the application\n" unless $app_name;
- last;
- }
- return $app_name
-}
-
-=head2 sub make_model()
-
-Creates the sqlite auth db in ./db and makes the dbic schema and
-catalyst model with Catalyst::Helper::Model::DBIC::Schema
-
-=cut
-
-sub make_model {
- # put sqlitedb in __path_to('db')__;
- my $helper = Catalyst::Helper->new();
- $helper->mk_dir('db');
- my $dbh = DBI->connect("dbi:SQLite:dbname=db/auth.db","","");
- my @sql = ("CREATE TABLE role (
- id INTEGER PRIMARY KEY,
- role TEXT UNIQUE );",
- "CREATE TABLE user (
- id INTEGER PRIMARY KEY,
- username TEXT UNIQUE,
- email TEXT,
- password TEXT,
- status TEXT,
- role_text TEXT,
- session_data TEXT );",
- "CREATE TABLE user_role (
- id INTEGER PRIMARY KEY,
- user INTEGER REFERENCES user(id),
- roleid INTEGER REFERENCES role(id) );"
- );
-
- map { $dbh->do($_) } @sql;
- my $app_prefix = Catalyst::Utils::appprefix(app_name());
-
- make_schema_at(app_name() . "::Auth::Schema",
- { components => ['EncodedColumn'],
- dump_directory => 'lib' ,
- },
- ["dbi:SQLite:dbname=db/auth.db", "",""]);
-
- my @cmd = ( "./script/$app_prefix" . "_create.pl" ,
- 'model',
- 'Auth',
- 'DBIC::Schema',
- app_name() . "::Auth::Schema",
- );
- system( @cmd );
- my $schema_name = app_name() . "::Auth::Schema";
- my $user_schema = "$schema_name"."::Result::User";
- my @path = split /::/, $user_schema;
- my $user_schema_path = join '/', @path;
- my $module = "lib/$user_schema_path.pm";
- my $doc = PPI::Document->new($module);
- my $digest_code = $helper->get_file(__PACKAGE__, 'digest');
-
- my $comments = $doc->find(
- sub { $_[1]->isa('PPI::Token::Comment')}
- );
- my $last_comment = $comments->[$#{$comments}];
- $last_comment->set_content($digest_code);
- $doc->save($module);
-
- # we need to specify the dsn with __path_to(db/auth.db)__ in
- # .conf, rather than code in the model.
- my $conf_file = "$app_prefix.conf";
-
- open my $FH, ">>", $conf_file;
- my $conf = <<EOF;
- <Model Auth>
- schema_class $schema_name
- connect_info dbi:SQLite:__path_to(db/auth.db)__
- connect_info user
- connect_info passwd # keep these here for dsns that need 'em
- </Model>
-EOF
- print $FH $conf;
- close $FH;
-}
-
-=head2 sub mk_auth_controller()
-
-uses Catalyst::Helper to make a ::Controller::Auth
-
-=cut
-
-sub mk_auth_controller {
- my $helper = Catalyst::Helper->new();
- my $app_path = app_name();
- $app_path =~ s/::/\//g;
- my $controller_file = "lib/$app_path/Controller/Auth.pm";
- $helper->render_file ('auth_controller',
- $controller_file,
- {app_name => app_name()});
-}
-
-=head2 sub add_plugins()
-
- uses ppi to add the auth plugins in the use Catalyst qw// statement
-
-=cut
-
-sub add_plugins {
- my ($module, $doc) = _get_ppi();
-
- my $find = PPI::Find->new( \&_find_use_catalyst);
- my ($found) = $find->in($doc);
- my $find_plugins = PPI::Find->new(\&_find_plugins);
- my ($plugins) = $find_plugins->in($found);
- croak "Your app is not using any plugins, so we can't continue\n" if !$plugins;
- my $plugin_str = scalar($plugins);
- my $tail = chop $plugin_str;
- $plugin_str .= "\n Authentication\n Authorization::Roles\n Session\n Session::State::Cookie\n Session::Store::FastMmap $tail";
- $plugins->set_content($plugin_str);
- $doc->save($module);
-}
-
-sub _find_plugins {
- my ($element, $search) = @_;
- return 1 if $element->isa('PPI::Token::QuoteLike::Words');
- return 0
-}
-
-sub _find_use_catalyst {
- my ($element, $search) = @_;
- if ( $element->isa('PPI::Statement::Include') &&
- $element->type eq 'use' &&
- $element->module eq 'Catalyst'
- ) {
- return 1;
- }
- return 0;
-}
-
-=head2 sub add_config()
-
-Add the auth configuration in MyApp.pm
-
-=cut
-
-sub add_config {
- my ($credential) = @_;
- my ($module, $doc) = _get_ppi();
- my $found = PPI::Find->new(\&_find_setup);
- my ($setup) = $found->in($doc);
- croak "unable to find __PACKAGE__->setup in $module\n" if !$setup;
- my $auth_doc_plain;
-
- if ( $credential eq 'http' ) {
- warn "Configuring http credential\n";
- $auth_doc_plain = Catalyst::Helper->get_file(__PACKAGE__, 'auth_conf_http');
- }
- elsif ( $credential eq 'password' ) {
- warn "Configuring password (web based) authentication credential\n";
- $auth_doc_plain = Catalyst::Helper->get_file(__PACKAGE__, 'auth_conf_passwd');
- }
-
- $auth_doc_plain =~ s/__MYSCHEMA__/Auth/msg;
- my $auth_doc = PPI::Document->new(\$auth_doc_plain);
- my $auth_conf = $auth_doc->find_first('PPI::Statement');
- # the code produced here is a little ugly and lacks a \n between
- # the config and the __PACKAGE__->setup declaration. The usage of
- # PPI to modify source is also inconsistent here to elewhere.
- $setup->insert_before($auth_conf);
- $doc->save($module);
-}
-
-sub _find_setup {
- my ($element, $search) = @_;
- if ( $element->isa('PPI::Statement')
- && $element =~ /setup.*?;/
- ) {
- return 1;
- }
- return 0;
-}
-
-sub _get_ppi {
- my $app_name = app_name() || 'TestApp';
- my @path = split /::/, $app_name;
- my $app_path = join '/', @path;
- my $module = "lib/$app_path.pm";
- my $doc = PPI::Document->new($module);
- return ($module, $doc);
-}
-
-=head2 sub write_templates()
-
-make the login, logout and unauth templates
-
-=cut
-
-sub write_templates {
- my $helper = Catalyst::Helper->new();
- my $login = $helper->get_file(__PACKAGE__, 'login.tt');
- my $logout = $helper->get_file(__PACKAGE__, 'logout.tt');
- my $unauth = $helper->get_file(__PACKAGE__, 'unauth.tt');
- $helper->mk_dir("root/auth");
- $helper->mk_file("root/auth/login.tt", $login);
- $helper->mk_file("root/auth/logout.tt", $logout);
- $helper->mk_file("root/auth/unauth.tt", $unauth);
-}
-
-=head2 sub update_makefile()
-
-Adds the auth and session dependencies to Makefile.PL
-
-=cut
-
-sub update_makefile {
- my $deps = Catalyst::Helper->get_file(__PACKAGE__, 'requires');
- my $doc = PPI::Document->new('Makefile.PL');
- my $find = PPI::Find->new( \&_find_install_script );
- my ($found) = $find->in($doc);
- croak "There's something wrong with your Makefile.PL so we can't continue (can't find the install_script directive\n" if ! $found;
- my $install_script = $found->find_first('PPI::Token::Word');
- my $install_script_str = scalar($install_script);
- $install_script->set_content($deps . "\n" . $install_script_str);
- $doc->save('Makefile.PL')
-}
-
-sub _find_install_script {
- my ($element, $search) = @_;
- if ($element->isa('PPI::Statement')
- && $element =~ 'install_script') {
- return 1;
- }
- return 0;
-}
-
-=head2 sub add_user_helper()
-
-A little script to add a user to the database.
-
-=cut
-
-sub add_user_helper {
- my $helper = Catalyst::Helper->new;
- my $app_prefix = Catalyst::Utils::appprefix(app_name());
- my $script_dir = File::Spec->catdir( '.', 'script' );
- my $script = "$script_dir\/$app_prefix\_auth_admin.pl";
- my $startperl = "#!$Config{perlpath} -w";
- $DB::single=1;
- $helper->render_file('auth_admin',
- $script,
- { start_perl => $startperl,
- appprefix => $app_prefix,
- startperl => $startperl,
- app_name => app_name(),
- });
- chmod 0700, $script;
-}
-
-=head2 BUGS
-
-This is experimental, fairly rough code. It's a proof of concept for
-helper modules for Catalyst that need to alter the application
-configuration, Makefile.PL and other parts of the application. Bug
-reports, and patches are encouraged. Report bugs or provide patches
-to http://rt.cpan.org/NoAuth/Bugs.html?Dist=Catalyst-Helper-AuthDBIC.
-
-=head2 AUTHOR
-
-Kieren Diment <zarquon at cpan.org>
-
-
-=head1 COPYRIGHT AND LICENCE
-
-Copyright (c) 2008 Kieren Diment
-
-This library is free software; you can redistribute it and/or modify it under
-the same terms as Perl itself.
-
-See L<http://www.perl.com/perl/misc/Artistic.html>
-
-=cut
-
-1;
-
-__DATA__
-
-=begin pod_to_ignore
-
-__auth_controller__
-package [% app_name %]::Controller::Auth;
-
-use strict;
-use warnings;
-use base 'Catalyst::Controller';
-
-sub index :Path :Args(0) {
- my ($self, $c) = @_;
- $c->detach('get_login');
-}
-
-sub get_login : Local {
- my ($self, $c) = @_;
- $c->stash->{destination} = $c->req->path;
- $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};
- $c->flash->{destination} = $c->req->params->{destination} || $c->req->path;
- $c->stash->{remember} = $c->req->params->{remember};
- if ( $user && $password ) {
- if ( $c->authenticate( { username => $user,
- password => $password } ) ) {
- $c->{session}{expires} = 999999999999 if $c->req->params->{remember};
- $c->res->redirect($c->uri_for($c->flash->{destination}));
- }
- else {
- # login incorrect
- $c->stash->{message} = 'Invalid user and/or password';
- $c->stash->{template} = 'auth/login.tt';
- }
- }
- else {
- # invalid form input
- $c->stash->{message} = 'invalid form input';
- $c->stash->{template} = 'auth/login.tt';
- }
-}
-
-sub unauthorized : Private {
- my ($self, $c) = @_;
- $c->stash->{template}= 'auth/unauth.tt';
-}
-
-1;
-
-=pod
-
-=head1 NAME
-
-[% app_name %]Controller::Auth
-
-=head2 SUMMARY
-
-This is a controller to provide simple authentication provided by
-Catalyst::Helper::AuthDBIC. The database schema provided by the Helper
-will also provide autheorization facilities. As an example, If you
-wanted to use this controller to provide application wide requirement
-for login you would put something like the following in
-MyApp::Controller::Root:
-
- sub auto : Private {
- my ( $self, $c) = @_;
- if ( !$c->user && $c->req->path !~ /^auth.*?login/) {
- $c->forward('[% app_name %]::Controller::Auth');
- return 0;
- }
- return 1;
- }
-
-=cut
-
-__auth_conf_http__
- __PACKAGE__->config( authentication => {
- 'default_realm' => 'users',
- 'realms' => {
- 'users' => {
- 'store' => {
- 'role_column' => 'role_text',
- 'user_class' => '__MYSCHEMA__::User',
- 'class' => 'DBIx::Class',
- },
- 'credential' => {
- 'password_type' => 'hashed',
- 'password_field' => 'password',
- 'password_hash_type' => 'SHA-1',
- 'class' => 'HTTP',
- 'type' => 'basic',
- }
- }
- },
-});
-
-
-__auth_conf_password__
- __PACKAGE__->config( authentication => {
- 'default_realm' => 'users',
- 'realms' => {
- 'users' => {
- 'store' => {
- 'role_column' => 'role_text',
- 'user_class' => '__MYSCHEMA__::User',
- 'class' => 'DBIx::Class',
- },
- 'credential' => {
- 'password_type' => 'hashed',
- 'password_field' => 'password',
- 'password_hash_type' => 'SHA-1',
- 'class' => 'Password'
- }
- }
- },
-});
-
-__digest__
-
- __PACKAGE__->add_columns(
- 'password' => {
- data_type => 'CHAR',
- size => 40,
- encode_column => 1,
- encode_class => 'Digest',
- encode_args => {algorithm => 'SHA-1', format => 'hex'},
- });
-
-__requires__
-requires 'Catalyst::Plugin::Authentication';
-requires 'Catalyst::Plugin::Authorization::Roles';
-requires 'Catalyst::Plugin::Session';
-requires 'Catalyst::Plugin::Session::State::Cookie';
-requires 'Catalyst::Plugin::Session::Store::FastMmap';
-requires 'Catalyst::Authentication::Store::DBIx::Class';
-requires 'Catalyst::Authentication::Credential::HTTP';
-requires 'DBIx::Class::EncodedColumn';
-__login.tt__
-<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>
-
-__logout.tt__
-<h1> Logout successful</h1>
-<a href='[% c.uri_for('/') %]'>Return to home page</a>
-__unauth.tt__
-<h1> [%c.user.id %]: You are not allowed to view this page.</h1>
-You can <a href="[% c.req.referrer %]">go back</a> where you came from, or <a h
-ref="[% c.uri_for('/auth/logout') %]">logout</a> and try logging in again as a d
-ifferent user. If you think this is an error, please contact <a href="mailto:[%
-c.config.admin %]">[% c.config.admin %]</a>
-
-__auth_admin__
-[% startperl %]
-
-use strict;
-use warnings;
-use Pod::Usage;
-use Getopt::Long;
-use FindBin qw/$Bin/;
-use lib "$Bin/../lib";
-
-use [% app_name %]::Auth::Schema;
-
-my $user = undef;
-my $passwd = undef;
-my $help = undef;
-my $role = undef;
-my $email = undef;
-my $schema = [% app_name %]::Auth::Schema->connect("dbi:SQLite:$Bin/../db/auth.db");
-
-GetOptions(
- 'user=s' => \$user,
- 'pass|password|passwd=s' => \$passwd,
- 'role:s' => \$role,
- 'help' => \$help,
- 'email:s' => \$email,
-);
-
-pod2usage(1) if ( $help || !$user || !$passwd );
-
-add_user($schema, $user,$passwd,$role, $email);
-
-sub add_user {
- my ($schema, $user, $passwd, $role, $email ) = @_;
- my %user_insert = (
- username => $user,
- password => $passwd,
- email => $email,
- role_text => $role,
- );
-
- my $role_rs = undef;
- if ($role) {
- $role_rs = $schema->resultset('Role')->find_or_create({role => $role});
- $user_insert{role_text} = $role;
- }
- my $user_rs = $schema->resultset('User')->create(\%user_insert);
- if ($role_rs) {
- my $user_role_rs = $schema->resultset('UserRole')
- ->create({ user => $user_rs,
- roleid => $role_rs});
- }
-}
-
-=head1 NAME
-
-[% appprefix %]_auth_admin.pl - Sets the username and password for the generated authentication database
-
-=head1 SYNOPSIS
-
-[% appprefix %]_auth_admin.pl -user username -passwd password [-role role]
-
- Options:
- -user username
- -passwd password
- -role role (optional)
- -email email address (optional)
- -help display this help and exit
-
-=cut
Copied: Catalyst-Helper-AuthDBIC/tags/0.14/lib/Catalyst/Helper/AuthDBIC.pm (from rev 13405, Catalyst-Helper-AuthDBIC/trunk/lib/Catalyst/Helper/AuthDBIC.pm)
===================================================================
--- Catalyst-Helper-AuthDBIC/tags/0.14/lib/Catalyst/Helper/AuthDBIC.pm (rev 0)
+++ Catalyst-Helper-AuthDBIC/tags/0.14/lib/Catalyst/Helper/AuthDBIC.pm 2010-07-09 00:25:31 UTC (rev 13406)
@@ -0,0 +1,579 @@
+package Catalyst::Helper::AuthDBIC;
+use strict;
+use warnings;
+use Catalyst::Helper;
+our $VERSION = '0.14';
+use Carp;
+use DBI;
+use DBIx::Class::Schema::Loader qw/ make_schema_at /;
+use Memoize;
+use PPI;
+use PPI::Find;
+use Catalyst::Utils;
+use File::Spec;
+use Config;
+
+memoize('app_name');
+
+=head1 NAME
+
+Catalyst::Helper::AuthDBIC (EXPERIMENTAL)
+
+=head1 SUMMARY
+
+This is an experimental module to bootstrap the authentication portion
+of a Catalyst application. It creates a Catalyst model,
+DBIx::Class::Schema classes, basic templates adjusts the required
+plugins for you, and configures authentication. There are no options,
+and it doesn't do much inthe way of error checking for you, so you are
+recommended to back up your application before using this module.
+
+=head2 USAGE
+
+Run the auth_bootstrap.pl in your application's root dir.
+
+The helper also creates a script in the script dir. To add a user
+(with an optional role) do:
+
+ myapp_auth_admin.pl -user username -passwd password [-role role] [-email me at example.com]
+
+=head2 sub app_name()
+
+Get the name of the application from Makefile.PL
+
+=cut
+
+sub app_name {
+ my $app_name;
+ my $file = "Makefile.PL";
+ open my ($FH), "<", $file or croak "Makefile.PL not found, run this script from your application root dir\n";
+ while (<$FH>) {
+ next unless /^name '(.*?)';/;
+ $app_name=$1;
+ $app_name =~ s/-/::/g; # only unsafe if you are already insane
+ # because everything else in
+ # Catalyst::Helper will also be broken
+ # for you.
+ croak "Makefile.PL appears to have no name for the application\n" unless $app_name;
+ last;
+ }
+ return $app_name
+}
+
+=head2 sub make_model()
+
+Creates the sqlite auth db in ./db and makes the dbic schema and
+catalyst model with Catalyst::Helper::Model::DBIC::Schema
+
+=cut
+
+sub make_model {
+ # put sqlitedb in __path_to('db')__;
+ my $helper = Catalyst::Helper->new();
+ $helper->mk_dir('db');
+ my $dbh = DBI->connect("dbi:SQLite:dbname=db/auth.db","","");
+ my @sql = ("CREATE TABLE role (
+ id INTEGER PRIMARY KEY,
+ role TEXT UNIQUE );",
+ "CREATE TABLE user (
+ id INTEGER PRIMARY KEY,
+ username TEXT UNIQUE,
+ email TEXT,
+ password TEXT,
+ status TEXT,
+ role_text TEXT,
+ session_data TEXT );",
+ "CREATE TABLE user_role (
+ id INTEGER PRIMARY KEY,
+ user INTEGER REFERENCES user(id),
+ roleid INTEGER REFERENCES role(id) );"
+ );
+
+ map { $dbh->do($_) } @sql;
+ my $app_prefix = Catalyst::Utils::appprefix(app_name());
+
+ make_schema_at(app_name() . "::Auth::Schema",
+ { components => ['EncodedColumn'],
+ dump_directory => 'lib' ,
+ },
+ ["dbi:SQLite:dbname=db/auth.db", "",""]);
+ my $create_file = File::Spec->catfile(File::Spec->curdir(),
+ 'script',
+ "${app_prefix}_create.pl");
+ my @cmd = ( "$create_file",
+ 'model',
+ 'Auth',
+ 'DBIC::Schema',
+ app_name() . "::Auth::Schema",
+ );
+ system( @cmd );
+ my $schema_name = app_name() . "::Auth::Schema";
+ my $user_schema = "$schema_name"."::Result::User";
+ my @path = split /::/, $user_schema;
+ my $user_schema_path = join '/', @path;
+ my $module = "lib/$user_schema_path.pm";
+ my $doc = PPI::Document->new($module);
+ my $digest_code = $helper->get_file(__PACKAGE__, 'digest');
+
+ my $comments = $doc->find(
+ sub { $_[1]->isa('PPI::Token::Comment')}
+ );
+ my $last_comment = $comments->[$#{$comments}];
+ $last_comment->set_content($digest_code);
+ $doc->save($module);
+
+ # we need to specify the dsn with __path_to(db/auth.db)__ in
+ # .conf, rather than code in the model.
+ my $conf_file = "$app_prefix.conf";
+
+ open my $FH, ">>", $conf_file;
+ my $conf = <<EOF;
+ <Model Auth>
+ schema_class $schema_name
+ connect_info dbi:SQLite:__path_to(db/auth.db)__
+ connect_info user
+ connect_info passwd # keep these here for dsns that need 'em
+ </Model>
+EOF
+ print $FH $conf;
+ close $FH;
+}
+
+=head2 sub mk_auth_controller()
+
+uses Catalyst::Helper to make a ::Controller::Auth
+
+=cut
+
+sub mk_auth_controller {
+ my $helper = Catalyst::Helper->new();
+ my $app_path = app_name();
+ $app_path =~ s/::/\//g;
+ my $controller_file = "lib/$app_path/Controller/Auth.pm";
+ $helper->render_file ('auth_controller',
+ $controller_file,
+ {app_name => app_name()});
+}
+
+=head2 sub add_plugins()
+
+ uses ppi to add the auth plugins in the use Catalyst qw// statement
+
+=cut
+
+sub add_plugins {
+ my ($module, $doc) = _get_ppi();
+
+ my $find = PPI::Find->new( \&_find_use_catalyst);
+ my ($found) = $find->in($doc);
+ my $find_plugins = PPI::Find->new(\&_find_plugins);
+ my ($plugins) = $find_plugins->in($found);
+ croak "Your app is not using any plugins, so we can't continue\n" if !$plugins;
+ my $plugin_str = scalar($plugins);
+ my $tail = chop $plugin_str;
+ $plugin_str .= "\n Authentication\n Authorization::Roles\n Session\n Session::State::Cookie\n Session::Store::FastMmap $tail";
+ $plugins->set_content($plugin_str);
+ $doc->save($module);
+}
+
+sub _find_plugins {
+ my ($element, $search) = @_;
+ return 1 if $element->isa('PPI::Token::QuoteLike::Words');
+ return 0
+}
+
+sub _find_use_catalyst {
+ my ($element, $search) = @_;
+ if ( $element->isa('PPI::Statement::Include') &&
+ $element->type eq 'use' &&
+ $element->module eq 'Catalyst'
+ ) {
+ return 1;
+ }
+ return 0;
+}
+
+=head2 sub add_config()
+
+Add the auth configuration in MyApp.pm
+
+=cut
+
+sub add_config {
+ my ($credential) = @_;
+ my ($module, $doc) = _get_ppi();
+ my $found = PPI::Find->new(\&_find_setup);
+ my ($setup) = $found->in($doc);
+ croak "unable to find __PACKAGE__->setup in $module\n" if !$setup;
+ my $auth_doc_plain;
+
+ if ( $credential eq 'http' ) {
+ warn "Configuring http credential\n";
+ $auth_doc_plain = Catalyst::Helper->get_file(__PACKAGE__, 'auth_conf_http');
+ }
+ elsif ( $credential eq 'password' ) {
+ warn "Configuring password (web based) authentication credential\n";
+ $auth_doc_plain = Catalyst::Helper->get_file(__PACKAGE__, 'auth_conf_passwd');
+ }
+
+ $auth_doc_plain =~ s/__MYSCHEMA__/Auth/msg;
+ my $auth_doc = PPI::Document->new(\$auth_doc_plain);
+ my $auth_conf = $auth_doc->find_first('PPI::Statement');
+ # the code produced here is a little ugly and lacks a \n between
+ # the config and the __PACKAGE__->setup declaration. The usage of
+ # PPI to modify source is also inconsistent here to elewhere.
+ $setup->insert_before($auth_conf);
+ $doc->save($module);
+}
+
+sub _find_setup {
+ my ($element, $search) = @_;
+ if ( $element->isa('PPI::Statement')
+ && $element =~ /setup.*?;/
+ ) {
+ return 1;
+ }
+ return 0;
+}
+
+sub _get_ppi {
+ my $app_name = app_name() || 'TestApp';
+ my @path = split /::/, $app_name;
+ my $app_path = join '/', @path;
+ my $module = "lib/$app_path.pm";
+ my $doc = PPI::Document->new($module);
+ return ($module, $doc);
+}
+
+=head2 sub write_templates()
+
+make the login, logout and unauth templates
+
+=cut
+
+sub write_templates {
+ my $helper = Catalyst::Helper->new();
+ my $login = $helper->get_file(__PACKAGE__, 'login.tt');
+ my $logout = $helper->get_file(__PACKAGE__, 'logout.tt');
+ my $unauth = $helper->get_file(__PACKAGE__, 'unauth.tt');
+ $helper->mk_dir("root/auth");
+ $helper->mk_file("root/auth/login.tt", $login);
+ $helper->mk_file("root/auth/logout.tt", $logout);
+ $helper->mk_file("root/auth/unauth.tt", $unauth);
+}
+
+=head2 sub update_makefile()
+
+Adds the auth and session dependencies to Makefile.PL
+
+=cut
+
+sub update_makefile {
+ my $deps = Catalyst::Helper->get_file(__PACKAGE__, 'requires');
+ my $doc = PPI::Document->new('Makefile.PL');
+ my $find = PPI::Find->new( \&_find_install_script );
+ my ($found) = $find->in($doc);
+ croak "There's something wrong with your Makefile.PL so we can't continue (can't find the install_script directive\n" if ! $found;
+ my $install_script = $found->find_first('PPI::Token::Word');
+ my $install_script_str = scalar($install_script);
+ $install_script->set_content($deps . "\n" . $install_script_str);
+ $doc->save('Makefile.PL')
+}
+
+sub _find_install_script {
+ my ($element, $search) = @_;
+ if ($element->isa('PPI::Statement')
+ && $element =~ 'install_script') {
+ return 1;
+ }
+ return 0;
+}
+
+=head2 sub add_user_helper()
+
+A little script to add a user to the database.
+
+=cut
+
+sub add_user_helper {
+ my $helper = Catalyst::Helper->new;
+ my $app_prefix = Catalyst::Utils::appprefix(app_name());
+ my $script_dir = File::Spec->catdir( '.', 'script' );
+ my $script = "$script_dir\/$app_prefix\_auth_admin.pl";
+ my $startperl = "#!$Config{perlpath} -w";
+ $DB::single=1;
+ $helper->render_file('auth_admin',
+ $script,
+ { start_perl => $startperl,
+ appprefix => $app_prefix,
+ startperl => $startperl,
+ app_name => app_name(),
+ });
+ chmod 0700, $script;
+}
+
+=head2 BUGS
+
+This is experimental, fairly rough code. It's a proof of concept for
+helper modules for Catalyst that need to alter the application
+configuration, Makefile.PL and other parts of the application. Bug
+reports, and patches are encouraged. Report bugs or provide patches
+to http://rt.cpan.org/NoAuth/Bugs.html?Dist=Catalyst-Helper-AuthDBIC.
+
+=head2 AUTHOR
+
+Kieren Diment <zarquon at cpan.org>
+
+
+=head1 COPYRIGHT AND LICENCE
+
+Copyright (c) 2008 Kieren Diment
+
+This library is free software; you can redistribute it and/or modify it under
+the same terms as Perl itself.
+
+See L<http://www.perl.com/perl/misc/Artistic.html>
+
+=cut
+
+1;
+
+__DATA__
+
+=begin pod_to_ignore
+
+__auth_controller__
+package [% app_name %]::Controller::Auth;
+
+use strict;
+use warnings;
+use base 'Catalyst::Controller';
+
+sub index :Path :Args(0) {
+ my ($self, $c) = @_;
+ $c->detach('get_login');
+}
+
+sub get_login : Local {
+ my ($self, $c) = @_;
+ $c->stash->{destination} = $c->req->path;
+ $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};
+ $c->flash->{destination} = $c->req->params->{destination} || $c->req->path;
+ $c->stash->{remember} = $c->req->params->{remember};
+ if ( $user && $password ) {
+ if ( $c->authenticate( { username => $user,
+ password => $password } ) ) {
+ $c->{session}{expires} = 999999999999 if $c->req->params->{remember};
+ $c->res->redirect($c->uri_for($c->flash->{destination}));
+ }
+ else {
+ # login incorrect
+ $c->stash->{message} = 'Invalid user and/or password';
+ $c->stash->{template} = 'auth/login.tt';
+ }
+ }
+ else {
+ # invalid form input
+ $c->stash->{message} = 'invalid form input';
+ $c->stash->{template} = 'auth/login.tt';
+ }
+}
+
+sub unauthorized : Private {
+ my ($self, $c) = @_;
+ $c->stash->{template}= 'auth/unauth.tt';
+}
+
+1;
+
+=pod
+
+=head1 NAME
+
+[% app_name %]Controller::Auth
+
+=head2 SUMMARY
+
+This is a controller to provide simple authentication provided by
+Catalyst::Helper::AuthDBIC. The database schema provided by the Helper
+will also provide autheorization facilities. As an example, If you
+wanted to use this controller to provide application wide requirement
+for login you would put something like the following in
+MyApp::Controller::Root:
+
+ sub auto : Private {
+ my ( $self, $c) = @_;
+ if ( !$c->user && $c->req->path !~ /^auth.*?login/) {
+ $c->forward('[% app_name %]::Controller::Auth');
+ return 0;
+ }
+ return 1;
+ }
+
+=cut
+
+__auth_conf_http__
+ __PACKAGE__->config( authentication => {
+ 'default_realm' => 'users',
+ 'realms' => {
+ 'users' => {
+ 'store' => {
+ 'role_column' => 'role_text',
+ 'user_class' => '__MYSCHEMA__::User',
+ 'class' => 'DBIx::Class',
+ },
+ 'credential' => {
+ 'password_type' => 'hashed',
+ 'password_field' => 'password',
+ 'password_hash_type' => 'SHA-1',
+ 'class' => 'HTTP',
+ 'type' => 'basic',
+ }
+ }
+ },
+});
+
+
+__auth_conf_password__
+ __PACKAGE__->config( authentication => {
+ 'default_realm' => 'users',
+ 'realms' => {
+ 'users' => {
+ 'store' => {
+ 'role_column' => 'role_text',
+ 'user_class' => '__MYSCHEMA__::User',
+ 'class' => 'DBIx::Class',
+ },
+ 'credential' => {
+ 'password_type' => 'hashed',
+ 'password_field' => 'password',
+ 'password_hash_type' => 'SHA-1',
+ 'class' => 'Password'
+ }
+ }
+ },
+});
+
+__digest__
+
+ __PACKAGE__->add_columns(
+ 'password' => {
+ data_type => 'CHAR',
+ size => 40,
+ encode_column => 1,
+ encode_class => 'Digest',
+ encode_args => {algorithm => 'SHA-1', format => 'hex'},
+ });
+
+__requires__
+requires 'Catalyst::Plugin::Authentication';
+requires 'Catalyst::Plugin::Authorization::Roles';
+requires 'Catalyst::Plugin::Session';
+requires 'Catalyst::Plugin::Session::State::Cookie';
+requires 'Catalyst::Plugin::Session::Store::FastMmap';
+requires 'Catalyst::Authentication::Store::DBIx::Class';
+requires 'Catalyst::Authentication::Credential::HTTP';
+requires 'DBIx::Class::EncodedColumn';
+__login.tt__
+<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>
+
+__logout.tt__
+<h1> Logout successful</h1>
+<a href='[% c.uri_for('/') %]'>Return to home page</a>
+__unauth.tt__
+<h1> [%c.user.id %]: You are not allowed to view this page.</h1>
+You can <a href="[% c.req.referrer %]">go back</a> where you came from, or <a h
+ref="[% c.uri_for('/auth/logout') %]">logout</a> and try logging in again as a d
+ifferent user. If you think this is an error, please contact <a href="mailto:[%
+c.config.admin %]">[% c.config.admin %]</a>
+
+__auth_admin__
+[% startperl %]
+
+use strict;
+use warnings;
+use Pod::Usage;
+use Getopt::Long;
+use FindBin qw/$Bin/;
+use lib "$Bin/../lib";
+
+use [% app_name %]::Auth::Schema;
+
+my $user = undef;
+my $passwd = undef;
+my $help = undef;
+my $role = undef;
+my $email = undef;
+my $schema = [% app_name %]::Auth::Schema->connect("dbi:SQLite:$Bin/../db/auth.db");
+
+GetOptions(
+ 'user=s' => \$user,
+ 'pass|password|passwd=s' => \$passwd,
+ 'role:s' => \$role,
+ 'help' => \$help,
+ 'email:s' => \$email,
+);
+
+pod2usage(1) if ( $help || !$user || !$passwd );
+
+add_user($schema, $user,$passwd,$role, $email);
+
+sub add_user {
+ my ($schema, $user, $passwd, $role, $email ) = @_;
+ my %user_insert = (
+ username => $user,
+ password => $passwd,
+ email => $email,
+ role_text => $role,
+ );
+
+ my $role_rs = undef;
+ if ($role) {
+ $role_rs = $schema->resultset('Role')->find_or_create({role => $role});
+ $user_insert{role_text} = $role;
+ }
+ my $user_rs = $schema->resultset('User')->create(\%user_insert);
+ if ($role_rs) {
+ my $user_role_rs = $schema->resultset('UserRole')
+ ->create({ user => $user_rs,
+ roleid => $role_rs});
+ }
+}
+
+=head1 NAME
+
+[% appprefix %]_auth_admin.pl - Sets the username and password for the generated authentication database
+
+=head1 SYNOPSIS
+
+[% appprefix %]_auth_admin.pl -user username -passwd password [-role role]
+
+ Options:
+ -user username
+ -passwd password
+ -role role (optional)
+ -email email address (optional)
+ -help display this help and exit
+
+=cut
Deleted: Catalyst-Helper-AuthDBIC/tags/0.14/t/02-usage.t
===================================================================
--- Catalyst-Helper-AuthDBIC/trunk/t/02-usage.t 2010-02-20 22:38:50 UTC (rev 12955)
+++ Catalyst-Helper-AuthDBIC/tags/0.14/t/02-usage.t 2010-07-09 00:25:31 UTC (rev 13406)
@@ -1,55 +0,0 @@
-#!/usr/bin/env perl
-
-use strict;
-use warnings;
-use Test::Command qw/no_plan/;
-use Test::More;
-use Directory::Scratch;
-use Path::Class;
-use FindBin qw/$Bin/;
-my $bootstrap = "$Bin/../script/auth_bootstrap.pl";
-
-use ok 'Catalyst::Helper::AuthDBIC';
-
-my $scratch = Directory::Scratch->new();
-my $wdir = Path::Class::Dir->new($scratch);
-
-chdir $wdir;
-exit_is_num ( 'catalyst.pl Test::App', 0 , 'test app');
-ok(chdir 'Test-App');
-exit_is_num ("/usr/bin/env perl $bootstrap -credential http", 0, 'auth bootstrap');
-exit_is_num( "/usr/bin/env perl script/test_app_auth_admin.pl -user fred -password wilma", 0 , "created user");
-
-my $controller = <<'EOF';
-
-package Test::App::Controller::Secret;
-
-use strict;
-use warnings;
-use parent 'Catalyst::Controller';
-
-sub auto : Private {
- my ( $self, $c ) = @_;
- $c->authenticate({realm => 'users'});
-}
-
-sub default : Path {
- my ($self, $c) = @_;
- $c->res->body('ok');
-}
-
-1;
-
-EOF
-
-my $controller_file;
-$controller_file = $wdir->subdir('Test-App')->subdir('lib')->subdir('Test')->subdir('App')->subdir('Controller')->file('Secret.pm');
-
-my $FH;
-
-open $FH, ">", $controller_file;
-print $FH $controller;
-close $FH;
-# stdout_like('$wdir/script/test_app_test.pl /secret', qr/Authorization required/ism, 'auth required');
-chdir "$Bin/.."; # restore dir before pulling rug
-undef $scratch;
Copied: Catalyst-Helper-AuthDBIC/tags/0.14/t/02-usage.t (from rev 12956, Catalyst-Helper-AuthDBIC/trunk/t/02-usage.t)
===================================================================
--- Catalyst-Helper-AuthDBIC/tags/0.14/t/02-usage.t (rev 0)
+++ Catalyst-Helper-AuthDBIC/tags/0.14/t/02-usage.t 2010-07-09 00:25:31 UTC (rev 13406)
@@ -0,0 +1,55 @@
+#!/usr/bin/env perl
+
+use strict;
+use warnings;
+use Test::Command qw/no_plan/;
+use Test::More;
+use Directory::Scratch;
+use Path::Class;
+use FindBin qw/$Bin/;
+my $bootstrap = "$Bin/../script/auth_bootstrap.pl";
+my $catscript = ($^O eq "MSWin32") ? "catalyst" : "catalyst.pl";
+
+use ok 'Catalyst::Helper::AuthDBIC';
+
+my $scratch = Directory::Scratch->new();
+my $wdir = Path::Class::Dir->new($scratch);
+chdir $wdir;
+exit_is_num ( "$catscript Test::App", 0 , 'test app');
+ok(chdir 'Test-App');
+exit_is_num ("$^X $bootstrap -credential http", 0, 'auth bootstrap');
+exit_is_num ("$^X script/test_app_auth_admin.pl -user fred -password wilma", 0 , "created user");
+
+my $controller = <<'EOF';
+
+package Test::App::Controller::Secret;
+
+use strict;
+use warnings;
+use parent 'Catalyst::Controller';
+
+sub auto : Private {
+ my ( $self, $c ) = @_;
+ $c->authenticate({realm => 'users'});
+}
+
+sub default : Path {
+ my ($self, $c) = @_;
+ $c->res->body('ok');
+}
+
+1;
+
+EOF
+
+my $controller_file;
+$controller_file = $wdir->subdir('Test-App')->subdir('lib')->subdir('Test')->subdir('App')->subdir('Controller')->file('Secret.pm');
+
+my $FH;
+
+open $FH, ">", $controller_file;
+print $FH $controller;
+close $FH;
+# stdout_like('$wdir/script/test_app_test.pl /secret', qr/Authorization required/ism, 'auth required');
+chdir "$Bin/.."; # restore dir before pulling rug
+undef $scratch;
Deleted: Catalyst-Helper-AuthDBIC/tags/0.14/t/live-test.t
===================================================================
--- Catalyst-Helper-AuthDBIC/trunk/t/live-test.t 2010-02-20 22:38:50 UTC (rev 12955)
+++ Catalyst-Helper-AuthDBIC/tags/0.14/t/live-test.t 2010-07-09 00:25:31 UTC (rev 13406)
@@ -1,26 +0,0 @@
-#!/usr/bin/env perl
-
-use strict;
-use warnings;
-use Test::More;
-
-BEGIN {
- eval { require Test::WWW::Mechanize::Catalyst }
- or plan skip_all => 'Need Test::WWW::Mechanize::Catalyst to run this test';
-}
-
-plan tests => 3;
-
-# setup library path
-use FindBin qw($Bin);
-use lib "$Bin/lib";
-
-# make sure testapp works
-use ok 'TestApp';
-
-# a live test against TestApp, the test application
-use Test::WWW::Mechanize::Catalyst 'TestApp';
-my $mech = Test::WWW::Mechanize::Catalyst->new;
-$mech->get_ok('http://localhost/', 'get main page');
-$mech->content_like(qr/it works/i, 'see if it has our text');
-
Copied: Catalyst-Helper-AuthDBIC/tags/0.14/t/live-test.t (from rev 12956, Catalyst-Helper-AuthDBIC/trunk/t/live-test.t)
===================================================================
--- Catalyst-Helper-AuthDBIC/tags/0.14/t/live-test.t (rev 0)
+++ Catalyst-Helper-AuthDBIC/tags/0.14/t/live-test.t 2010-07-09 00:25:31 UTC (rev 13406)
@@ -0,0 +1,24 @@
+#!/usr/bin/env perl
+
+use strict;
+use warnings;
+use Test::More tests => 3;
+
+BEGIN {
+ eval { require Test::WWW::Mechanize::Catalyst }
+ or plan skip_all => 'Need Test::WWW::Mechanize::Catalyst to run this test';
+}
+
+# setup library path
+use FindBin qw($Bin);
+use lib "$Bin/lib";
+
+# make sure testapp works
+use ok 'TestApp';
+
+# a live test against TestApp, the test application
+use Test::WWW::Mechanize::Catalyst 'TestApp';
+my $mech = Test::WWW::Mechanize::Catalyst->new;
+$mech->get_ok('http://localhost/', 'get main page');
+$mech->content_like(qr/it works/i, 'see if it has our text');
+
More information about the Catalyst-commits
mailing list