Developer Area

Changeset 639

Show
Ignore:
Timestamp:
01/12/10 12:51:19 (2 months ago)
Author:
henri
Message:

Better error handling in account management and login

Location:
apps/iphone/my.tel/trunk
Files:
5 modified

Legend:

Unmodified
Added
Removed
  • apps/iphone/my.tel/trunk/Classes/AccountEditController.m

    r626 r639  
    231231#pragma mark UITextFieldDelegate methods 
    232232 
     233- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range 
     234replacementString:(NSString *)string { 
     235        // Always reset the api root url if the domain name changes 
     236        if (textField == cellDomainName.textField) { 
     237                self.apiRootUrl = @""; 
     238                [cellApiRootUrl setNeedsDisplay]; 
     239        } 
     240        return YES; 
     241} 
     242 
    233243- (void)textFieldDidEndEditing:(UITextField *)textField { 
    234244        // Clean data entry as necessary 
     
    237247                        self.domainName = [self.domainName stringByAppendingString:@".tel"]; 
    238248                } 
    239                 if ([self.accountLabel length] == 0) { 
     249                if ((self.accountLabel == nil) || ([self.accountLabel length] == 0)) { 
    240250                        self.accountLabel = self.domainName; 
    241251                } 
     
    260270        [self performSelector:@selector(self) withObject:nil afterDelay:0.1]; 
    261271 
    262         if ([self.accountLabel length] == 0) { 
     272        if ((self.accountLabel == nil) || ([self.accountLabel length] == 0)) { 
    263273                self.accountLabel = self.domainName; 
     274        } 
     275        if (self.userName == nil) { 
     276                self.userName = @""; 
     277        } 
     278        if (self.password == nil) { 
     279                self.password = @""; 
    264280        } 
    265281         
  • apps/iphone/my.tel/trunk/Classes/MyTelConnect.m

    r612 r639  
    3939                                                 delegate:(id)aDelegate 
    4040                                                 selector:(SEL)aSel { 
     41         
     42        if ((aName == nil) || (aPassword == nil)) { 
     43                SBJSON *json = [[SBJSON new] autorelease]; 
     44                NSError *jsonError; 
     45                NSDictionary *parsedJSON = [json objectWithString:@"{\"success\":false;\"actionMessages\":\"bad username or password\"}" error:&jsonError]; 
     46                [aDelegate performSelector:aSel withObject:parsedJSON]; 
     47                return;          
     48        } 
    4149         
    4250        NSDictionary *loginInfo = [NSDictionary dictionaryWithObjectsAndKeys: 
  • apps/iphone/my.tel/trunk/Classes/RootViewController.h

    r612 r639  
    2929        NSString *dataFilePath; 
    3030        NSMutableArray *accountsArray; 
     31        NSUInteger currentDomainIndex;          // index of the current domain in the current account (set from the account view controller) 
     32@private 
     33        BOOL mustLogin; 
    3134        NSUInteger currentAccountIndex;         // accountsArray index of the account being edited or viewed 
    32         NSUInteger currentDomainIndex;          // index of the current domain in the current account (set from the account view controller) 
    3335} 
    3436 
  • apps/iphone/my.tel/trunk/Classes/RootViewController.m

    r626 r639  
    99#import "RootViewController.h" 
    1010 
     11@interface RootViewController (PrivateMethods) 
     12 
     13- (void)setCurrentAccountIndex:(NSUInteger)index; 
     14 
     15@end 
    1116 
    1217@implementation RootViewController 
     
    2429    if (self = [super initWithStyle:style]) { 
    2530                currentAccountIndex = NSUIntegerMax; 
     31                mustLogin = YES; 
    2632                [self loadData]; 
    2733    } 
     
    126132} 
    127133 
     134- (void)setCurrentAccountIndex:(NSUInteger)index { 
     135        if (index != currentAccountIndex) { 
     136                currentAccountIndex = index; 
     137                mustLogin = YES; 
     138        } 
     139} 
     140 
    128141- (void)loginToCurrentAccount { 
    129142        if (currentAccountIndex == NSUIntegerMax) { 
     
    132145                return; 
    133146        } 
    134         return [self loginToAccountAtIndex:currentAccountIndex forced:YES]; 
     147        return [self loginToAccountAtIndex:currentAccountIndex forced:mustLogin]; 
    135148} 
    136149 
    137150- (void)loginToAccountAtIndex:(NSUInteger)accountIndex forced:(BOOL)forced{ 
    138         if (forced || (accountIndex != currentAccountIndex)) { 
    139                 currentAccountIndex = accountIndex; 
     151        if (currentAccountIndex == NSUIntegerMax) 
     152                return; 
     153        [self setCurrentAccountIndex:accountIndex]; 
     154        if (forced || mustLogin) { 
    140155                NSDictionary *selectedAccount = [self.accountsArray objectAtIndex:currentAccountIndex]; 
    141156                [[[UIApplication sharedApplication] keyWindow] addSubview:[MyTelConnect sharedInstance].view]; 
     
    156171 
    157172        if ([[parsedJson valueForKey:@"success"] integerValue] == 1) { 
    158                 // Success. Go to account if there's no account, otherwise do nothing 
     173                // Success. Go to account if there's no account visible 
     174                mustLogin = NO; 
    159175                if (self.navigationController.topViewController == self) { 
    160176                        [self displayControllerForAccountAtIndex:currentAccountIndex]; 
     
    163179        } else { 
    164180                // Failed. Get back to the root 
    165                 currentAccountIndex = NSUIntegerMax; 
     181                NSDictionary *failedAccount = self.currentAccount; 
     182                [self setCurrentAccountIndex:NSUIntegerMax]; 
    166183                [self.navigationController popToRootViewControllerAnimated:NO]; 
     184                UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:[failedAccount objectForKey:@"accountLabel"] 
     185                                                                                                                        message:[[parsedJson valueForKey:@"actionErrors"] objectAtIndex:0] 
     186                                                                                                                   delegate:nil 
     187                                                                                                  cancelButtonTitle:NSLocalizedString(@"OK", nil) 
     188                                                                                                  otherButtonTitles:nil]; 
     189                [alertView show]; 
     190                [alertView release]; 
    167191        } 
    168192} 
     
    195219        NSArray *indexPaths = [NSArray arrayWithObject:[NSIndexPath indexPathForRow:currentAccountIndex inSection:kKRootTableViewSectionAccounts]]; 
    196220        [self.tableView deleteRowsAtIndexPaths:indexPaths withRowAnimation:UITableViewRowAnimationFade]; 
    197         currentAccountIndex = NSUIntegerMax; 
     221        [self setCurrentAccountIndex:NSUIntegerMax]; 
    198222        [self saveData]; 
    199223} 
     
    272296                case kKRootTableViewSectionAccounts: 
    273297                        if (self.tableView.editing) {   // in edit mode, open the account edit view 
    274                                 [self editAccountAtIndex:indexPath.row]; 
     298                                [self setCurrentAccountIndex:indexPath.row]; 
     299                                [self objectWillGetEditedInController:self]; 
    275300                        } else {        // in non-edit mode, login and move to the account 
    276301                                [self loginToAccountAtIndex:indexPath.row forced:NO]; 
     
    278303                        break; 
    279304                case kKRootTableViewSectionAddAccount: 
     305                        [self setCurrentAccountIndex:NSUIntegerMax]; 
    280306                        eVC = [[AccountEditController new] autorelease]; 
    281307                        eVC.delegate = self; 
     
    411437                } 
    412438                [self saveData]; 
     439                mustLogin = YES; 
    413440        } 
    414441} 
  • apps/iphone/my.tel/trunk/VIP.tel.xcodeproj/project.pbxproj

    r637 r639  
    10911091                                GCC_WARN_UNUSED_VARIABLE = YES; 
    10921092                                PREBINDING = NO; 
     1093                                PROVISIONING_PROFILE = "8073E846-129F-4458-A198-31367F83CF72"; 
    10931094                                SDKROOT = iphoneos3.0; 
    10941095                        }; 
Telnic
Search This Site
Partners
Neustar
ICANN
Main site | WHOIS | Sell .tel | FAQ | Archived Site | About Telnic | Contact Us