2017-04-06 22:12:28 +00:00
|
|
|
package Pear::LocalLoop::Controller::Admin;
|
|
|
|
use Mojo::Base 'Mojolicious::Controller';
|
|
|
|
|
|
|
|
sub under {
|
|
|
|
my $c = shift;
|
|
|
|
|
|
|
|
if ( $c->is_user_authenticated ) {
|
2017-08-31 12:35:49 +00:00
|
|
|
return 1 if $c->current_user->is_admin;
|
2017-04-06 23:33:50 +00:00
|
|
|
}
|
2017-09-29 13:45:44 +00:00
|
|
|
$c->redirect_to('/admin');
|
2017-08-31 12:35:49 +00:00
|
|
|
return 0;
|
2017-04-06 23:33:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
sub home {
|
|
|
|
my $c = shift;
|
2017-04-18 09:43:23 +00:00
|
|
|
|
|
|
|
my $user_rs = $c->schema->resultset('User');
|
|
|
|
my $token_rs = $c->schema->resultset('AccountToken');
|
2017-08-31 12:35:49 +00:00
|
|
|
my $pending_orgs_rs = $c->schema->resultset('Organisation')->search({ pending => 1 });
|
|
|
|
my $pending_transaction_rs = $pending_orgs_rs->entity->sales;
|
2017-10-23 15:09:20 +00:00
|
|
|
my $feedback_rs = $c->schema->resultset('Feedback');
|
|
|
|
my $pending_feedback_rs = $feedback_rs->search({ actioned => 0 });
|
2017-04-18 09:43:23 +00:00
|
|
|
$c->stash(
|
|
|
|
user_count => $user_rs->count,
|
|
|
|
tokens => {
|
|
|
|
total => $token_rs->count,
|
2017-04-20 21:16:44 +00:00
|
|
|
unused => $token_rs->search({ used => 0 })->count,
|
2017-04-18 09:43:23 +00:00
|
|
|
},
|
2017-04-20 21:16:44 +00:00
|
|
|
pending_orgs => $pending_orgs_rs->count,
|
|
|
|
pending_trans => $pending_transaction_rs->count,
|
2017-10-23 15:09:20 +00:00
|
|
|
feedback => {
|
|
|
|
total => $feedback_rs->count,
|
|
|
|
pending => $pending_feedback_rs->count,
|
|
|
|
},
|
2017-04-18 09:43:23 +00:00
|
|
|
);
|
2017-04-06 23:33:50 +00:00
|
|
|
}
|
|
|
|
|
2017-04-24 16:42:07 +00:00
|
|
|
sub auth_login {
|
|
|
|
my $c = shift;
|
|
|
|
|
2017-11-21 10:42:23 +00:00
|
|
|
$c->app->log->debug( __PACKAGE__ . " admin login attempt for [" . $c->param('email') . "]" );
|
|
|
|
|
2017-04-24 16:42:07 +00:00
|
|
|
if ( $c->authenticate($c->param('email'), $c->param('password')) ) {
|
|
|
|
$c->redirect_to('/admin/home');
|
|
|
|
} else {
|
2017-11-21 10:42:23 +00:00
|
|
|
$c->app->log->info( __PACKAGE__ . " failed admin login for [" . $c->param('email') . "]" );
|
2017-04-24 16:42:07 +00:00
|
|
|
$c->redirect_to('/admin');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
sub auth_logout {
|
|
|
|
my $c = shift;
|
|
|
|
|
|
|
|
$c->logout;
|
|
|
|
$c->redirect_to('/admin');
|
|
|
|
}
|
|
|
|
|
2017-04-06 22:12:28 +00:00
|
|
|
1;
|