File: authextest.pl

package info (click to toggle)
libdancer-plugin-auth-extensible-perl 1.00-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 232 kB
  • sloc: perl: 599; makefile: 11
file content (44 lines) | stat: -rw-r--r-- 1,129 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!/usr/bin/perl

use Dancer;
use lib '../lib';
use Dancer::Plugin::Auth::Extensible;

get '/' => sub {
    my $content = "<h1>Non-secret home page!</h1>";
    if (my $user = logged_in_user()) {
        $content .= "<p>Hi there, $user->{name}!</p>";
    } else {
        $content .= "<p>Why not <a href=\"/login\">log in</a>?</p>";
    }

    $content .= <<LINKS;
<p><a href="/secret">Psst, wanna know a secret?</a></p>
<p><a href="/beer">Or maybe you want a beer</a></p>
<p><a href="/vodka">Or, a vodka?</a></p>
LINKS

    if (user_has_role('BeerDrinker')) {
        $content .= "<p>You can drink beer</p>";
    }
    if (user_has_role('WineDrinker')) {
        $content .= "<p>You can drink wine</p>";
    }

    return $content;
};

get '/secret' => require_login sub { "Only logged-in users can see this" };

get '/beer' => require_any_role [qw(BeerDrinker HardDrinker)], sub {
    "Any drinker can get beer.";
};

get '/vodka' => require_role HardDrinker => sub {
    "Only hard drinkers get vodka";
};

get '/realm' => require_login sub {
    "You are logged in using realm: " . session->{logged_in_user_realm};
};
dance();