Made authorization optional
Change-Id: Ib86f47d05136bc806a3f4ccde5e567a387528804
diff --git a/kalamar.conf b/kalamar.conf
index 0d52586..99e16e2 100644
--- a/kalamar.conf
+++ b/kalamar.conf
@@ -10,7 +10,8 @@
api => $ENV{'KALAMAR_API'} // $api
},
Kalamar => {
- api => $ENV{'KALAMAR_API'} // $api
+ api => $ENV{'KALAMAR_API'} // $api,
+ auth_support => 0
},
CHI => {
default => {
diff --git a/lib/Kalamar.pm b/lib/Kalamar.pm
index 799d8d3..b324be5 100644
--- a/lib/Kalamar.pm
+++ b/lib/Kalamar.pm
@@ -74,7 +74,9 @@
my $mount_point = '/api/v0.1/';
$self->plugin(Mount => {
- $mount_point => $self->home->child('lib/Kalamar/Apps/test_backend.pl')
+ $mount_point => $self->home->child(
+ 'lib/Kalamar/Apps/test_backend.pl'
+ )
});
# Fix api endpoints
@@ -128,18 +130,28 @@
$self->log->info('API expected at ' . $self->config->{Kalamar}->{api});
# Establish routes with authentification
- my $r = $self->routes->under(
- '/' => sub {
- my $c = shift;
+ my $r = $self->routes;
- if ($c->session('auth')) {
- $c->stash(auth => $c->session('auth'));
- $c->stash(user => $c->session('user'));
- };
- return 1;
- }
+ # Check for auth support
+ $self->defaults(
+ auth_support => $self->config('Kalamar')->{auth_support}
);
+ # Support auth
+ if ($self->stash('auth_support')) {
+ $r = $r->under(
+ '/' => sub {
+ my $c = shift;
+
+ if ($c->session('auth')) {
+ $c->stash(auth => $c->session('auth'));
+ $c->stash(user => $c->session('user'));
+ };
+ return 1;
+ }
+ );
+ };
+
# Base query route
$r->get('/')->to('search#query')->name('index');
diff --git a/t/remote_user.t b/t/remote_user.t
index d8a0450..d90fec1 100644
--- a/t/remote_user.t
+++ b/t/remote_user.t
@@ -8,6 +8,8 @@
my $t = Test::Mojo->new('Kalamar');
+$t->app->defaults(auth_support => 1);
+
$t->get_ok('/?q=Baum')
->status_is(200)
->text_like('h1 span', qr/KorAP: Find .Baum./i)
diff --git a/templates/layouts/main.html.ep b/templates/layouts/main.html.ep
index 7ddb283..5f02f17 100644
--- a/templates/layouts/main.html.ep
+++ b/templates/layouts/main.html.ep
@@ -23,7 +23,7 @@
%= include 'partial/header'
% }
-% unless (user_auth) { # user not logged in
+% if (!user_auth && stash('auth_support')) { # user not logged in
% content_for 'sidebar', begin
% if (flash('handle_or_email') && !param('handle_or_email')) {
% param(handle_or_email => flash('handle_or_email'));