Skip to content

Commit

Permalink
add user list
Browse files Browse the repository at this point in the history
  • Loading branch information
davemenninger committed Nov 21, 2014
1 parent dd7100d commit 838360b
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 2 deletions.
1 change: 1 addition & 0 deletions Readme.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ This is an example Mojolicious app. Its goals are:
* ~~more tests for authentication, registration~~
* ~~add authorization ( logged in user can see some things, but not others )~~
* tests for authorization
* tests for user routes
* ~~catch-all route~~, switch routes to use over() conditions
* Mojolicious plugins: CSRFProtect, VaildateTiny, Toto
* ~~user can create document objects into mongo~~
Expand Down
2 changes: 2 additions & 0 deletions lib/Lrrr.pm
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ sub startup {
}
);

$r->get('/users')->to( controller => 'users', action => 'list' );

$r->get(
'/hidden' => sub {
$self = shift;
Expand Down
6 changes: 4 additions & 2 deletions lib/Lrrr/Authorization.pm
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ use strict;
use warnings;

my %roles = (
admin => { create_user => 1, delete_user => 1 },
guest => { foo => 1 }
admin =>
{ create_user => 1, delete_user => 1, create_post => 1, delete_post => 1 },
author => { create_post => 1 },
guest => { read_posts => 1 }
);

sub has_priv {
Expand Down
17 changes: 17 additions & 0 deletions lib/Lrrr/Controller/Users.pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package Lrrr::Controller::Users;

use strict;
use warnings;

use Mojo::Base 'Mojolicious::Controller';

# This action will render a template
sub list {
my $self = shift;

$self->render( template => 'userlist', format => 'html' );

return;
}

1;
10 changes: 10 additions & 0 deletions templates/userlist.html.ep
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
% layout 'default';
% title 'User List';
<h2>User List</h2>

% my $docs = mango->db->collection('users')->find;
<ul>
% while ( my $doc = $docs->next ) {
<li><%= $doc->{username} %>, <%= $doc->{role} %></li>
% }
</ul>

0 comments on commit 838360b

Please sign in to comment.