use Mojolicious::Lite;
# Authenticate based on name parameter
under sub {
my $c = shift;
# Authenticated
my $name = $c->param('name') || '';
return 1 if $name eq 'Bender';
# Not authenticated
$c->render(template => 'denied');
return undef;
};
# Only reached when authenticated
get '/' => 'index';
app->start;
__DATA__
@@ denied.html.ep
You are not Bender, permission denied.
@@ index.html.ep
Hi Bender.
(Lifted from the Mojolicious docs at https://mojolicious.org/perldoc/Mojolicious/Guides/Tutorial#Under.)
Of course now that you've got the 'under' hook into which you can inject authentication, you are left with the more meaty problem of what authentication method you want to plug in there.
|