X-Git-Url: http://git.ieval.ro/?a=blobdiff_plain;f=app.psgi;h=be72e9b18b9bd2fa4dd7ea7317d41d84a44e035c;hb=d2a977e374a40ff05a877e183f2d015ae0f1b877;hp=728e144e4cf0b742cf7f22765925419d51f350e1;hpb=a8dc218ceb178e05b574deed4090503fa9be3502;p=plack-app-gruntmaster.git diff --git a/app.psgi b/app.psgi index 728e144..be72e9b 100644 --- a/app.psgi +++ b/app.psgi @@ -5,11 +5,8 @@ no if $] >= 5.017011, warnings => 'experimental::smartmatch'; use Gruntmaster::Data; use Plack::App::Gruntmaster; use Plack::Builder; -use Plack::Request; use Plack::Util; -use Digest::SHA qw/sha256/; use Log::Log4perl; -use Tie::Hash::Expire; use constant AUTH_TIMEOUT => 5 * 60; use constant ACCESSLOG_FORMAT => '%{X-Forwarded-For}i %l %u %t "%r" %>s %b "%{Referer}i" "%{User-agent}i"'; @@ -22,8 +19,8 @@ form-action 'self' frame-ancestors 'none' img-src 'self' https://static.mindcoding.ro https://www.google-analytics.com/collect referrer origin-when-cross-origin -script-src https://static.mindcoding.ro/js.js https://www.google-analytics.com/analytics.js -style-src https://static.mindcoding.ro/css/ +script-src https://static.mindcoding.ro/static/js.js https://www.google-analytics.com/analytics.js +style-src https://static.mindcoding.ro/static/css/ CSP chomp $csp; $csp =~ s/\n/; /gr; @@ -31,17 +28,6 @@ CSP my $db; -tie my %auth, 'Tie::Hash::Expire', {expire_seconds => AUTH_TIMEOUT}; - -sub authenticate { - my ($user, $pass, $env) = @_; - my $key = sha256 "$user:$pass"; - $env->{'gruntmaster.user'} = $user; - return 1 if exists $auth{$key}; - return unless $db->user($user) && $db->user($user)->check_passphrase($pass); - $auth{key} = 1; -} - sub add_database { my $app = $_[0]; sub { @@ -76,6 +62,9 @@ builder { enable 'Static', path => qr,^/static/,; enable 'Log4perl', category => 'plack'; enable \&add_database; - enable_if { shift->{HTTP_AUTHORIZATION} } 'Auth::Basic', authenticator => \&authenticate, realm => 'Gruntmaster 6000'; + enable '+Plack::App::Gruntmaster::Auth', + dbi_connect => [$ENV{GRUNTMASTER_DSN} // 'dbi:Pg:', '', ''], + realm => 'Gruntmaster 6000', + mail_from => $ENV{GRUNTMASTER_RESET_FROM}; Plack::App::Gruntmaster->run_if_script }