Encourage login on zero matches (fixes #67)
Change-Id: Ic7805d2286de9fc24d06ca94c71b7ab4890f7973
diff --git a/Changes b/Changes
index 8f24bb2..a8df8da 100755
--- a/Changes
+++ b/Changes
@@ -15,6 +15,8 @@
proxy by default.
- Establish 'after_search_results' content part.
- Establish 'after_search' hook.
+ - Recommend log in on zero matches in search results
+ in case not logged in (addresses #67).
0.37 2020-01-16
- Removed deprecated 'kalamar_test_port' helper.
diff --git a/dev/scss/main/main.scss b/dev/scss/main/main.scss
index f1d0048..67b48fa 100644
--- a/dev/scss/main/main.scss
+++ b/dev/scss/main/main.scss
@@ -52,6 +52,11 @@
}
}
}
+
+ p.hint {
+ margin: 0 auto;
+ text-align: center;
+ }
}
blockquote {
diff --git a/lib/Kalamar/Plugin/Auth.pm b/lib/Kalamar/Plugin/Auth.pm
index b9c97f8..070ad32 100644
--- a/lib/Kalamar/Plugin/Auth.pm
+++ b/lib/Kalamar/Plugin/Auth.pm
@@ -75,7 +75,8 @@
registerSuccess => 'Registrierung erfolgreich',
registerFail => 'Registrierung fehlgeschlagen',
oauthSettings => 'OAuth',
- oauthUnregister => 'Möchten sie <span class="client-name"><%= $clientName %></span> wirklich löschen?'
+ oauthUnregister => 'Möchten sie <span class="client-name"><%= $clientName %></span> wirklich löschen?',
+ loginHint => 'Möglicherweise müssen sie sich zunächst einloggen.'
},
-en => {
loginSuccess => 'Login successful',
@@ -102,6 +103,7 @@
registerFail => 'Registration denied',
oauthSettings => 'OAuth',
oauthUnregister => 'Do you really want to unregister <span class="client-name"><%= $clientName %></span>?',
+ loginHint => 'Maybe you need to log in first?'
}
}
}
@@ -123,6 +125,24 @@
}
);
+
+ # Add hook after search
+ $app->hook(
+ after_search => sub {
+ my $c = shift;
+
+ # User is not logged in
+ if ($c->stash('results')->size == 0 && !$c->auth->token) {
+ $c->content_for(
+ 'after_search_results' =>
+ $c->render_to_string(
+ inline => '<p class="hint"><%= loc "Auth_loginHint" %></p>'
+ )
+ );
+ };
+ }
+ );
+
# The plugin path
my $path = catdir(dirname(__FILE__), 'Auth');
diff --git a/t/fixtures/response_query_paum_o0_c25.json b/t/fixtures/response_query_paum_o0_c25.json
new file mode 100644
index 0000000..ca9ebba
--- /dev/null
+++ b/t/fixtures/response_query_paum_o0_c25.json
@@ -0,0 +1,41 @@
+{
+ "status" : 200,
+ "json" : {
+ "@context" : "http://korap.ids-mannheim.de/ns/KoralQuery/v0.3/context.jsonld",
+ "meta" : {
+ "count" : 25,
+ "startIndex" : 0,
+ "authorized" : null,
+ "timeout" : 120000,
+ "context" : {
+ "left" : ["token",40],
+ "right" : ["token",40]
+ },
+ "fields" : ["pubDate","subTitle","author","pubPlace","title","textSigle","UID","ID","layerInfos","corpusSigle","docSigle","corpusID","textClass"],
+ "version" : "0.55.7",
+ "benchmark" : "0.120577834 s",
+ "totalResults" : 0,
+ "serialQuery" : "tokens:s:Paum",
+ "itemsPerPage" : 25
+ },
+ "query" : {
+ "@type" : "koral:token",
+ "wrap" : {
+ "@type" : "koral:term",
+ "layer" : "orth",
+ "key" : "Baum",
+ "match" : "match:eq",
+ "foundry" : "opennlp",
+ "rewrites" : [
+ {
+ "@type" : "koral:rewrite",
+ "src" : "Kustvakt",
+ "operation" : "operation:injection",
+ "scope" : "foundry"
+ }
+ ]
+ }
+ },
+ "matches" : []
+ }
+}
diff --git a/t/plugin/auth-oauth.t b/t/plugin/auth-oauth.t
index b211eab..802f9d2 100644
--- a/t/plugin/auth-oauth.t
+++ b/t/plugin/auth-oauth.t
@@ -213,6 +213,15 @@
->element_exists('div.button.top a.logout[title~="test"]')
;
+$t->get_ok('/?q=Paum')
+ ->status_is(200)
+ ->text_like('h1 span', qr/KorAP: Find .Paum./i)
+ ->text_is('#total-results', '')
+ ->content_like(qr/\"authorized\"\:\"yes\"/)
+ ->element_exists_not('p.hint')
+ ;
+
+
# Logout
$t->get_ok('/user/logout')
->status_is(302)
@@ -237,6 +246,15 @@
->content_like(qr/\"authorized\"\:null/)
;
+$t->get_ok('/?q=Paum')
+ ->status_is(200)
+ ->text_like('h1 span', qr/KorAP: Find .Paum./i)
+ ->text_is('#total-results', '')
+ ->content_like(qr/\"authorized\"\:null/)
+ ->text_is('p.hint', 'Maybe you need to log in first?')
+ ;
+
+
# Get redirect
my $fwd = $t->get_ok('/?q=Baum&ql=poliqarp')
->status_is(200)