Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Move /list/add to a more sensible URL. Use Dancer2::Plugin::Auth::Tiny.
  • Loading branch information
davorg committed Jan 15, 2016
1 parent fa7b285 commit 0184bfc
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
5 changes: 3 additions & 2 deletions lib/Lystyng.pm
Expand Up @@ -9,6 +9,7 @@ package Lystyng;
use Dancer2;
our $VERSION = '0.0.1';
use Dancer2::Plugin::DBIC qw[schema resultset];
use Dancer2::Plugin::Auth::Tiny;
use Lystyng::Schema;

Lystyng::Schema->check_env();
Expand Down Expand Up @@ -46,13 +47,13 @@ get '/user/:username' => sub {
}
};

get '/user/:username/list/add' => sub {
get '/list/add' => needs login => sub {
redirect '/login' unless session('user');

template 'addlist';
};

post '/user/:username/list/add' => sub {
post '/list/add' => needs login => sub {
redirect '/login' unless session('user');

session('user')->add_to_lists({
Expand Down
4 changes: 2 additions & 2 deletions views/addlist.tt
Expand Up @@ -13,7 +13,7 @@
} ] -%]

<h2>Add List</h2>
<form role="form" class="form-horizontal" method="post" action="/user/[% session.user.username %]/list/add">
<form role="form" class="form-horizontal" method="post" action="/list/add">
[% FOREACH field IN fields -%]
<div class="form-group">
<label class="col-md-2 control-label" for="[% field.name %]">[% field.label %]</label>
Expand All @@ -27,4 +27,4 @@
<button type="submit" class="btn btn-primary btn-block">Add</button>
</div>
</div>
</form>
</form>
2 changes: 1 addition & 1 deletion views/user.tt
Expand Up @@ -9,7 +9,7 @@
<p>User has no lists</p>
[% END -%]
[% IF session.user AND session.user.username == user.username -%]
<a href="/user/[% user.username %]/list/add"><button type="button" class="btn btn-default btn-lg">
<a href="/list/add"><button type="button" class="btn btn-default btn-lg">
<span class="glyphicon glyphicon-plus"></span> Add List
</button></a>
[% END -%]

0 comments on commit 0184bfc

Please sign in to comment.