From: Errietta Kostala <errietta@errietta.me>
Date: Wed, 4 Feb 2015 14:34:04 +0000 (+0000)
Subject: Pass email along.
X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=1c65af4117a07fa1e9a80fa92b1409133c4edba8;p=scpubgit%2Fstemmaweb.git

Pass email along.
---

diff --git a/lib/Text/Tradition/Directory.pm b/lib/Text/Tradition/Directory.pm
index cb20c97..1727903 100644
--- a/lib/Text/Tradition/Directory.pm
+++ b/lib/Text/Tradition/Directory.pm
@@ -545,6 +545,7 @@ sub _find_gplus {
 
     my $sub = $userinfo->{sub};
     my $openid = $userinfo->{openid_id};
+    my $email = $userinfo->{email};
 
     # Do we have a user with the google id already?
 
@@ -567,12 +568,13 @@ sub _find_gplus {
     }
 
     my $new_user = $self->add_user({
-            username => $sub,
-            password => $user->password,
-            role     => $user->role,
-            active   => $user->active,
-            sub      => $sub,
+            username  => $sub,
+            password  => $user->password,
+            role      => $user->role,
+            active    => $user->active,
+            sub       => $sub,
             openid_id => $openid,
+            email     => $email,
         });
 
     foreach my $t (@{ $user->traditions }) {
diff --git a/lib/stemmaweb/Authentication/Credential/Google.pm b/lib/stemmaweb/Authentication/Credential/Google.pm
index 5a7e3d8..32f22c9 100644
--- a/lib/stemmaweb/Authentication/Credential/Google.pm
+++ b/lib/stemmaweb/Authentication/Credential/Google.pm
@@ -48,11 +48,17 @@ sub authenticate {
         Catalyst::Exception->throw("id_token not specified.");
     }
 
+    my $email = $authinfo->{email};
+    $email ||= $c->req->method eq 'GET' ? $c->req->query_params->{email} :
+    $c->req->body_params->{email};
+
     my $userinfo = $self->decode($id_token);
 
     my $sub = $userinfo->{sub};
     my $openid = $userinfo->{openid_id};
 
+    $userinfo->{email} = $email if $email;
+
     if (!$sub || !$openid) {
         Catalyst::Exception->throw(
             'Could not retrieve sub and openid from token! Is the token
diff --git a/t/07google.t b/t/07google.t
index 7816957..09a2c65 100644
--- a/t/07google.t
+++ b/t/07google.t
@@ -199,7 +199,7 @@ io("$FindBin::Bin/var")->rmtree if io("$FindBin::Bin/var")->exists;
 
     $ua->get('/');
 
-    $ua->content_contains('Hello! 4242!', 'We are logged in.');
+    $ua->content_contains('Hello! email@example.org!', 'We are logged in.');
 
     ok $dir->find_user({ sub => 4242, openid_id => 'https://www.google.com/accounts/o8/id3' }), 'The G+ user is there.';
 
@@ -219,7 +219,7 @@ io("$FindBin::Bin/var")->rmtree if io("$FindBin::Bin/var")->exists;
 
     $ua->get('/');
 
-    $ua->content_contains('Hello! 4242!', 'We are logged in.');
+    $ua->content_contains('Hello! email@example.org!', 'We ar logged in.');
 }
 
 io("$FindBin::Bin/var")->rmtree if io("$FindBin::Bin/var")->exists;