Did test and routing fixes and dependency fix
This commit is contained in:
parent
2acee95d86
commit
a4ce60407e
12 changed files with 116 additions and 116 deletions
2
cpanfile
2
cpanfile
|
@ -14,5 +14,5 @@ requires 'DBIx::Class::TimeStamp';
|
|||
requires 'DBIx::Class::Schema::Loader';
|
||||
requires 'SQL::Translator';
|
||||
requires 'DateTime';
|
||||
requires 'DateTime::Format::Strptime';
|
||||
requires 'DateTime::Format::Strptime', "1.73";
|
||||
requires 'DateTime::Format::SQLite';
|
||||
|
|
|
@ -104,10 +104,11 @@ sub startup {
|
|||
|
||||
my $r = $self->routes;
|
||||
$r->get('/')->to('root#index');
|
||||
$r->post('/')->to('root#auth_login');
|
||||
$r->get('/register')->to('register#index');
|
||||
$r->post('/register')->to('register#register');
|
||||
$r->any('/logout')->to('root#auth_logout');
|
||||
$r->get('/admin')->to('admin#index');
|
||||
$r->post('/admin')->to('admin#auth_login');
|
||||
# $r->get('/register')->to('register#index');
|
||||
# $r->post('/register')->to('register#register');
|
||||
$r->any('/admin/logout')->to('admin#auth_logout');
|
||||
|
||||
my $api_public_get = $r->under('/api');
|
||||
$api_public_get->get('/info/ages')->to('api-info#get_ages');
|
||||
|
@ -142,7 +143,7 @@ sub startup {
|
|||
|
||||
my $admin_routes = $r->under('/admin')->to('admin#under');
|
||||
|
||||
$admin_routes->get('/')->to('admin#home');
|
||||
$admin_routes->get('/home')->to('admin#home');
|
||||
|
||||
$admin_routes->get('/tokens')->to('admin-tokens#index');
|
||||
$admin_routes->post('/tokens')->to('admin-tokens#create');
|
||||
|
@ -160,14 +161,14 @@ sub startup {
|
|||
$admin_routes->get('/organisations/pending/:id')->to('admin-organisations#pending_read');
|
||||
$admin_routes->get('/organisations/pending/:id/approve')->to('admin-organisations#pending_approve');
|
||||
|
||||
my $user_routes = $r->under('/')->to('root#under');
|
||||
# my $user_routes = $r->under('/')->to('root#under');
|
||||
|
||||
$user_routes->get('/home')->to('root#home');
|
||||
# $user_routes->get('/home')->to('root#home');
|
||||
|
||||
my $portal_api = $r->under('/portal')->to('api-auth#check_json')->under('/')->to('portal#under');
|
||||
# my $portal_api = $r->under('/portal')->to('api-auth#check_json')->under('/')->to('portal#under');
|
||||
|
||||
$portal_api->post('/upload')->to('api-upload#post_upload');
|
||||
$portal_api->post('/search')->to('api-upload#post_search');
|
||||
# $portal_api->post('/upload')->to('api-upload#post_upload');
|
||||
# $portal_api->post('/search')->to('api-upload#post_search');
|
||||
|
||||
$self->hook( before_dispatch => sub {
|
||||
my $self = shift;
|
||||
|
|
|
@ -6,10 +6,8 @@ sub under {
|
|||
|
||||
if ( $c->is_user_authenticated ) {
|
||||
return 1 if defined $c->current_user->administrator;
|
||||
$c->redirect_to('/home');
|
||||
} else {
|
||||
$c->redirect_to('/');
|
||||
}
|
||||
$c->redirect_to('/');
|
||||
return undef;
|
||||
}
|
||||
|
||||
|
@ -31,4 +29,21 @@ sub home {
|
|||
);
|
||||
}
|
||||
|
||||
sub auth_login {
|
||||
my $c = shift;
|
||||
|
||||
if ( $c->authenticate($c->param('email'), $c->param('password')) ) {
|
||||
$c->redirect_to('/admin/home');
|
||||
} else {
|
||||
$c->redirect_to('/admin');
|
||||
}
|
||||
}
|
||||
|
||||
sub auth_logout {
|
||||
my $c = shift;
|
||||
|
||||
$c->logout;
|
||||
$c->redirect_to('/admin');
|
||||
}
|
||||
|
||||
1;
|
||||
|
|
|
@ -4,9 +4,9 @@ use Mojo::Base 'Mojolicious::Controller';
|
|||
sub index {
|
||||
my $c = shift;
|
||||
|
||||
if ( $c->is_user_authenticated ) {
|
||||
$c->redirect_to('/home');
|
||||
}
|
||||
# if ( $c->is_user_authenticated ) {
|
||||
# $c->redirect_to('/home');
|
||||
# }
|
||||
}
|
||||
|
||||
sub under {
|
||||
|
|
|
@ -21,7 +21,7 @@ $schema->resultset('AgeRange')->populate([
|
|||
[ '50+' ],
|
||||
]);
|
||||
|
||||
if ( $ENV{MOJO_MODE} eq 'development' ) {
|
||||
if (defined $ENV{MOJO_MODE} && $ENV{MOJO_MODE} eq 'development' ) {
|
||||
|
||||
$schema->resultset('User')->create({
|
||||
email => 'test@example.com',
|
||||
|
|
|
@ -1,29 +1,12 @@
|
|||
use strict;
|
||||
use warnings;
|
||||
use Mojo::Base -strict;
|
||||
|
||||
use FindBin qw/ $Bin /;
|
||||
use lib "$Bin/../../lib";
|
||||
|
||||
use File::Temp;
|
||||
use Test::More;
|
||||
use Test::Mojo;
|
||||
use DateTime;
|
||||
my $file = File::Temp->new;
|
||||
use Mojo::JSON;
|
||||
use Test::Pear::LocalLoop;
|
||||
|
||||
print $file <<'END';
|
||||
{
|
||||
dsn => "dbi:SQLite::memory:",
|
||||
user => undef,
|
||||
pass => undef,
|
||||
}
|
||||
END
|
||||
$file->seek( 0, SEEK_END );
|
||||
|
||||
$ENV{MOJO_CONFIG} = $file->filename;
|
||||
|
||||
my $t = Test::Mojo->new('Pear::LocalLoop');
|
||||
my $framework = Test::Pear::LocalLoop->new;
|
||||
my $t = $framework->framework;
|
||||
my $schema = $t->app->schema;
|
||||
$schema->deploy;
|
||||
|
||||
$schema->resultset('User')->create({
|
||||
email => 'admin@example.com',
|
||||
|
@ -47,46 +30,42 @@ my $location_is = sub {
|
|||
};
|
||||
|
||||
$t->get_ok('/admin')
|
||||
->status_is(302)
|
||||
->$location_is('/');
|
||||
->status_is(200)->or($framework->dump_error);
|
||||
|
||||
$t->ua->max_redirects(10);
|
||||
$t->post_ok('/', form => {
|
||||
$t->post_ok('/admin', form => {
|
||||
email => 'user@example.com',
|
||||
password => 'abc123',
|
||||
})->status_is(200);
|
||||
|
||||
$t->ua->max_redirects(0);
|
||||
$t->get_ok('/admin')
|
||||
->status_is(302)
|
||||
->$location_is('/home');
|
||||
->status_is(200);
|
||||
|
||||
$t->get_ok('/logout')
|
||||
$t->get_ok('/admin/logout')
|
||||
->status_is(302)
|
||||
->$location_is('/');
|
||||
->$location_is('/admin');
|
||||
|
||||
$t->get_ok('/admin')
|
||||
->status_is(302)
|
||||
->$location_is('/', 'Logged out');
|
||||
->status_is(200);
|
||||
|
||||
$t->ua->max_redirects(10);
|
||||
$t->post_ok('/', form => {
|
||||
$t->post_ok('/admin', form => {
|
||||
email => 'admin@example.com',
|
||||
password => 'abc123',
|
||||
})->status_is(200);
|
||||
|
||||
$t->ua->max_redirects(0);
|
||||
$t->get_ok('/admin')
|
||||
$t->get_ok('/admin/home')
|
||||
->status_is(200)
|
||||
->content_like(qr/Admin/);
|
||||
|
||||
$t->get_ok('/logout')
|
||||
$t->get_ok('/admin/logout')
|
||||
->status_is(302)
|
||||
->$location_is('/');
|
||||
->$location_is('/admin');
|
||||
|
||||
$t->get_ok('/admin')
|
||||
->status_is(302)
|
||||
->$location_is('/', 'Logged out');
|
||||
->status_is(200);
|
||||
|
||||
done_testing;
|
||||
|
||||
|
|
|
@ -10,6 +10,6 @@ BEGIN {
|
|||
}
|
||||
|
||||
my $t = Test::Mojo->new("Pear::LocalLoop");
|
||||
$t->get_ok('/')->status_is(200)->content_like(qr/login/i);
|
||||
$t->get_ok('/')->status_is(200);
|
||||
|
||||
done_testing();
|
||||
|
|
|
@ -38,7 +38,7 @@ my $testJson = {
|
|||
'age_range' => 1
|
||||
};
|
||||
$t->post_ok('/api/register' => json => $testJson)
|
||||
->status_is(200)->or($dump_error)
|
||||
->status_is(200)->or($framework->dump_error)
|
||||
->json_is('/success', Mojo::JSON->true);
|
||||
|
||||
#test with an organisation.
|
||||
|
|
55
templates/admin/index.html.ep
Normal file
55
templates/admin/index.html.ep
Normal file
|
@ -0,0 +1,55 @@
|
|||
% layout 'default';
|
||||
% title 'Login';
|
||||
% content_for css => begin
|
||||
<style>
|
||||
body {
|
||||
background: whitesmoke;
|
||||
padding-top: 54px;
|
||||
}
|
||||
|
||||
.panel {
|
||||
background: white;
|
||||
padding: 16px;
|
||||
-webkit-box-shadow: 0px 2px 4px 0px rgba(0,0,0,0.2);
|
||||
-moz-box-shadow: 0px 2px 4px 0px rgba(0,0,0,0.2);
|
||||
box-shadow: 0px 2px 4px 0px rgba(0,0,0,0.2);
|
||||
}
|
||||
|
||||
.login-form {
|
||||
margin-top: 20%;
|
||||
}
|
||||
</style>
|
||||
% end
|
||||
% content_for javascript => begin
|
||||
% end
|
||||
<div class="container">
|
||||
% if ( my $error = flash 'error' ) {
|
||||
<div class="alert alert-danger" role="alert">
|
||||
<strong>Error!</strong> <%= $error %>
|
||||
</div>
|
||||
% } elsif ( my $success = flash 'success' ) {
|
||||
<div class="alert alert-success" role="alert">
|
||||
<strong>Success!</strong> <%= $success %>
|
||||
</div>
|
||||
% }
|
||||
<div class="row justify-content-center">
|
||||
<!-- Fluid Gird, this login box stay in the middle of screen -->
|
||||
<div class="col-5">
|
||||
|
||||
<div class="login-form panel">
|
||||
<form action="<%= url_for %>" method="post">
|
||||
<div class="form-group">
|
||||
<label for="login-email">Email Address</label>
|
||||
<input type="email" id="login-email" class="form-control" name="email" required>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="login-password">Password</label>
|
||||
<input type="password" id="login-password" class="form-control" name="password" required>
|
||||
</div>
|
||||
<input type="submit" class="btn btn-block btn-primary" value="Sign In">
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div><!-- Container fluid-->
|
||||
|
|
@ -25,14 +25,14 @@
|
|||
<span class="navbar-toggler-icon"></span>
|
||||
</button>
|
||||
|
||||
<a class="navbar-brand" href="<%= url_for '/admin' %>">LocalLoop Admin</a>
|
||||
<a class="navbar-brand" href="<%= url_for '/admin/home' %>">LocalLoop Admin</a>
|
||||
<div class="collapse navbar-collapse" id="navbarNav">
|
||||
<div class="navbar-nav ml-auto">
|
||||
<a class="nav-item nav-link" href="<%= url_for '/home' %>">User Section</a>
|
||||
<a class="nav-item nav-link" href="<%= url_for '/' %>">User Section</a>
|
||||
<a class="nav-item nav-link<%= title eq 'Tokens' ? ' active' : '' %>" href="<%= url_for '/admin/tokens' %>">Tokens</a>
|
||||
<a class="nav-item nav-link<%= title eq 'Users' ? ' active' : '' %>" href="<%= url_for '/admin/users' %>">Users</a>
|
||||
<a class="nav-item nav-link<%= title eq 'Organisations' ? ' active' : '' %>" href="<%= url_for '/admin/organisations' %>">Organisations</a>
|
||||
<a class="nav-item nav-link" href="<%= url_for '/logout' %>">Logout</a>
|
||||
<a class="nav-item nav-link" href="<%= url_for '/admin/logout' %>">Logout</a>
|
||||
</div>
|
||||
</div>
|
||||
</nav>
|
||||
|
|
|
@ -28,9 +28,6 @@
|
|||
<a class="navbar-brand" href="<%= url_for '/home' %>">LocalLoop</a>
|
||||
<div class="collapse navbar-collapse" id="navbarNav">
|
||||
<div class="navbar-nav ml-auto">
|
||||
% if ( defined $c->current_user->administrator ) {
|
||||
<a class="nav-item nav-link" href="<%= url_for '/admin' %>">Admin Section</a>
|
||||
% }
|
||||
<a class="nav-item nav-link<%= title eq 'Receipts' ? ' active' : '' %>" href="#">Receipts</a>
|
||||
<a class="nav-item nav-link<%= title eq 'Settings' ? ' active' : '' %>" href="#">Settings</a>
|
||||
<a class="nav-item nav-link" href="<%= url_for '/logout' %>">Logout</a>
|
||||
|
|
|
@ -1,55 +1,8 @@
|
|||
% layout 'default';
|
||||
% title 'Login';
|
||||
% content_for css => begin
|
||||
<style>
|
||||
body {
|
||||
background: whitesmoke;
|
||||
padding-top: 54px;
|
||||
}
|
||||
|
||||
.panel {
|
||||
background: white;
|
||||
padding: 16px;
|
||||
-webkit-box-shadow: 0px 2px 4px 0px rgba(0,0,0,0.2);
|
||||
-moz-box-shadow: 0px 2px 4px 0px rgba(0,0,0,0.2);
|
||||
box-shadow: 0px 2px 4px 0px rgba(0,0,0,0.2);
|
||||
}
|
||||
|
||||
.login-form {
|
||||
margin-top: 20%;
|
||||
}
|
||||
</style>
|
||||
% end
|
||||
% layout 'user';
|
||||
% title 'Home';
|
||||
% content_for javascript => begin
|
||||
%= javascript '/static/user/js/home.js';
|
||||
% end
|
||||
<div class="container">
|
||||
% if ( my $error = flash 'error' ) {
|
||||
<div class="alert alert-danger" role="alert">
|
||||
<strong>Error!</strong> <%= $error %>
|
||||
</div>
|
||||
% } elsif ( my $success = flash 'success' ) {
|
||||
<div class="alert alert-success" role="alert">
|
||||
<strong>Success!</strong> <%= $success %>
|
||||
</div>
|
||||
% }
|
||||
<div class="row justify-content-center">
|
||||
<!-- Fluid Gird, this login box stay in the middle of screen -->
|
||||
<div class="col-5">
|
||||
|
||||
<div class="login-form panel">
|
||||
<form action="<%= url_for %>" method="post">
|
||||
<div class="form-group">
|
||||
<label for="login-email">Email Address</label>
|
||||
<input type="email" id="login-email" class="form-control" name="email" required>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="login-password">Password</label>
|
||||
<input type="password" id="login-password" class="form-control" name="password" required>
|
||||
</div>
|
||||
<input type="submit" class="btn btn-block btn-primary" value="Sign In">
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div><!-- Container fluid-->
|
||||
|
||||
<div class="card">
|
||||
<h3 class="card-header">User Home</h3>
|
||||
</div>
|
||||
|
|
Reference in a new issue