Check if the dir exists before getting rid of it
[scpubgit/stemmaweb.git] / lib / Text / Tradition / Directory.pm
index a6101e3..cb20c97 100644 (file)
@@ -440,10 +440,14 @@ 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" )
-               unless ( $self->validate_password($password) || $username =~ /^https?:/ );
+               unless ( $self->validate_password($password) || $username =~ /^https?:/  || exists ($userinfo->{openid_id}) || exists ($userinfo->{sub}));
 
     my $user = Text::Tradition::User->new(
         id => $username,
@@ -559,7 +563,7 @@ sub _find_gplus {
         });
 
     if (!$user) {
-        throw ("Could not find a user with that openid or sub!");
+        return undef;
     }
 
     my $new_user = $self->add_user({
@@ -567,6 +571,8 @@ sub _find_gplus {
             password => $user->password,
             role     => $user->role,
             active   => $user->active,
+            sub      => $sub,
+            openid_id => $openid,
         });
 
     foreach my $t (@{ $user->traditions }) {