NanoTech

Don't disable the auth dialog login button, but ensure username and password are never nil.

@@ -17,12 +17,11 @@ typedef enum _ASIAuthenticationType { @@ -17,12 +17,11 @@ typedef enum _ASIAuthenticationType {
17 @interface ASIAutorotatingViewController : UIViewController 17 @interface ASIAutorotatingViewController : UIViewController
18 @end 18 @end
19 19
20 -@interface ASIAuthenticationDialog : ASIAutorotatingViewController <UIActionSheetDelegate, UITableViewDelegate, UITableViewDataSource, UITextFieldDelegate> { 20 +@interface ASIAuthenticationDialog : ASIAutorotatingViewController <UIActionSheetDelegate, UITableViewDelegate, UITableViewDataSource> {
21 ASIHTTPRequest *request; 21 ASIHTTPRequest *request;
22 ASIAuthenticationType type; 22 ASIAuthenticationType type;
23 UITableView *tableView; 23 UITableView *tableView;
24 UIViewController *presentingController; 24 UIViewController *presentingController;
25 - UIBarButtonItem *loginButton;  
26 } 25 }
27 + (void)presentAuthenticationDialogForRequest:(ASIHTTPRequest *)request; 26 + (void)presentAuthenticationDialogForRequest:(ASIHTTPRequest *)request;
28 + (void)presentProxyAuthenticationDialogForRequest:(ASIHTTPRequest *)request; 27 + (void)presentProxyAuthenticationDialogForRequest:(ASIHTTPRequest *)request;
@@ -39,7 +39,6 @@ static const NSUInteger kDomainSection = 1; @@ -39,7 +39,6 @@ static const NSUInteger kDomainSection = 1;
39 @interface ASIAuthenticationDialog () 39 @interface ASIAuthenticationDialog ()
40 - (void)show; 40 - (void)show;
41 @property (retain) UITableView *tableView; 41 @property (retain) UITableView *tableView;
42 -@property (retain) UIBarButtonItem *loginButton;  
43 @end 42 @end
44 43
45 @implementation ASIAuthenticationDialog 44 @implementation ASIAuthenticationDialog
@@ -95,7 +94,6 @@ static const NSUInteger kDomainSection = 1; @@ -95,7 +94,6 @@ static const NSUInteger kDomainSection = 1;
95 94
96 [request release]; 95 [request release];
97 [tableView release]; 96 [tableView release];
98 - [loginButton release];  
99 [presentingController.view removeFromSuperview]; 97 [presentingController.view removeFromSuperview];
100 [presentingController release]; 98 [presentingController release];
101 [super dealloc]; 99 [super dealloc];
@@ -209,10 +207,8 @@ static const NSUInteger kDomainSection = 1; @@ -209,10 +207,8 @@ static const NSUInteger kDomainSection = 1;
209 [navItem setTitle:[[[self request] url] host]]; 207 [navItem setTitle:[[[self request] url] host]];
210 } 208 }
211 209
212 - [self setLoginButton:[[UIBarButtonItem alloc] initWithTitle:@"Login" style:UIBarButtonItemStyleDone target:self action:@selector(loginWithCredentialsFromDialog:)]];  
213 [navItem setLeftBarButtonItem:[[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(cancelAuthenticationFromDialog:)] autorelease]]; 210 [navItem setLeftBarButtonItem:[[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(cancelAuthenticationFromDialog:)] autorelease]];
214 - [navItem setRightBarButtonItem:loginButton]; 211 + [navItem setRightBarButtonItem:[[[UIBarButtonItem alloc] initWithTitle:@"Login" style:UIBarButtonItemStyleDone target:self action:@selector(loginWithCredentialsFromDialog:)] autorelease]];
215 - loginButton.enabled = NO;  
216 212
217 // We show the login form in a table view, similar to Safari's authentication dialog 213 // We show the login form in a table view, similar to Safari's authentication dialog
218 [bar sizeToFit]; 214 [bar sizeToFit];
@@ -252,6 +248,9 @@ static const NSUInteger kDomainSection = 1; @@ -252,6 +248,9 @@ static const NSUInteger kDomainSection = 1;
252 NSString *username = [[self usernameField] text]; 248 NSString *username = [[self usernameField] text];
253 NSString *password = [[self passwordField] text]; 249 NSString *password = [[self passwordField] text];
254 250
  251 + if (username == nil) { username = @""; }
  252 + if (password == nil) { password = @""; }
  253 +
255 if ([self type] == ASIProxyAuthenticationType) { 254 if ([self type] == ASIProxyAuthenticationType) {
256 [[self request] setProxyUsername:username]; 255 [[self request] setProxyUsername:username];
257 [[self request] setProxyPassword:password]; 256 [[self request] setProxyPassword:password];
@@ -329,7 +328,6 @@ static const NSUInteger kDomainSection = 1; @@ -329,7 +328,6 @@ static const NSUInteger kDomainSection = 1;
329 [textField setAutoresizingMask:UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight]; 328 [textField setAutoresizingMask:UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight];
330 [textField setAutocapitalizationType:UITextAutocapitalizationTypeNone]; 329 [textField setAutocapitalizationType:UITextAutocapitalizationTypeNone];
331 [textField setAutocorrectionType:UITextAutocorrectionTypeNo]; 330 [textField setAutocorrectionType:UITextAutocorrectionTypeNo];
332 - [textField setDelegate:self];  
333 331
334 NSUInteger s = [indexPath section]; 332 NSUInteger s = [indexPath section];
335 NSUInteger r = [indexPath row]; 333 NSUInteger r = [indexPath row];
@@ -370,40 +368,9 @@ static const NSUInteger kDomainSection = 1; @@ -370,40 +368,9 @@ static const NSUInteger kDomainSection = 1;
370 return nil; 368 return nil;
371 } 369 }
372 370
373 -#pragma mark text field delegates  
374 -  
375 -- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string  
376 -{  
377 - NSString *newString = [[textField text] stringByReplacingCharactersInRange:range withString:string];  
378 - NSArray *fields = [NSArray arrayWithObjects:  
379 - [self usernameField],  
380 - [self passwordField],  
381 - [self domainField], // ends the array early if not set  
382 - nil];  
383 - BOOL allFilled = YES;  
384 -  
385 - for (UITextField *field in fields) {  
386 - NSString *text = nil;  
387 - if (field == textField) {  
388 - text = newString;  
389 - } else {  
390 - text = [field text];  
391 - }  
392 -  
393 - if ([text length] == 0) {  
394 - allFilled = NO;  
395 - break;  
396 - }  
397 - }  
398 -  
399 - loginButton.enabled = allFilled;  
400 - return YES;  
401 -}  
402 -  
403 #pragma mark - 371 #pragma mark -
404 372
405 @synthesize request; 373 @synthesize request;
406 @synthesize type; 374 @synthesize type;
407 @synthesize tableView; 375 @synthesize tableView;
408 -@synthesize loginButton;  
409 @end 376 @end