Don't delete old users
[scpubgit/stemmaweb.git] / lib / Text / Tradition / Directory.pm
index 078127c..c669bd8 100644 (file)
@@ -440,6 +440,10 @@ sub add_user {
     my $password = $userinfo->{password};
     my $role = $userinfo->{role} || 'user';
 
+    if ($userinfo->{sub}) {
+        $username = $userinfo->{sub};
+    }
+
        throw( "No username given" ) unless $username;
        throw( "Invalid password - must be at least " . $self->MIN_PASS_LEN 
                . " characters long" )
@@ -541,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?
 
@@ -559,23 +564,24 @@ sub _find_gplus {
         });
 
     if (!$user) {
-        throw ("Could not find a user with that openid or sub!");
+        return undef;
     }
 
     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 }) {
         $new_user->add_tradition($t);
     }
 
-    $self->delete_user({ username => $user->id });
+    # $self->delete_user({ username => $user->id });
     return $new_user;
 }