Reintroduce email support for login (fixes #165; reverts #e208d30513f7cfafb6405324fee5b88902dcf2fb) - 2

Change-Id: Ia145f1e47295e2e5df0248604262024f87583bab
diff --git a/t/plugin/auth-oauth.t b/t/plugin/auth-oauth.t
index 45281df..7dc2549 100644
--- a/t/plugin/auth-oauth.t
+++ b/t/plugin/auth-oauth.t
@@ -116,7 +116,7 @@
 
 $t->get_ok('/')
   ->status_is(200)
-  ->element_exists('form[action=/user/login] input[name=handle]')
+  ->element_exists('form[action=/user/login] input[name=handle_or_email]')
   ->element_exists('aside.active')
   ->element_exists_not('aside.off')
   ;
@@ -128,12 +128,12 @@
 
 # Test for bug with long password
 $t->post_ok('/user/login' => form => {
-  handle => 'test',
+  handle_or_email => 'test',
   pwd => 'kjskjhndkjndqknaskjnakjdnkjdankajdnkjdsankjdsakjdfkjahzroiuqzriudjoijdmlamdlkmdsalkmdl' })
   ->status_is(302)
   ->header_is('Location' => '/');
 
-$t->post_ok('/user/login' => form => { handle => 'test', pwd => 'fail' })
+$t->post_ok('/user/login' => form => { handle_or_email => 'test', pwd => 'fail' })
   ->status_is(302)
   ->header_is('Location' => '/');
 
@@ -141,11 +141,11 @@
   ->status_is(200)
   ->element_exists('div.notify-error')
   ->text_is('div.notify-error', 'Bad CSRF token')
-  ->element_exists('input[name=handle][value=test]')
+  ->element_exists('input[name=handle_or_email][value=test]')
   ->element_exists_not('div.button.top a')
   ;
 
-$t->post_ok('/user/login' => form => { handle => 'test', pwd => 'pass' })
+$t->post_ok('/user/login' => form => { handle_or_email => 'test', pwd => 'pass' })
   ->status_is(302)
   ->header_is('Location' => '/');
 
@@ -158,7 +158,7 @@
   ;
 
 $t->post_ok('/user/login' => form => {
-  handle => 'test',
+  handle_or_email => 'test',
   pwd => 'ldaperr',
   csrf_token => $csrf
 })
@@ -170,14 +170,14 @@
   ->status_is(200)
   ->element_exists('div.notify-error')
   ->text_is('div.notify-error', '2022: LDAP Authentication failed due to unknown user or password!')
-  ->element_exists('input[name=handle][value=test]')
+  ->element_exists('input[name=handle_or_email][value=test]')
   ->element_exists_not('div.button.top a')
   ->element_exists_not('div.notify-success')
   ->tx->res->dom->at('input[name=csrf_token]')->attr('value')
   ;
 
 $t->post_ok('/user/login' => form => {
-  handle => 'test',
+  handle_or_email => 'test',
   pwd => 'unknown',
   csrf_token => $csrf
 })
@@ -189,13 +189,13 @@
   ->status_is(200)
   ->element_exists('div.notify-error')
   ->text_is('div.notify-error', '2022: LDAP Authentication failed due to unknown user or password!')
-  ->element_exists('input[name=handle][value=test]')
+  ->element_exists('input[name=handle_or_email][value=test]')
   ->element_exists_not('div.button.top a')
   ->tx->res->dom->at('input[name=csrf_token]')->attr('value')
   ;
 
 $t->post_ok('/user/login' => form => {
-  handle => 'test',
+  handle_or_email => 'test',
   pwd => 'pass',
   csrf_token => $csrf
 })
@@ -256,8 +256,8 @@
   ->element_exists_not('div.notify-error')
   ->element_exists('div.notify-success')
   ->text_is('div.notify-success', 'Logout successful')
-  ->element_exists("input[name=handle]")
-  ->element_exists("input[name=handle][value=test]")
+  ->element_exists("input[name=handle_or_email]")
+  ->element_exists("input[name=handle_or_email][value=test]")
   ;
 
 $t->get_ok('/?q=Baum')
@@ -286,7 +286,7 @@
 is($fwd, '/?q=Baum&ql=poliqarp', 'Redirect is valid');
 
 $t->post_ok('/user/login' => form => {
-  handle => 'test',
+  handle_or_email => 'test',
   pwd => 'pass',
   csrf_token => $csrf,
   fwd => 'http://bad.example.com/test'
@@ -302,7 +302,7 @@
   ;
 
 $t->post_ok('/user/login' => form => {
-  handle => 'test',
+  handle_or_email => 'test',
   pwd => 'pass',
   csrf_token => $csrf,
   fwd => $fwd
@@ -436,7 +436,7 @@
 # This should fail
 my $wide_char_login = "\x{61}\x{E5}\x{61}"; # "\x{443}\x{434}";
 $t->post_ok('/user/login' => form => {
-  handle => $wide_char_login,
+  handle_or_email => $wide_char_login,
   pwd => 'pass',
   csrf_token => $csrf,
   fwd => $fwd
@@ -448,7 +448,7 @@
   ->status_is(200)
   ->element_exists('div.notify-error')
   ->text_is('div.notify-error', 'Invalid character in request')
-  ->element_exists('input[name=handle]:not([value])')
+  ->element_exists('input[name=handle_or_email]:not([value])')
   ->element_exists_not('div.button.top a')
   ;
 
@@ -456,7 +456,7 @@
 # UTF8 request
 my $username = b('täst')->encode;
 $t->post_ok('/user/login' => form => {
-  handle => $username,
+  handle_or_email => $username,
   pwd => 'pass',
   csrf_token => $csrf
 })
@@ -783,7 +783,7 @@
   ->element_exists_not('div.notify-error')
   ->element_exists('div.notify-success')
   ->text_is('div.notify-success', 'Logout successful')
-  ->element_exists("input[name=handle]")
+  ->element_exists("input[name=handle_or_email]")
   ->tx->res->dom->at('input[name=csrf_token]')->attr('value')
   ;
 
@@ -817,7 +817,7 @@
   state => 'abcde',
   scope => 'search match',
   redirect_uri => 'http://test.com/',
-  handle => 'test',
+  handle_or_email => 'test',
   pwd => 'pass',
   fwd => $fwd
 }))
diff --git a/t/plugin/auth.t b/t/plugin/auth.t
index 4ea6a2f..db19a36 100644
--- a/t/plugin/auth.t
+++ b/t/plugin/auth.t
@@ -50,12 +50,12 @@
 
 $t->get_ok('/')
   ->status_is(200)
-  ->element_exists('form[action=/user/login] input[name=handle]')
+  ->element_exists('form[action=/user/login] input[name=handle_or_email]')
   ->element_exists('aside.active')
   ->element_exists_not('aside.off')
   ;
 
-$t->post_ok('/user/login' => form => { handle => 'test', pwd => 'fail' })
+$t->post_ok('/user/login' => form => { handle_or_email => 'test', pwd => 'fail' })
   ->status_is(302)
   ->header_is('Location' => '/');
 
@@ -63,11 +63,11 @@
   ->status_is(200)
   ->element_exists('div.notify-error')
   ->text_is('div.notify-error', 'Bad CSRF token')
-  ->element_exists('input[name=handle][value=test]')
+  ->element_exists('input[name=handle_or_email][value=test]')
   ->element_exists_not('div.button.top a')
   ;
 
-$t->post_ok('/user/login' => form => { handle => 'test', pwd => 'pass' })
+$t->post_ok('/user/login' => form => { handle_or_email => 'test', pwd => 'pass' })
   ->status_is(302)
   ->header_is('Location' => '/');
 
@@ -80,7 +80,7 @@
   ;
 
 $t->post_ok('/user/login' => form => {
-  handle => 'test',
+  handle_or_email => 'test',
   pwd => 'ldaperr',
   csrf_token => $csrf
 })
@@ -92,13 +92,13 @@
   ->status_is(200)
   ->element_exists('div.notify-error')
   ->text_is('div.notify-error', '2022: LDAP Authentication failed due to unknown user or password!')
-  ->element_exists('input[name=handle][value=test]')
+  ->element_exists('input[name=handle_or_email][value=test]')
   ->element_exists_not('div.button.top a')
   ->tx->res->dom->at('input[name=csrf_token]')->attr('value')
   ;
 
 $t->post_ok('/user/login' => form => {
-  handle => 'test',
+  handle_or_email => 'test',
   pwd => 'unknown',
   csrf_token => $csrf
 })
@@ -110,13 +110,13 @@
   ->status_is(200)
   ->element_exists('div.notify-error')
   ->text_is('div.notify-error', 'Access denied')
-  ->element_exists('input[name=handle][value=test]')
+  ->element_exists('input[name=handle_or_email][value=test]')
   ->element_exists_not('div.button.top a')
   ->tx->res->dom->at('input[name=csrf_token]')->attr('value')
   ;
 
 $t->post_ok('/user/login' => form => {
-  handle => 'test',
+  handle_or_email => 'test',
   pwd => 'pass',
   csrf_token => $csrf
 })
@@ -175,7 +175,7 @@
 is($fwd, '/?q=Baum&ql=poliqarp', 'Redirect is valid');
 
 $t->post_ok('/user/login' => form => {
-  handle => 'test',
+  handle_or_email => 'test',
   pwd => 'pass',
   csrf_token => $csrf,
   fwd => 'http://bad.example.com/test'
@@ -191,7 +191,7 @@
   ;
 
 $t->post_ok('/user/login' => form => {
-  handle => 'test',
+  handle_or_email => 'test',
   pwd => 'pass',
   csrf_token => $csrf,
   fwd => $fwd
diff --git a/t/plugin/query_reference.t b/t/plugin/query_reference.t
index 4fdcf09..56053c7 100644
--- a/t/plugin/query_reference.t
+++ b/t/plugin/query_reference.t
@@ -106,7 +106,7 @@
   ;
 
 $t->post_ok('/user/login' => form => {
-  handle => 'test',
+  handle_or_email => 'test',
   pwd => 'pass',
   csrf_token => $csrf
 })
diff --git a/t/subfolder.t b/t/subfolder.t
index f1e5730..88eba3a 100644
--- a/t/subfolder.t
+++ b/t/subfolder.t
@@ -19,7 +19,7 @@
 
 my $q = qr!(?:\"|")!;
 
-$t->post_ok('/user/login' => form => { handle => 'test', pwd => 'fail' })
+$t->post_ok('/user/login' => form => { handle_or_email => 'test', pwd => 'fail' })
   ->status_is(302)
   ->header_is('Location' => '/');
 
@@ -29,7 +29,7 @@
   ->element_exists('script[src^=/js/kalamar-]')
   ->element_exists('div.notify-error')
   ->text_is('div.notify-error', 'Bad CSRF token')
-  ->element_exists('input[name=handle][value=test]')
+  ->element_exists('input[name=handle_or_email][value=test]')
   ->element_exists_not('div.button.top a')
   ->attr_is('body','data-korap-url','')
   ->header_exists_not('Strict-Transport-Security')
@@ -50,7 +50,7 @@
   }
 });
 
-$t->post_ok('/user/login' => form => { handle => 'test', pwd => 'fail' })
+$t->post_ok('/user/login' => form => { handle_or_email => 'test', pwd => 'fail' })
   ->status_is(302)
   ->header_is('Location' => '/')
   ->header_is('Strict-Transport-Security', 'max-age=3600; includeSubDomains')
@@ -88,7 +88,7 @@
 is('kalamar-koraptest',$t->app->sessions->cookie_name);
 ok($t->app->sessions->secure);
 
-$t->post_ok('/user/login' => form => { handle => 'test', pwd => 'fail' })
+$t->post_ok('/user/login' => form => { handle_or_email => 'test', pwd => 'fail' })
   ->status_is(302)
   ->header_is('Location' => '/');