Skip to content

Commit

Permalink
add catch-all route
Browse files Browse the repository at this point in the history
  • Loading branch information
davemenninger committed Nov 18, 2014
1 parent 6ccf1d8 commit 4448446
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 9 deletions.
3 changes: 2 additions & 1 deletion Readme.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ This is a test app for trying new things in Mojolicious.
* ~~more tests for authentication, registration~~
* ~~add authorization ( logged in user can see some things, but not others )~~
* tests for authorization
* catch-all route, switch routes to use over() conditions
* ~~catch-all route~~, switch routes to use over() conditions
* Mojolicious plugins: CSRFProtect, VaildateTiny
* ~~user can create document objects into mongo~~
* roles: ~~admin~~, ~~guest~~, author, reader?
* scripts: setup new db,
Expand Down
9 changes: 9 additions & 0 deletions lib/Lrrr.pm
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,15 @@ sub startup {
}
);

# catch-all route
$r->any(
'/*whatever' => {whatever => ''} => sub {
my $c = shift;
my $whatever = $c->param('whatever');
$c->render(text => "/$whatever did not match.", status => 404);
}
);

return;
}

Expand Down
15 changes: 7 additions & 8 deletions templates/user.html.ep
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,19 @@
% title 'User';
<h2>User</h2>

<p>
% if( my $authentication = stash '__authentication__' ) {
<p>
You are logged in as <%= $authentication->{user}->{username} %>.
Here is <a href="/hidden">a page</a> with something you can only see if logged in.
% } else {
You are not logged in.
% }
</p>
<p>
Your role is <%= role %>.
</p>
<p>
Your privs are
Your role is <%= role %> and your privs are
% for my $p ( privileges() ){
<li><%= $p %></li>
% }
</p>
% } else {
<p>
You are not logged in.
</p>
% }

0 comments on commit 4448446

Please sign in to comment.