Skip to content

Instantly share code, notes, and snippets.

Created September 23, 2011 07:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/1236883 to your computer and use it in GitHub Desktop.
Save anonymous/1236883 to your computer and use it in GitHub Desktop.
use Mojolicious::Lite;
under sub {
my $self = shift;
my ($user) = split /:/, $self->req->url->to_abs->userinfo;
unless($user) {
$self->res->headers->www_authenticate('Basic realm=test');
$self->render_text('You must log in', status => 401);
return;
} else {
$self->stash( user => $user );
return 1;
}
};
get '/' => sub { $_[0]->render_text( 'Hello '.$_[0]->stash('user').'. Would you like to play a game?'); };
group {
under '/gtw' => sub { shift->stash('user') eq 'david' };
get sub {
shift->render_text('The only way to win is to not play at all');
};
};
get '/chess' => sub { shift->render_text('checkmate'); };
get '/bye' => sub { shift->render_text('Bye!', status => 401); };
app->start;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment