fix
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -12,3 +12,4 @@ posts/*.post
|
||||
bookshelf.txt
|
||||
site.db*
|
||||
less/cache/
|
||||
*.secret
|
||||
12
site.pl
12
site.pl
@@ -3,10 +3,14 @@ use 5.016;
|
||||
|
||||
use Mojolicious::Lite -signatures;
|
||||
use Mojo::SQLite;
|
||||
use Mojo::File;
|
||||
use Carp qw(croak);
|
||||
|
||||
croak qq{No AUTH_HEADER value in environment.} unless exists $ENV{AUTH_HEADER};
|
||||
croak qq{No AUTH_KEY value in environment.} unless exists $ENV{AUTH_KEY};
|
||||
my $AUTH_HEADER = [ split( /,/, Mojo::File->new('.secret')->slurp ) ]->[0];
|
||||
my $AUTH_KEY = [ split( /,/, Mojo::File->new('.secret')->slurp ) ]->[1];
|
||||
|
||||
croak qq{No AUTH_HEADER value in .secret} unless $AUTH_HEADER;
|
||||
croak qq{No AUTH_KEY value in .secret} unless $AUTH_KEY;
|
||||
|
||||
my $sql = Mojo::SQLite->new('sqlite:site.db');
|
||||
helper db => sub { state $db = $sql->db };
|
||||
@@ -58,8 +62,8 @@ get '/blog/:post' => sub {
|
||||
|
||||
post '/blog' => sub {
|
||||
my $c = shift;
|
||||
my $auth = $c->req->headers->to_hash->{ $ENV{AUTH_HEADER} };
|
||||
return $c->rendered(400) unless $auth and ( $auth eq $ENV{AUTH_KEY} );
|
||||
my $auth = $c->req->headers->to_hash->{$AUTH_HEADER};
|
||||
return $c->rendered(400) unless $auth and ( $auth eq $AUTH_KEY );
|
||||
|
||||
if ( my $old_post =
|
||||
$c->db->select( 'posts', ['id'], { slug => $c->req->json->{slug} } )
|
||||
|
||||
Reference in New Issue
Block a user