Initial user admin page

This commit is contained in:
Tom Bloor 2017-04-18 10:44:07 +01:00
parent 36e8cfe1d0
commit 1466ea84eb
3 changed files with 60 additions and 0 deletions

View file

@ -110,6 +110,11 @@ sub startup {
$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');
$admin_routes->get('/users')->to('admin-users#index');
$admin_routes->post('/users')->to('admin-users#create');
$admin_routes->get('/users/:id')->to('admin-users#read');
$admin_routes->post('/users/:id')->to('admin-users#update');
$admin_routes->post('/users/:id/delete')->to('admin-users#delete');
my $user_routes = $r->under('/')->to('root#under');

View file

@ -0,0 +1,33 @@
package Pear::LocalLoop::Controller::Admin::Users;
use Mojo::Base 'Mojolicious::Controller';
has result_set => sub {
my $c = shift;
return $c->schema->resultset('User');
};
sub index {
my $c = shift;
my $user_rs = $c->result_set;
$user_rs->result_class('DBIx::Class::ResultClass::HashRefInflator');
$c->stash( users => [ $user_rs->all ] );
}
sub create {
my $c = shift;
}
sub read {
my $c = shift;
}
sub update {
my $c = shift;
}
sub delete {
my $c = shift;
}
1;

View file

@ -0,0 +1,22 @@
% layout 'admin';
% title 'Users';
% content_for javascript => begin
% end
% 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="list-group">
% for my $user (@$users) {
<a href="<%= url_for . '/' . $user->{userid} %>" class="list-group-item list-group-item-action">
<div>
%= $user->{email}
</div>
</a>
% }
</div>