Ben Copsey

Bug fixes and tweaks

... ... @@ -55,21 +55,40 @@ NSLock *dialogLock = nil;
[[self loginDialog] setDelegate:self];
// We show the login form in a table view, similar to Safari's authentication dialog
UITableView *table = [[[UITableView alloc] initWithFrame:CGRectMake(0,50,320,480) style:UITableViewStyleGrouped] autorelease];
UITableView *table = [[[UITableView alloc] initWithFrame:CGRectMake(0,80,320,480) style:UITableViewStyleGrouped] autorelease];
[table setDelegate:self];
[table setDataSource:self];
[[self loginDialog] addSubview:table];
[[self loginDialog] showInView:[[[UIApplication sharedApplication] windows] objectAtIndex:0]];
[[self loginDialog] setFrame:CGRectMake(0,0,320,480)];
UIToolbar *toolbar = [[[UIToolbar alloc] initWithFrame:CGRectMake(0,0,320,80)] autorelease];
//[toolbar setFrame:CGRectMake(0,20,320,50)];
// Setup the title (Couldn't figure out how to put this in the same toolbar as the buttons)
UIToolbar *titleBar = [[[UIToolbar alloc] initWithFrame:CGRectMake(0,0,320,30)] autorelease];
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(10,0,300,30)];
if ([self type] == ASIProxyAuthenticationType) {
[label setText:@"Login to this secure proxy server."];
} else {
[label setText:@"Login to this secure server."];
}
[label setTextColor:[UIColor blackColor]];
[label setFont:[UIFont systemFontOfSize:13.0]];
[label setShadowColor:[UIColor colorWithRed:1 green:1 blue:1 alpha:0.5]];
[label setShadowOffset:CGSizeMake(0, 1.0)];
[label setOpaque:NO];
[label setBackgroundColor:nil];
[label setTextAlignment:UITextAlignmentCenter];
[titleBar addSubview:label];
[[self loginDialog] addSubview:titleBar];
// Setup the toolbar
UIToolbar *toolbar = [[[UIToolbar alloc] initWithFrame:CGRectMake(0,30,320,50)] autorelease];
NSMutableArray *items = [[[NSMutableArray alloc] init] autorelease];
UIBarButtonItem *backButton = [[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(cancelAuthenticationFromDialog:)] autorelease];
//[backButton setContentEdgeInsets:UIEdgeInsetsMake(0,20,0,0)];
[items addObject:backButton];
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0,0,170,50)];
label = [[UILabel alloc] initWithFrame:CGRectMake(0,0,170,50)];
[label setText:[[[self request] url] host]];
[label setTextColor:[UIColor whiteColor]];
[label setFont:[UIFont boldSystemFontOfSize:22.0]];
... ... @@ -80,14 +99,19 @@ NSLock *dialogLock = nil;
[label setTextAlignment:UITextAlignmentCenter];
[toolbar addSubview:label];
UIBarButtonItem *labelButton = [[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:nil action:nil] autorelease];
//[labelButton setCustomView:label];
//[items addObject:labelButton];
UIBarButtonItem *labelButton = [[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:nil action:nil] autorelease];
[labelButton setCustomView:label];
[items addObject:labelButton];
[items addObject:[[[UIBarButtonItem alloc] initWithTitle:@"Login" style:UIBarButtonItemStyleDone target:self action:@selector(loginWithCredentialsFromDialog:)] autorelease]];
[toolbar setItems:items];
[[self loginDialog] addSubview:toolbar];
// Force reload the table content, and focus the first field to show the keyboard
[table reloadData];
[[[[table cellForRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]] subviews] objectAtIndex:2] becomeFirstResponder];
}
- (void)cancelAuthenticationFromDialog:(id)sender
... ... @@ -164,10 +188,12 @@ NSLock *dialogLock = nil;
- (NSString *)tableView:(UITableView *)tableView titleForFooterInSection:(NSInteger)section
{
if (section == [self numberOfSectionsInTableView:tableView]-1) {
if ([[[[self request] url] scheme] isEqualToString:@"https"]) {
return @"Password will be sent securely.";
} else {
// If we're using Basic authentication and the connection is not using SSL, we'll show the plain text message
if ([[[self request] authenticationScheme] isEqualToString:(NSString *)kCFHTTPAuthenticationSchemeBasic] && ![[[[self request] url] scheme] isEqualToString:@"https"]) {
return @"Password will be sent in the clear.";
// We are using Digest, NTLM, or any scheme over SSL
} else {
return @"Password will be sent securely.";
}
}
return nil;
... ...
... ... @@ -267,26 +267,32 @@
[ASIHTTPRequest setProgress:progress forProgressIndicator:[self downloadProgressDelegate]];
}
// Since this queue takes over as the delegate for all requests it contains, it should forward authorisation requests to its own delegate
- (void)authorizationNeededForRequest:(ASIHTTPRequest *)request
- (void)authenticationNeededForRequest:(ASIHTTPRequest *)request
{
if ([[self delegate] respondsToSelector:@selector(authorizationNeededForRequest:)]) {
[[self delegate] performSelector:@selector(authorizationNeededForRequest:) withObject:request];
if ([[self delegate] respondsToSelector:@selector(authenticationNeededForRequest:)]) {
[[self delegate] performSelector:@selector(authenticationNeededForRequest:) withObject:request];
}
}
- (void)proxyAuthorizationNeededForRequest:(ASIHTTPRequest *)request
- (void)proxyAuthenticationNeededForRequest:(ASIHTTPRequest *)request
{
if ([[self delegate] respondsToSelector:@selector(proxyAuthorizationNeededForRequest:)]) {
[[self delegate] performSelector:@selector(proxyAuthorizationNeededForRequest:) withObject:request];
if ([[self delegate] respondsToSelector:@selector(proxyAuthenticationNeededForRequest:)]) {
[[self delegate] performSelector:@selector(proxyAuthenticationNeededForRequest:) withObject:request];
}
}
- (BOOL)respondsToSelector:(SEL)selector
{
if (selector == @selector(authorizationNeededForRequest:)) {
if ([[self delegate] respondsToSelector:@selector(authorizationNeededForRequest:)]) {
if (selector == @selector(authenticationNeededForRequest:)) {
if ([[self delegate] respondsToSelector:@selector(authenticationNeededForRequest:)]) {
return YES;
}
return NO;
} else if (selector == @selector(proxyAuthenticationNeededForRequest:)) {
if ([[self delegate] respondsToSelector:@selector(proxyAuthenticationNeededForRequest:)]) {
return YES;
}
return NO;
... ...
... ... @@ -355,7 +355,7 @@ IMPORTANT
}
- (void)authorizationNeededForRequest:(ASIHTTPRequest *)request
- (void)authenticationNeededForRequest:(ASIHTTPRequest *)request
{
// We're using this method in multiple tests:
// testProgressWithAuthentication will set a userInfo dictionary on the main request, to tell us not to supply credentials
... ...
... ... @@ -45,31 +45,31 @@
[topSecretInfo setFont:[UIFont boldSystemFontOfSize:12]];
}
//- (void)authorizationNeededForRequest:(ASIHTTPRequest *)request
//{
// // Why oh why is there no contextInfo for alertView like on Mac OS ?!
// [self setRequestRequiringProxyAuthentication:nil];
// [self setRequestRequiringAuthentication:request];
//
// [ASIHTTPRequest showAuthenticationDialogForRequest:request];
//
// //UIAlertView *alertView = [[[UIAlertView alloc] initWithTitle:@"Please Login" message:[request authenticationRealm] delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"OK",nil] autorelease];
// // These are undocumented, use at your own risk!
// // A better general approach would be to subclass UIAlertView
// //[alertView addTextFieldWithValue:@"" label:@"Username"];
// //[alertView addTextFieldWithValue:@"" label:@"Password"];
//
//}
//
//- (void)proxyAuthorizationNeededForRequest:(ASIHTTPRequest *)request
//{
// [self setRequestRequiringAuthentication:nil];
// [self setRequestRequiringProxyAuthentication:request];
// UIAlertView *alertView = [[[UIAlertView alloc] initWithTitle:@"Please Login to proxy" message:[request authenticationRealm] delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"OK",nil] autorelease];
// [alertView addTextFieldWithValue:@"" label:@"Username"];
// [alertView addTextFieldWithValue:@"" label:@"Password"];
// [alertView show];
//}
- (void)authenticationNeededForRequest:(ASIHTTPRequest *)request
{
// Why oh why is there no contextInfo for alertView like on Mac OS ?!
[self setRequestRequiringProxyAuthentication:nil];
[self setRequestRequiringAuthentication:request];
UIAlertView *alertView = [[[UIAlertView alloc] initWithTitle:@"Please Login" message:[request authenticationRealm] delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"OK",nil] autorelease];
// These are undocumented, use at your own risk!
// A better general approach would be to subclass UIAlertView, or just use ASIHTTPRequest's built-in dialog
[alertView addTextFieldWithValue:@"" label:@"Username"];
[alertView addTextFieldWithValue:@"" label:@"Password"];
[alertView show];
}
- (void)proxyAuthenticationNeededForRequest:(ASIHTTPRequest *)request
{
[self setRequestRequiringAuthentication:nil];
[self setRequestRequiringProxyAuthentication:request];
UIAlertView *alertView = [[[UIAlertView alloc] initWithTitle:@"Please Login to proxy" message:[request authenticationRealm] delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"OK",nil] autorelease];
[alertView addTextFieldWithValue:@"" label:@"Username"];
[alertView addTextFieldWithValue:@"" label:@"Password"];
[alertView show];
}
... ... @@ -86,14 +86,22 @@
[[self requestRequiringProxyAuthentication] retryWithAuthentication];
}
} else {
if ([self requestRequiringAuthentication]) {
[[self requestRequiringAuthentication] cancelLoad];
} else {
[[self requestRequiringProxyAuthentication] cancelLoad];
[[self requestRequiringAuthentication] cancelAuthentication];
}
}
- (BOOL)respondsToSelector:(SEL)selector
{
if (selector == @selector(authenticationNeededForRequest:) || selector == @selector(proxyAuthenticationNeededForRequest:)) {
if ([useBuiltInDialog isOn]) {
return NO;
}
return YES;
}
return [super respondsToSelector:selector];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
}
... ...