| 1 | #!/usr/bin/perl |
| 2 | |
| 3 | use Dancerscip-perl cpan Dancer-Plugin-Auth-Extensible 1.00 Dancer/; |
| 4 | use libscip-perl cpan Dancer-Plugin-Auth-Extensible 1.00 lib/ '../lib'; |
| 5 | use Dancer::Plugin::Auth::Extensiblescip-perl cpan Dancer-Plugin-Auth-Extensible 1.00 Dancer/Plugin/Auth/Extensible/; |
| 6 | |
| 7 | getscip-perl cpan Dancer-Plugin-Auth-Extensible 1.00 main/get(). '/' => sub { |
| 8 | my $content = "<h1>Non-secret home page!</h1>"; |
| 9 | if (my $user = logged_in_userscip-perl cpan Dancer-Plugin-Auth-Extensible 1.00 main/logged_in_user().()) { |
| 10 | $content .= "<p>Hi there, $user->{name}!</p>"; |
| 11 | } else { |
| 12 | $content .= "<p>Why not <a href=\"/login\">log in</a>?</p>"; |
| 13 | } |
| 14 | |
| 15 | $content .= <<LINKS; |
| 16 | <p><a href="/secret">Psst, wanna know a secret?</a></p> |
| 17 | <p><a href="/beer">Or maybe you want a beer</a></p> |
| 18 | <p><a href="/vodka">Or, a vodka?</a></p> |
| 19 | LINKS |
| 20 | |
| 21 | if (user_has_rolescip-perl cpan Dancer-Plugin-Auth-Extensible 1.00 main/user_has_role().('BeerDrinker')) { |
| 22 | $content .= "<p>You can drink beer</p>"; |
| 23 | } |
| 24 | if (user_has_rolescip-perl cpan Dancer-Plugin-Auth-Extensible 1.00 main/user_has_role().('WineDrinker')) { |
| 25 | $content .= "<p>You can drink wine</p>"; |
| 26 | } |
| 27 | |
| 28 | return $content; |
| 29 | }; |
| 30 | |
| 31 | getscip-perl cpan Dancer-Plugin-Auth-Extensible 1.00 main/get(). '/secret' => require_login sub { "Only logged-in users can see this" }; |
| 32 | |
| 33 | getscip-perl cpan Dancer-Plugin-Auth-Extensible 1.00 main/get(). '/beer' => require_any_role [qw(BeerDrinker HardDrinker)], sub { |
| 34 | "Any drinker can get beer."; |
| 35 | }; |
| 36 | |
| 37 | getscip-perl cpan Dancer-Plugin-Auth-Extensible 1.00 main/get(). '/vodka' => require_role HardDrinker => sub { |
| 38 | "Only hard drinkers get vodka"; |
| 39 | }; |
| 40 | |
| 41 | getscip-perl cpan Dancer-Plugin-Auth-Extensible 1.00 main/get(). '/realm' => require_login sub { |
| 42 | "You are logged in using realm: " . session->{logged_in_user_realm}; |
| 43 | }; |
| 44 | dancescip-perl cpan Dancer-Plugin-Auth-Extensible 1.00 main/dance().(); |