Added initial admin login page and backend page with authentication

This commit is contained in:
Tom Bloor 2017-04-07 00:33:50 +01:00
parent 998259f0ae
commit 61d609861a
5 changed files with 116 additions and 1 deletions

View file

@ -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);
});

View file

@ -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;