diff --git a/lib/Lrrr/Authentication.pm b/lib/Lrrr/Authentication.pm index cf4345a..46e4c26 100644 --- a/lib/Lrrr/Authentication.pm +++ b/lib/Lrrr/Authentication.pm @@ -3,11 +3,7 @@ package Lrrr::Authentication; sub load_user { my ($class, $app, $username) = @_; - #return 1; - #my $self = shift; - #my $username = shift; - - my $collection = $app->mango->db('test')->collection('users'); + my $collection = $app->mango->db->collection('users'); my $user = $collection->find_one( {username => $username} ); return { @@ -19,16 +15,10 @@ sub load_user { sub validate_user { my ($class, $app, $username, $password, $extas) = @_; - #return 1; - #my $self = shift; - #my $username = shift || ''; - #my $password = shift || ''; - #my $extradata = shift || {}; - - my $collection = $app->mango->db('test')->collection('users'); + my $collection = $app->mango->db->collection('users'); my $user = $collection->find_one( {username => $username} ); - return $user->{username} if ( $password eq $user->{password} ); + return $user->{username} if ( defined $user->{username} && defined $user->{password} && $password eq $user->{password} ); return undef; } diff --git a/t/mango.t b/t/mango.t new file mode 100644 index 0000000..d93f8f7 --- /dev/null +++ b/t/mango.t @@ -0,0 +1,26 @@ +use Mojo::Base -strict; + +use Test::More; +use Test::Mojo; + +#plan skip_all => 'set TEST_ONLINE to enable this test' +# unless $ENV{TEST_ONLINE}; + +use Mango; + +my $t = Test::Mojo->new('Lrrr'); + +# Clean up before start +my $collection = $t->app->mango->db->collection('users'); +$collection->drop if $collection->options; +#$collection->create; + +# insert user and pass +$collection->insert({username => 'bender', password => 'rodriguez'}); +# test login, hidden +$t->post_ok('/login' => form => { u => 'bender', p => 'rodriguez' })->status_is(200)->content_like(qr/ok/i); + +# Cleanup at end +$collection->drop; + +done_testing();