Skip to content

Commit

Permalink
Merge pull request dennisreimann#105 from aharren/master
Browse files Browse the repository at this point in the history
missing login/password should not map to nil
  • Loading branch information
Dennis Reimann committed Jun 9, 2011
2 parents 75be84c + d692e17 commit cf5f247
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions Classes/LoginController.m
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@


@interface LoginController ()
+ (NSString *)stringFromUserDefaults:(NSUserDefaults *)defaults forKey:(NSString *)key defaultsTo:(NSString *)defaultValue;
- (void)presentLogin;
- (void)dismissLogin;
- (void)showAuthenticationSheet;
Expand All @@ -21,6 +22,11 @@ @implementation LoginController
@synthesize delegate;
@synthesize user;

+ (NSString *)stringFromUserDefaults:(NSUserDefaults *)defaults forKey:(NSString *)key defaultsTo:(NSString *)defaultValue {
NSString *value = [defaults stringForKey:key];
return value != nil ? value : defaultValue;
}

- (id)initWithViewController:(UIViewController *)theViewController {
[super initWithNibName:@"Login" bundle:nil];
viewController = theViewController;
Expand All @@ -30,8 +36,8 @@ - (id)initWithViewController:(UIViewController *)theViewController {
- (void)viewDidLoad {
[super viewDidLoad];
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
loginField.text = [defaults valueForKey:kLoginDefaultsKey];
passwordField.text = [defaults valueForKey:kPasswordDefaultsKey];
loginField.text = [LoginController stringFromUserDefaults:defaults forKey:kLoginDefaultsKey defaultsTo:@""];
passwordField.text = [LoginController stringFromUserDefaults:defaults forKey:kPasswordDefaultsKey defaultsTo:@""];
loginField.clearButtonMode = UITextFieldViewModeWhileEditing;
passwordField.clearButtonMode = UITextFieldViewModeWhileEditing;
}
Expand Down Expand Up @@ -100,7 +106,7 @@ - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(N
[self finishAuthenticating];
} else {
[self presentLogin];
[self failWithMessage:@"Please ensure that you are connected to the internet and that your login and API token are correct"];
[self failWithMessage:@"Please ensure that you are connected to the internet and that your login and password are correct"];
}
}
}
Expand Down

0 comments on commit cf5f247

Please sign in to comment.