take username from email address as fallback
authorJoey Hess <joey@kitenet.net>
Wed, 23 Jun 2010 23:36:23 +0000 (19:36 -0400)
committerJoey Hess <joey@kitenet.net>
Wed, 23 Jun 2010 23:36:23 +0000 (19:36 -0400)
IkiWiki/Plugin/openid.pm

index f4ba8db189c8bcb6e0c3592c55fee760430c73c8..f19a559a9e325d2bac6e1309a124e9ed22ed7ac1 100644 (file)
@@ -187,12 +187,17 @@ sub auth ($$) {
                                        $vident->signed_extension_fields('http://openid.net/srv/ax/1.0'),
                                );
                        }
+                       my $username;
                        foreach my $ext (@extensions) {
                                foreach my $field (qw{value.email email}) {
                                        if (exists $ext->{$field} &&
                                            defined $ext->{$field} &&
                                            length $ext->{$field}) {
                                                $session->param(email => $ext->{$field});
+                                               if (! defined $username &&
+                                                   $ext->{$field}=~/(.+)@.+/) {
+                                                       $username = $1;
+                                               }
                                                last;
                                        }
                                }
@@ -200,11 +205,15 @@ sub auth ($$) {
                                        if (exists $ext->{$field} &&
                                            defined $ext->{$field} &&
                                            length $ext->{$field}) {
-                                               $session->param(username => $ext->{$field});
+                                               $username=$ext->{$field};
                                                last;
                                        }
                                }
                        }
+                       if (defined $username) {
+                               $username=~s/\s+/_/g;
+                               $session->param(username => $username);
+                       }
                }
                else {
                        error("OpenID failure: ".$csr->err);