rd qw/Object Str StrMatch Enum Optional HashRef Bool/;
use Future::HTTP;
use HTTP::CookieJar;
use JSON;
our ($validate, $session);
BEGIN {
$validate = cpo(
login => {
username => Str,
passwo
alhost:5000'
}
);
has [qw/csrf/] => (
is => 'rw',
isa => Str
);
has json => (
is => 'ro',
default => sub {
return JSON->new->allow_blessed->convert_blessed;
}
);
has ua => (
is => 'ro',
d
a->http_get(
sprintf("%s/api/session", $self->host),
headers => {
'Accept' => 'application/json'
}
)->then(sub {
my ($body, $headers) = @_;
$self->csrf($headers->{token});
return Futur
d => Types::Standard::Optional->of(Str)
);
post '/login' => sub {
my $body = $login->(
decode_json(request->body)
);
my %res = ();
if ($body->{username} && $body->{password}) {
if ($body->{u
{success} = 'You have logged in.';
}
}
return encode_json(\%res);
};
post '/logout' => sub {
app->destroy_session;
return encode_json({ success => 'User has logged out.' });
};
get '/session
# check whether we have a session
response_headers 'Token' => get_csrf_token();
return encode_json({
session => session->data->{logged_in} ? 1 : 0
});
};
our $generatePOD = compile_named(
s