Skip to content

Instantly share code, notes, and snippets.

@amiri
Created September 28, 2011 21:53
Show Gist options
  • Save amiri/1249360 to your computer and use it in GitHub Desktop.
Save amiri/1249360 to your computer and use it in GitHub Desktop.
Login
package RoosterPirates::Web::Controller::Login;
use Moose;
use namespace::autoclean;
BEGIN { extends 'Catalyst::Controller'; }
sub index : Chained('/') PathPart('login') Args('0') {
my ( $self, $c ) = @_;
$c->stash( template => 'login.tt2' );
if ( lc $c->req->method eq 'post' ) {
my $email = $c->req->params->{email};
my $password = $c->req->params->{password};
if ( $c->authenticate( { email => $email, password => $password } ) )
{
$c->flash(
status_msg => "Welcome back, " . $c->user->first_name );
return $c->res->redirect(
$c->uri_for( $c->controller('Root')->action_for('index') ) );
}
else {
$c->stash( error_msg => "Bad username or password." );
}
}
$c->stash( template => 'login.tt2' );
}
__PACKAGE__->meta->make_immutable;
1;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment