Created
May 5, 2010 09:48
-
-
Save memowe/390582 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
package Mojolicious::Lite::Auth; | |
use base Mojolicious::Controller; | |
sub check { | |
my $self = shift; | |
return 1 if $self->param('password') eq 42; | |
$self->flash( message => 'Go away!' ); | |
$self->redirect_to('message'); | |
return; | |
} | |
package main; | |
use Mojolicious::Lite; | |
app->routes->bridge->to('auth#check')->route('/main')->to({ callback => sub { | |
my $self = shift; | |
$self->stash( | |
hi => 'This is main.', | |
template => 'main', | |
); | |
}}); | |
get '/' => 'index'; | |
get '/message' => 'message'; | |
app->start; | |
__DATA__ | |
@@ index.html.ep | |
% layout 'default'; | |
<h1>Hi, please authorize with 42</h1><hr> | |
<form action="/main" method="get"> | |
<p> | |
<label for="password">password</label>: | |
<input type="password" id="password" name="password"> | |
<input type="submit" value="login"> | |
</p> | |
</form> | |
@@ message.html.ep | |
% layout 'default'; | |
<h1>Message for you</h1><hr> | |
<p><%= flash('message') %></p> | |
@@ main.html.ep | |
% layout 'default'; | |
<h1>Yay!</h1><hr> | |
<p>You got that right.</p> | |
<p><%= $hi %></p> | |
@@ layouts/default.html.ep | |
<!doctype html><html> | |
<head><title>Example!</title></head> | |
<body><%== content %></body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment