Permalink
Browse files

updating our controller: turning common posting auth code into a ladder

  • Loading branch information...
1 parent bfa937d commit bd7b55f6f4db2843cdf89ebebea13c62cca530e9 @garu committed Jun 14, 2010
Showing with 10 additions and 9 deletions.
  1. +10 −9 tweetylicious.pl
View
19 tweetylicious.pl
@@ -164,14 +164,19 @@ package main;
} => 'homepage';
-# this one handles users creating new posts ('message')
-post '/:user/post' => sub {
+# next comes actions that can only be performed if the user is
+# looking at its own posts (creating and deleting posts),
+# so we do a ladder
+ladder sub {
my $self = shift;
-
- # user can only create posts for their own account
$self->redirect_to('/')
- unless $self->session('name') eq $self->param('user');
+ unless $self->session('name') eq $self->param('user');
+};
+
+# this one handles users creating new posts ('message')
+post '/:user/post' => sub {
+ my $self = shift;
my $user = $self->session('name');
if( $self->param('message') ) {
@@ -190,10 +195,6 @@ package main;
get '/:user/post/:id/delete' => sub {
my $self = shift;
- # user can only delete posts for their own account
- $self->redirect_to('/')
- unless $self->session('name') eq $self->param('user');
-
my $post = Model::Post->select('WHERE id = ?', $self->param('id'));
$post->[0]->delete if $post->[0];

0 comments on commit bd7b55f

Please sign in to comment.