From: Jess Robinson Date: Fri, 4 May 2012 10:17:27 +0000 (+0000) Subject: Basic usable login-auth using KiokuDB X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=scpubgit%2Fstemmatology.git;a=commitdiff_plain;h=d1ba091f9e2db1d9f927b319be798f2d865f8acc Basic usable login-auth using KiokuDB --- diff --git a/lib/Text/Tradition/UserStore.pm b/lib/Text/Tradition/UserStore.pm index 6a10e88..4475986 100644 --- a/lib/Text/Tradition/UserStore.pm +++ b/lib/Text/Tradition/UserStore.pm @@ -6,10 +6,15 @@ use warnings; use Moose; use KiokuX::User::Util qw(crypt_password); +extends 'KiokuX::Model'; + use Text::Tradition::User; -use Text::Tradition::Directory; -has 'directory' => ( is => 'rw', isa => 'KiokuX::Model'); +# has 'directory' => ( +# is => 'rw', +# isa => 'KiokuX::Model', +# handles => [] +# ); sub add_user { my ($self, $username, $password) = @_; @@ -19,16 +24,17 @@ sub add_user { password => crypt_password($password), ); - my $scope = $self->directory->new_scope; - $self->directory->store($user->kiokudb_object_id, $user); + my $scope = $self->new_scope; + $self->store($user->kiokudb_object_id, $user); return $user; } sub find_user { - my ($self, $username) = @_; + my ($self, $userinfo) = @_; + my $username = $userinfo->{username}; - return $self->directory->lookup($self->user_prefix . $username); + return $self->lookup(Text::Tradition::User->id_for_user($username)); } diff --git a/stemmaweb/Makefile.PL b/stemmaweb/Makefile.PL index a31e6ed..e42015a 100644 --- a/stemmaweb/Makefile.PL +++ b/stemmaweb/Makefile.PL @@ -18,6 +18,13 @@ requires 'Catalyst::Model::KiokuDB'; requires 'Catalyst::View::Download::Plain'; requires 'Catalyst::View::JSON'; requires 'Catalyst::View::TT'; +## Auth: +requires 'Catalyst::Plugin::Authentication'; +requires 'Catalyst::Plugin::Session'; +requires 'Catalyst::Plugin::Session::Store::File'; +requires 'Catalyst::Plugin::Session::State::Cookie'; +requires 'CatalystX::SimpleLogin'; +## requires 'Moose'; requires 'TryCatch'; requires 'namespace::autoclean'; diff --git a/stemmaweb/lib/stemmaweb.pm b/stemmaweb/lib/stemmaweb.pm index 94121c1..b2f68e8 100644 --- a/stemmaweb/lib/stemmaweb.pm +++ b/stemmaweb/lib/stemmaweb.pm @@ -4,6 +4,10 @@ use namespace::autoclean; use Catalyst::Runtime 5.80; +use Search::GIN::Extract::Class; +use Search::GIN::Extract::Attributes; +use Search::GIN::Extract::Multiplex; + # Set flags and add plugins for the application. # # Note that ORDERING IS IMPORTANT here as plugins are initialized in order, @@ -20,6 +24,11 @@ use Catalyst qw/ ConfigLoader Static::Simple Unicode::Encoding + +CatalystX::SimpleLogin + Authentication + Session + Session::Store::File + Session::State::Cookie /; extends 'Catalyst'; @@ -48,6 +57,20 @@ __PACKAGE__->config( stemmaweb->path_to( 'root', 'src' ), ], }, + ## kiokudb auth store testing + 'Plugin::Authentication' => { + default => { + credential => { + class => 'Password', + password_field => 'password', + password_type => 'self_check', + }, + store => { + class => 'Model::KiokuDB', + model_name => 'User', + }, + } + }, ); # Start the application diff --git a/stemmaweb/lib/stemmaweb/Model/User.pm b/stemmaweb/lib/stemmaweb/Model/User.pm new file mode 100644 index 0000000..d8f8c91 --- /dev/null +++ b/stemmaweb/lib/stemmaweb/Model/User.pm @@ -0,0 +1,11 @@ +package stemmaweb::Model::User; +use strict; +use warnings; +use Moose; +use Text::Tradition::UserStore; + +extends 'Catalyst::Model::KiokuDB'; + +has '+model_class' => ( default => 'Text::Tradition::UserStore' ); + +1; diff --git a/stemmaweb/stemmaweb.conf b/stemmaweb/stemmaweb.conf index a64ce1e..a0169dc 100644 --- a/stemmaweb/stemmaweb.conf +++ b/stemmaweb/stemmaweb.conf @@ -3,4 +3,7 @@ name = stemmaweb dsn dbi:SQLite:dbname=db/traditions.db - \ No newline at end of file + + + dsn dbi:SQLite:dbname=db/traditions.db + diff --git a/t/text_tradition_user.t b/t/text_tradition_user.t index d1e15ae..fc06fe0 100644 --- a/t/text_tradition_user.t +++ b/t/text_tradition_user.t @@ -4,7 +4,7 @@ use strict; use warnings; use Test::More 'no_plan'; -use KiokuX::Model; +# use KiokuX::Model; use File::Temp; use_ok('Text::Tradition::UserStore'); @@ -13,10 +13,18 @@ my $fh = File::Temp->new(); my $file = $fh->filename; $fh->close; my $dsn = "dbi:SQLite:dbname=$file"; -my $d = KiokuX::Model->new( 'dsn' => $dsn,'extra_args' => { 'create' => 1 } ); +# my $d = KiokuX::Model->new( 'dsn' => $dsn,'extra_args' => { 'create' => 1 } ); -my $user_store = Text::Tradition::UserStore->new(directory => $d); +my $user_store = Text::Tradition::UserStore->new('dsn' => $dsn,'extra_args' => { 'create' => 1 } ); +## create user my $new_user = $user_store->add_user('fred', 'bloggs'); isa_ok($new_user, 'Text::Tradition::User'); +## find user +my $find_user = $user_store->find_user({ username => 'fred'}); +isa_ok($find_user, 'Text::Tradition::User'); +ok($find_user->check_password('bloggs'), 'Stored & retrieved with correct password'); + + +