Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

updating our controller: creating posts

  • Loading branch information...
commit 76eed746264c0ebb12567213845624c9a64d2a7f 1 parent 31785e3
@garu authored
Showing with 23 additions and 0 deletions.
  1. +23 −0 tweetylicious.pl
View
23 tweetylicious.pl
@@ -164,6 +164,29 @@ package main;
} => 'homepage';
+# this one handles users creating new posts ('message')
+post '/:user/post' => sub {
+ my $self = shift;
+
+ # user can only create posts for their own account
+ $self->redirect_to('/')
+ unless $self->session('name') eq $self->param('user');
+
+ my $user = $self->session('name');
+
+ if( $self->param('message') ) {
+ my $post = Model::Post->create(
+ username => $user,
+ content => $self->param('message'),
+ date => time,
+ );
+ }
+
+ # render the user page again
+ $self->redirect_to("/$user");
+};
+
+
# let's rock and roll!
shagadelic;
Please sign in to comment.
Something went wrong with that request. Please try again.