Created
July 29, 2010 07:46
-
-
Save CastIrony/497538 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-(void)authenticateWithEmail:(NSString*)email password:(NSString*)password retries:(int)retries andThen:(BasicBlock)work | |
{ | |
NSString* urlString = @"https://www.google.com/accounts/ClientLogin"; | |
NSMutableDictionary* requestParameters = [NSMutableDictionary dictionary]; | |
[requestParameters setObject:email forKey:@"Email"]; | |
[requestParameters setObject:password forKey:@"Passwd"]; | |
[NSURLConnection postToUrlString:urlString withParameters:requestParameters completionBlock:^(NSData* data, NSURLResponse* response, NSError* error) | |
{ | |
NSString* dataString = [NSString stringWithUTF8String:[data bytes]]; | |
if([dataString hasPrefix:@"SID="]) | |
{ | |
NSString* sid = [[[dataString componentsSeparatedByString:@"\n"] objectAtIndex:0] substringFromIndex:4]; | |
[NSHTTPCookieStorage setCookieWithName:@"SID" value:sid origin:urlString]; | |
RunOnMainThread(work); | |
} | |
else if(retries > 0) | |
{ | |
NSLog(@"Authentication failed, %i retries left", retries); | |
RunAfterDelay(0.2, ^{ [self authenticateWithEmail:email password:password retries:(retries - 1) andThen:work]; }); | |
} | |
else | |
{ | |
NSLog(@"Authentication failed for good"); | |
} | |
}]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-(void)authenticateWithEmail:(NSString *)email password:(NSString *)password retries:(int)retries andThen:(BasicBlock)work {
NSString *urlString = @"https://www.google.com/accounts/ClientLogin";
}