Updated login class
diff --git a/.gitignore b/.gitignore
index bb07aac..43657d5 100644
--- a/.gitignore
+++ b/.gitignore
@@ -24,5 +24,6 @@
*.db
*.old
.*
+t/kalamar_user_client.t
!.gitignore
npm-debug.log
\ No newline at end of file
diff --git a/kalamar.conf b/kalamar.conf
index 2fa18ef..79e4f70 100644
--- a/kalamar.conf
+++ b/kalamar.conf
@@ -1,14 +1,28 @@
{
Search => {
engine => 'Kalamar::API',
-# api => 'http://10.0.10.13:7070/api/v0.1/'
- api => 'http://localhost:9999/api/v0.1/'
+ # api => 'http://10.0.10.13:7070/api/v0.1/'
+ # api => 'http://localhost:9999/api/v0.1/'
+ api => 'http://10.0.10.51:7070/api/v0.1/'
},
CHI => {
default => {
driver => 'FastMmap',
root_dir => app->home . '/cache/data',
- cache_size => '12m'
+ cache_size => '100m',
+ max_size => '100m'
+ },
+ user => {
+ l1_cache => {
+ driver => 'FastMmap',
+ root_dir => app->home . '/cache/usermap',
+ cache_size => '50m',
+ max_size => '50m'
+ },
+ driver => 'File',
+ root_dir => app->home . '/cache/userfile',
+ max_key_length => 64,
+ max_size => '500m'
}
},
hypnotoad => {
diff --git a/lib/Kalamar/Plugin/KalamarUser.pm b/lib/Kalamar/Plugin/KalamarUser.pm
index a9ea947..a7d13bb 100644
--- a/lib/Kalamar/Plugin/KalamarUser.pm
+++ b/lib/Kalamar/Plugin/KalamarUser.pm
@@ -3,6 +3,7 @@
use Mojo::ByteStream 'b';
has 'api';
+has 'ua';
sub register {
my ($plugin, $mojo, $param) = @_;
@@ -14,6 +15,7 @@
# Set API!
$plugin->api($param->{api}) or return;
+ $plugin->ua(Mojo::UserAgent->new);
# Get the user token necessary for authorization
$mojo->helper(
@@ -36,7 +38,7 @@
my $c = shift;
my ($user, $pwd) = @_;
- return if index($user, ':') >= 0;
+ return if (index($user, ':') >= 0);
my $url = Mojo::URL->new($plugin->api)->path('auth/apiToken');
my $tx = $c->ua->get($url => {
@@ -75,7 +77,7 @@
my $c = shift;
my $param = shift;
- return unless $param =~ m/^details$/;
+ return unless $param =~ m/^details|settings$/;
# The user may be logged in
my $auth = ($c->stash('auth') || $c->session('auth')) or return;
@@ -90,7 +92,18 @@
my $value = $chi->get($user . '_' . $param);
unless ($value) {
- $value = $plugin->get_authorized($auth, 'user/' . $param) or return;
+
+ my $tx = $plugin->build_authorized_tx($auth, 'GET', 'user/' . $param);
+ $tx = $plugin->ua->start($tx);
+ unless ($value = $tx->success) {
+# warn $tx->code;
+ return;
+ }
+# else {
+# warn $c->dumper($value->json);
+# };
+ $value = $value->json;
+
$chi->set($user . '_' . $param => $value);
};
@@ -118,21 +131,25 @@
);
};
-
-# Issue an authorized request
-sub get_authorized {
+sub build_authorized_tx {
my $plugin = shift;
- my ($auth, $path) = @_;
+ my $ua = $plugin->ua;
+ my ($auth, $method, $path, @values) = @_;
+
+ my $header;
+ if (@values && ref $values[0] eq 'HASH') {
+ $header = shift @values;
+ }
+ else {
+ $header = {};
+ };
+
my $url = Mojo::URL->new($plugin->api)->path($path);
- # Get authorized
- # TODO: REUSE USERAGENT
- my $tx = Mojo::UserAgent->new->get($url => {
- Authorization => $auth
- });
+ $header->{Authorization} = $auth;
- return $tx->success ? $tx->success->json : undef;
+ return $ua->build_tx($method, $url => $header => @values);
};
@@ -140,3 +157,11 @@
__END__
+
+# Failure
+entity {
+ "errors":[
+ [204,"authentication token is expired","eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJ0ZXN0MSIsImlzcyI6Imh0dHA6IiwiZXhwIjoxNDUyOTY2NzAxOTYxfQ.W_rJjJ8i82Srw7MiSPRGeIBLE-rMPmSPK9BA7Dt_7Yc"]
+ ]
+}
+