Permalink
Browse files

registering users: the controller

  • Loading branch information...
1 parent 04e44bf commit d16efb39f9a06c1cd2321e0722ecb5ddeabcb229 @garu committed Jun 13, 2010
Showing with 19 additions and 1 deletion.
  1. +19 −1 tweetylicious.pl
View
@@ -43,6 +43,7 @@ package Model;
package main;
use Mojolicious::Lite;
+use Mojo::ByteStream 'b'; # for unicode and md5
# this is a fake static route for our static data (static.js, static.css)
get '/static' => 'static';
@@ -52,8 +53,25 @@ package main;
get '/' => 'index';
-# this controls a user registering
+# these two control a user registering
get '/join' => 'join';
+post '/join' => sub {
+ my $self = shift;
+ my $user = $self->param('username');
+
+ Model::User->create(
+ username => $user,
+ password => b(app->secret . $self->param('pwd'))->md5_sum,
+ email => $self->param('email'),
+ gravatar => b($self->param('email'))->md5_sum,
+ bio => $self->param('bio'),
+ );
+
+ # auto-login the user after he joins, and redirect to /
+ $self->session( name => $user );
+ $self->redirect_to("/");
+} => 'join';
+
# let's rock and roll!

0 comments on commit d16efb3

Please sign in to comment.