Move to single login page instead of seperate admin login

This commit is contained in:
Tom Bloor 2017-04-08 14:25:06 +01:00
parent a78de6ea8e
commit 30c80679be
9 changed files with 143 additions and 131 deletions

View file

@ -48,10 +48,9 @@ sub startup {
my $r = $self->routes;
$r->any('/')->to('root#index');
$r->get('/')->to('root#index');
$r->post('/')->to('root#auth_login');
$r->any('/logout')->to('root#auth_logout');
$r->get('/admin')->to('admin#index');
$r->post('/admin')->to('admin#login');
my $api = $r->under('/api' => sub {
my $c = shift;
@ -101,13 +100,17 @@ sub startup {
my $admin_routes = $r->under('/admin')->to('admin#under');
$admin_routes->get('/home')->to('admin#home');
$admin_routes->get('/')->to('admin#home');
$admin_routes->get('/tokens')->to('admin-tokens#index');
$admin_routes->post('/tokens')->to('admin-tokens#create');
$admin_routes->get('/tokens/:id')->to('admin-tokens#read');
$admin_routes->post('/tokens/:id')->to('admin-tokens#update');
$admin_routes->post('/tokens/:id/delete')->to('admin-tokens#delete');
my $user_routes = $r->under('/')->to('root#under');
$user_routes->get('/home')->to('root#home');
$self->hook( before_dispatch => sub {
my $self = shift;

View file

@ -1,28 +1,16 @@
package Pear::LocalLoop::Controller::Admin;
use Mojo::Base 'Mojolicious::Controller';
sub index {
my $c = shift;
}
sub under {
my $c = shift;
if ( $c->is_user_authenticated ) {
return 1 if defined $c->current_user->administrator;
}
$c->redirect_to('/');
return undef;
}
sub login {
my $c = shift;
if ( $c->authenticate($c->param('email'), $c->param('password')) ) {
$c->redirect_to('/admin/home');
$c->redirect_to('/home');
} else {
$c->redirect_to('/admin');
$c->redirect_to('/');
}
return undef;
}
sub home {

View file

@ -3,7 +3,26 @@ use Mojo::Base 'Mojolicious::Controller';
sub index {
my $c = shift;
}
sub under {
my $c = shift;
if ( $c->is_user_authenticated ) {
return 1;
}
$c->redirect_to('/');
return undef;
}
sub auth_login {
my $c = shift;
if ( $c->authenticate($c->param('email'), $c->param('password')) ) {
$c->redirect_to('/home');
} else {
$c->redirect_to('/');
}
}
sub auth_logout {
@ -13,5 +32,9 @@ sub auth_logout {
$c->redirect_to('/');
}
sub home {
my $c = shift;
$c->render(text => 'Root Home');
}
1;