[Bps-public-commit] r18284 - in Net-Google-Code/branches/write: .

sunnavy at bestpractical.com sunnavy at bestpractical.com
Mon Feb 9 01:48:41 EST 2009


Author: sunnavy
Date: Mon Feb  9 01:48:41 2009
New Revision: 18284

Modified:
   Net-Google-Code/branches/write/   (props changed)
   Net-Google-Code/branches/write/lib/Net/Google/Code/Role/Authentication.pm

Log:
 r19693 at sunnavys-mb:  sunnavy | 2009-02-09 13:03:08 +0800
 improvement authentication


Modified: Net-Google-Code/branches/write/lib/Net/Google/Code/Role/Authentication.pm
==============================================================================
--- Net-Google-Code/branches/write/lib/Net/Google/Code/Role/Authentication.pm	(original)
+++ Net-Google-Code/branches/write/lib/Net/Google/Code/Role/Authentication.pm	Mon Feb  9 01:48:41 2009
@@ -16,11 +16,21 @@
 
 sub signin {
     my $self = shift;
+    return 1 if $self->signed_in;
     $self->ask_password unless $self->password && length $self->password;
 
-    $self->mech->follow_link(
-        url_regex => qr!^https?://www\.google\.com/accounts/Login! )
-      || $self->mech->get('https://www.google.com/accounts/Login');
+    my $already_in_google;
+    if (
+        $self->mech->follow_link(
+            url_regex => qr!^https?://www\.google\.com/accounts/Login!
+        )
+      )
+    {
+        $already_in_google = 1;
+    }
+    else {
+        $self->mech->get('https://www.google.com/accounts/Login');
+    }
 
     $self->mech->submit_form(
         with_fields => {
@@ -30,7 +40,8 @@
     );
 
     die 'signin failed to google code'
-      unless $self->mech->content =~ m!Sign Out!;
+      unless ( $already_in_google && $self->mech->uri =~ /CheckCookie/ )
+      || ( !$already_in_google && $self->mech->content =~ /Sign Out/ );
 
     return 1;
 }
@@ -62,7 +73,8 @@
 sub signed_in {
     my $self = shift;
     return 1
-      if $self->mech->uri =~ m!https?://[-\w]+\.google\.com/!
+      if $self->mech->content
+          && $self->mech->uri =~ m!https?://[-\w]+\.google\.com/!
           && $self->mech->content =~ /Sign Out/;
     return;
 }



More information about the Bps-public-commit mailing list