Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

authentication for writer

  • Loading branch information...
commit b11c9ac76823479cc984284f450f265e9212c75c 1 parent 81b3bcb
Nobuo Danjou authored

Showing 2 changed files with 16 additions and 0 deletions. Show diff stats Hide diff stats

  1. +12 0 app.p6sgi
  2. +4 0 config.pl.sample
12 app.p6sgi
@@ -3,6 +3,8 @@ use Journal;
3 3 use Plackdo::Builder;
4 4 use Plackdo::Middleware::Runtime;
5 5 use Plackdo::Middleware::Static;
  6 +use Plackdo::Middleware::Auth::Basic;
  7 +use Plackdo::Middleware::Conditional;
6 8
7 9 my $conf = eval slurp 'config.pl';
8 10 $conf or die 'invalid config';
@@ -10,6 +12,16 @@ $conf or die 'invalid config';
10 12 my $j = Journal.new(|$conf<database>);
11 13
12 14 my $b = Plackdo::Builder.new;
  15 +$b.add_middleware(
  16 + Plackdo::Middleware::Conditional.new(
  17 + middleware => Plackdo::Middleware::Auth::Basic.new(
  18 + authenticator => sub ($user, $pass, %env) {
  19 + ($user eq $conf<auth><name>) && ($pass eq $conf<auth><password>)
  20 + }
  21 + ),
  22 + condition => sub (%env) {%env<PATH_INFO> ~~ m{ ^ '/writer' } }
  23 + )
  24 +);
13 25 $b.add_middleware( Plackdo::Middleware::Static.new(|$conf<static>) );
14 26 $b.add_middleware( Plackdo::Middleware::Runtime.new );
15 27 $b.to_app($j.webapp);
4 config.pl.sample
@@ -15,6 +15,10 @@ use v6;
15 15 static => {
16 16 root => '.',
17 17 path => rx{ ^ '/static' }
  18 + },
  19 + auth => {
  20 + name => 'yourname',
  21 + password => 'password',
18 22 }
19 23 }
20 24

0 comments on commit b11c9ac

Please sign in to comment.
Something went wrong with that request. Please try again.