From 1466ea84eb85eb1b88daa316a01ecfd8cd0408ee Mon Sep 17 00:00:00 2001 From: Tom Bloor Date: Tue, 18 Apr 2017 10:44:07 +0100 Subject: [PATCH] Initial user admin page --- lib/Pear/LocalLoop.pm | 5 +++ lib/Pear/LocalLoop/Controller/Admin/Users.pm | 33 ++++++++++++++++++++ templates/admin/users/index.html.ep | 22 +++++++++++++ 3 files changed, 60 insertions(+) create mode 100644 lib/Pear/LocalLoop/Controller/Admin/Users.pm create mode 100644 templates/admin/users/index.html.ep diff --git a/lib/Pear/LocalLoop.pm b/lib/Pear/LocalLoop.pm index dbc55ed..fe6d738 100644 --- a/lib/Pear/LocalLoop.pm +++ b/lib/Pear/LocalLoop.pm @@ -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'); diff --git a/lib/Pear/LocalLoop/Controller/Admin/Users.pm b/lib/Pear/LocalLoop/Controller/Admin/Users.pm new file mode 100644 index 0000000..6c0828a --- /dev/null +++ b/lib/Pear/LocalLoop/Controller/Admin/Users.pm @@ -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; diff --git a/templates/admin/users/index.html.ep b/templates/admin/users/index.html.ep new file mode 100644 index 0000000..2fc74bc --- /dev/null +++ b/templates/admin/users/index.html.ep @@ -0,0 +1,22 @@ +% layout 'admin'; +% title 'Users'; +% content_for javascript => begin +% end +% if ( my $error = flash 'error' ) { + +% } elsif ( my $success = flash 'success' ) { + +% } +
+ % for my $user (@$users) { + +
+ %= $user->{email} +
+
+ % } +