diff --git a/lib/Pear/LocalLoop.pm b/lib/Pear/LocalLoop.pm index 196d3e5..c594357 100644 --- a/lib/Pear/LocalLoop.pm +++ b/lib/Pear/LocalLoop.pm @@ -49,7 +49,8 @@ sub startup { my $r = $self->routes; $r->any('/')->to('root#index'); - $r->any('/admin')->to('admin#index'); + $r->get('/admin')->to('admin#index'); + $r->post('/admin')->to('admin#login'); my $api = $r->under('/api' => sub { my $c = shift; @@ -99,6 +100,8 @@ sub startup { my $admin_routes = $r->under('/admin')->to('admin#under'); + $admin_routes->get('/home')->to('admin#home'); + $self->hook( before_dispatch => sub { my $self = shift; @@ -324,6 +327,7 @@ $self->helper(expire_current_session => sub { $self->helper(check_password_email => sub { my ( $c, $email, $password ) = @_; my $user = $c->schema->resultset('User')->find({ email => $email }); + return undef unless defined $user; my $ppr = Authen::Passphrase::BlowfishCrypt->from_crypt($user->hashedpassword); return $ppr->match($password); }); diff --git a/lib/Pear/LocalLoop/Controller/Admin.pm b/lib/Pear/LocalLoop/Controller/Admin.pm index c79a44f..4747677 100644 --- a/lib/Pear/LocalLoop/Controller/Admin.pm +++ b/lib/Pear/LocalLoop/Controller/Admin.pm @@ -15,4 +15,18 @@ sub under { return undef; } +sub login { + my $c = shift; + + if ( $c->authenticate($c->param('email'), $c->param('password')) ) { + $c->redirect_to('/admin/home'); + } else { + $c->redirect_to('/admin'); + } +} + +sub home { + my $c = shift; +} + 1; diff --git a/templates/admin/home.html.ep b/templates/admin/home.html.ep new file mode 100644 index 0000000..0dd6a5a --- /dev/null +++ b/templates/admin/home.html.ep @@ -0,0 +1,28 @@ +% layout 'default'; +% title 'LocalLoop Admin - Login'; +% content_for css => begin + +% end +% content_for javascript => begin +% end + +