From 10386e566716ccde73a30f2016c004b5ec0ef4d5 Mon Sep 17 00:00:00 2001 From: Vineet Choudhary Date: Wed, 26 Dec 2018 17:56:32 +0530 Subject: [PATCH 1/3] Fixed account crash if user id is nil --- AppBox/Common/ITCLoginClient/ITCLogin.m | 2 +- .../Common/KeychainHandler/KeychainHandler.h | 1 + .../Common/KeychainHandler/KeychainHandler.m | 12 +++++++++ .../ITCLoginViewController.m | 27 ++++++++++++++++++- .../AccountPreferencesViewController.m | 2 +- .../ViewController/Storyboard/Main.storyboard | 11 +++----- 6 files changed, 45 insertions(+), 10 deletions(-) diff --git a/AppBox/Common/ITCLoginClient/ITCLogin.m b/AppBox/Common/ITCLoginClient/ITCLogin.m index 98592c74..afd8079a 100644 --- a/AppBox/Common/ITCLoginClient/ITCLogin.m +++ b/AppBox/Common/ITCLoginClient/ITCLogin.m @@ -10,7 +10,7 @@ #define ITCStatsURL @"https://olympus.itunes.apple.com/itc/ui/stats" #define ITCLoginURL @"https://idmsa.apple.com/appleauth/auth/signin?widgetKey=" -#define ITCLoginControlURL @"https://itunesconnect.apple.com/itc/static-resources/controllers/login_cntrl.js" +#define ITCLoginControlURL @"https://appstoreconnect.apple.com/itc/static-resources/controllers/login_cntrl.js" #define ITCServiceKeyStartIdentifier @"var itcServiceKey = '" #define ITCServiceKeyEndIdentifier @"'" diff --git a/AppBox/Common/KeychainHandler/KeychainHandler.h b/AppBox/Common/KeychainHandler/KeychainHandler.h index 3a527b44..22e83983 100644 --- a/AppBox/Common/KeychainHandler/KeychainHandler.h +++ b/AppBox/Common/KeychainHandler/KeychainHandler.h @@ -11,6 +11,7 @@ @interface KeychainHandler : NSObject + (NSArray *)getAllTeamId; ++ (NSArray *)getAllITCAccounts; + (void)removeAllStoredCredentials; + (void)installPrivateKeyFromPath:(NSString *)path withPassword:(NSString *)password; diff --git a/AppBox/Common/KeychainHandler/KeychainHandler.m b/AppBox/Common/KeychainHandler/KeychainHandler.m index e51d4d9a..5463b5c4 100644 --- a/AppBox/Common/KeychainHandler/KeychainHandler.m +++ b/AppBox/Common/KeychainHandler/KeychainHandler.m @@ -123,6 +123,18 @@ + (NSDictionary *)valuesWithCertificate:(id)certificate keys:(NSArray *)keys err return result; } +#pragma mark - ITC Accounts ++ (NSArray *)getAllITCAccounts { + NSMutableArray *filteredITCAccounts = [[NSMutableArray alloc] init]; + NSArray *itcAccounts = [SAMKeychain accountsForService:abiTunesConnectService]; + for (NSDictionary *account in itcAccounts) { + if ([account.allKeys containsObject:kSAMKeychainAccountKey]) { + [filteredITCAccounts addObject:account]; + } + } + return filteredITCAccounts; +} + #pragma mark - Install Certificates + (void)installPrivateKeyFromPath:(NSString *)path withPassword:(NSString *)password { NSMutableArray *arguments = [[NSMutableArray alloc] initWithObjects:path, nil]; diff --git a/AppBox/ViewController/ITCLoginViewController/ITCLoginViewController.m b/AppBox/ViewController/ITCLoginViewController/ITCLoginViewController.m index aee2ceb1..2af535bf 100644 --- a/AppBox/ViewController/ITCLoginViewController/ITCLoginViewController.m +++ b/AppBox/ViewController/ITCLoginViewController/ITCLoginViewController.m @@ -22,7 +22,8 @@ - (void)viewDidLoad { [EventTracker logScreen:@"Apple Developer Login"]; //Load iTunes UserName and password - itcAccounts = [SAMKeychain accountsForService:abiTunesConnectService]; + itcAccounts = [KeychainHandler getAllITCAccounts]; + if (itcAccounts.count > 0){ [self selectITCAccountAtIndex:0]; } @@ -42,6 +43,10 @@ - (void)viewDidLoad { #pragma mark - Controls actions - (IBAction)buttonLoginTapped:(NSButton *)sender{ [[textFieldPassword window] makeFirstResponder:self.view]; + if (![self isValidDetails]) { + return; + } + [self showProgress:YES]; [ITCLogin loginWithUserName:textFieldUserName.stringValue andPassword:textFieldPassword.stringValue completion:^(bool success, NSString *message) { [self showProgress:NO]; @@ -65,6 +70,10 @@ - (IBAction)buttonLoginTapped:(NSButton *)sender{ - (IBAction)buttonUseWithoutLoginTapped:(NSButton *)sender { [[textFieldPassword window] makeFirstResponder:self.view]; + if (![self isValidDetails]) { + return; + } + NSAlert *alert = [[NSAlert alloc] init]; [alert setMessageText: @"Warning"]; [alert setInformativeText:@"Please make sure Username/Email and Password correct. Because AppBox would not verify with AppStore."]; @@ -132,4 +141,20 @@ - (void)showProgress:(BOOL)progress{ } } +-(BOOL)isValidDetails { + NSString *userName = [textFieldUserName stringValue]; + NSString *password = [textFieldPassword stringValue]; + + if (userName && !userName.isEmpty && [MailHandler isValidEmail:userName]) { + if (password && !password.isEmpty) { + return YES; + } else { + [Common showAlertWithTitle:nil andMessage:@"Please enter a Password."]; + } + } else { + [Common showAlertWithTitle:nil andMessage:@"Please enter a valid AppStore Connect email."]; + } + return NO; +} + @end diff --git a/AppBox/ViewController/PreferencesViewController/AccountPreferencesViewController/AccountPreferencesViewController.m b/AppBox/ViewController/PreferencesViewController/AccountPreferencesViewController/AccountPreferencesViewController.m index f4d48c64..b55b2cab 100644 --- a/AppBox/ViewController/PreferencesViewController/AccountPreferencesViewController/AccountPreferencesViewController.m +++ b/AppBox/ViewController/PreferencesViewController/AccountPreferencesViewController/AccountPreferencesViewController.m @@ -22,7 +22,7 @@ - (void)viewDidLoad { } -(void)loadAccounts{ - itcAccounts = [SAMKeychain accountsForService:abiTunesConnectService]; + itcAccounts = [KeychainHandler getAllITCAccounts]; } #pragma mark - AccountPreferencesViewController Delegate diff --git a/AppBox/ViewController/Storyboard/Main.storyboard b/AppBox/ViewController/Storyboard/Main.storyboard index 9b21cca9..be35048f 100644 --- a/AppBox/ViewController/Storyboard/Main.storyboard +++ b/AppBox/ViewController/Storyboard/Main.storyboard @@ -1,8 +1,8 @@ - + - + @@ -1042,9 +1042,6 @@ DQ - -Gw - @@ -2214,7 +2211,7 @@ Gw - - + + From e4b589cccbb41ff9fa05c754b65363d676037355 Mon Sep 17 00:00:00 2001 From: Vineet Choudhary Date: Wed, 26 Dec 2018 18:54:51 +0530 Subject: [PATCH 2/3] Added account delete and update option --- .../ITCLoginViewController.h | 2 + .../ITCLoginViewController.m | 48 +++++++++++++------ .../AccountPreferencesViewController.h | 4 +- .../AccountPreferencesViewController.m | 22 ++++++++- .../AccountPreferencesViewController.xib | 19 ++++++-- 5 files changed, 75 insertions(+), 20 deletions(-) diff --git a/AppBox/ViewController/ITCLoginViewController/ITCLoginViewController.h b/AppBox/ViewController/ITCLoginViewController/ITCLoginViewController.h index c2673914..7e914f26 100644 --- a/AppBox/ViewController/ITCLoginViewController/ITCLoginViewController.h +++ b/AppBox/ViewController/ITCLoginViewController/ITCLoginViewController.h @@ -30,6 +30,8 @@ @property(nonatomic, strong) XCProject *project; @property(weak) id delegate; +@property(nonatomic, strong) NSNumber *isNewAccount; +@property(nonatomic, strong) NSString *editAccountKey; - (IBAction)buttonLoginTapped:(NSButton *)sender; - (IBAction)buttonCancelTapped:(NSButton *)sender; diff --git a/AppBox/ViewController/ITCLoginViewController/ITCLoginViewController.m b/AppBox/ViewController/ITCLoginViewController/ITCLoginViewController.m index 2af535bf..27f4517a 100644 --- a/AppBox/ViewController/ITCLoginViewController/ITCLoginViewController.m +++ b/AppBox/ViewController/ITCLoginViewController/ITCLoginViewController.m @@ -21,23 +21,41 @@ - (void)viewDidLoad { [super viewDidLoad]; [EventTracker logScreen:@"Apple Developer Login"]; - //Load iTunes UserName and password - itcAccounts = [KeychainHandler getAllITCAccounts]; - - if (itcAccounts.count > 0){ - [self selectITCAccountAtIndex:0]; - } - - //check for multiple account available in keychain - BOOL isMultipleAccounts = itcAccounts.count > 1; - [comboUserName setHidden:!isMultipleAccounts]; - [textFieldUserName setHidden:isMultipleAccounts]; - if (isMultipleAccounts) { - for (NSDictionary *itcAccount in itcAccounts) { - [comboUserName addItemWithObjectValue:[itcAccount valueForKey:kSAMKeychainAccountKey]]; + if (self.isNewAccount) { + itcAccounts = [[NSArray alloc] init]; + [comboUserName setHidden:YES]; + [textFieldUserName setHidden:NO]; + } else { + //Load iTunes UserName and password + itcAccounts = [KeychainHandler getAllITCAccounts]; + + NSInteger selectedAccountIndex = 0; + if (self.editAccountKey && !self.editAccountKey.isEmpty) { + selectedAccountIndex = [itcAccounts indexOfObjectPassingTest:^BOOL(NSDictionary* _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) { + return [[obj valueForKey:kSAMKeychainAccountKey] isEqualToString:self.editAccountKey]; + }]; + } else if (itcAccounts.count > 0){ + selectedAccountIndex = 0; + } + + //check for multiple account available in keychain + BOOL isMultipleAccounts = itcAccounts.count > 1; + [comboUserName setHidden:!isMultipleAccounts]; + [textFieldUserName setHidden:isMultipleAccounts]; + if (isMultipleAccounts) { + for (NSDictionary *itcAccount in itcAccounts) { + [comboUserName addItemWithObjectValue:[itcAccount valueForKey:kSAMKeychainAccountKey]]; + } + } + + if (itcAccounts.count > selectedAccountIndex) { + [self selectITCAccountAtIndex: selectedAccountIndex]; + if (isMultipleAccounts) { + [comboUserName selectItemAtIndex: selectedAccountIndex]; + } } - [comboUserName selectItemAtIndex:0]; } + } #pragma mark - Controls actions diff --git a/AppBox/ViewController/PreferencesViewController/AccountPreferencesViewController/AccountPreferencesViewController.h b/AppBox/ViewController/PreferencesViewController/AccountPreferencesViewController/AccountPreferencesViewController.h index 8a399afc..f61345e1 100644 --- a/AppBox/ViewController/PreferencesViewController/AccountPreferencesViewController/AccountPreferencesViewController.h +++ b/AppBox/ViewController/PreferencesViewController/AccountPreferencesViewController/AccountPreferencesViewController.h @@ -19,10 +19,12 @@ __weak IBOutlet NSTextField *accountIdLabel; __weak IBOutlet NSTextField *accountDescLabel; __weak IBOutlet NSButton *addAccountButton; - __weak IBOutlet NSButton *deleteAccount; + __weak IBOutlet NSButton *deleteAccountButton; + __weak IBOutlet NSButton *updateAccountButton; } - (IBAction)addAccountButtonTapped:(NSButton *)sender; - (IBAction)deleteAccountButtonTapped:(NSButton *)sender; +- (IBAction)updateAccountButtonTapped:(NSButton *)sender; @end diff --git a/AppBox/ViewController/PreferencesViewController/AccountPreferencesViewController/AccountPreferencesViewController.m b/AppBox/ViewController/PreferencesViewController/AccountPreferencesViewController/AccountPreferencesViewController.m index b55b2cab..cab5d3cc 100644 --- a/AppBox/ViewController/PreferencesViewController/AccountPreferencesViewController/AccountPreferencesViewController.m +++ b/AppBox/ViewController/PreferencesViewController/AccountPreferencesViewController/AccountPreferencesViewController.m @@ -54,7 +54,26 @@ - (IBAction)addAccountButtonTapped:(NSButton *)sender { } - (IBAction)deleteAccountButtonTapped:(NSButton *)sender { - + NSInteger selectedRow = [accountTableView selectedRow]; + if (selectedRow >= 0) { + NSDictionary *keyChainAccount = [NSDictionary dictionaryWithDictionary:[itcAccounts objectAtIndex:selectedRow]]; + [SAMKeychain deletePasswordForService:abiTunesConnectService account:[keyChainAccount valueForKey:kSAMKeychainAccountKey]]; + } + [self loadAccounts]; + [accountTableView reloadData]; +} + +- (IBAction)updateAccountButtonTapped:(NSButton *)sender { + NSInteger selectedRow = [accountTableView selectedRow]; + if (selectedRow >= 0) { + NSDictionary *keyChainAccount = [NSDictionary dictionaryWithDictionary:[itcAccounts objectAtIndex:selectedRow]]; + + NSStoryboard *storyBoard = [NSStoryboard storyboardWithName:@"Main" bundle:nil]; + ITCLoginViewController *itcLoginViewController = [storyBoard instantiateControllerWithIdentifier:NSStringFromClass([ITCLoginViewController class])]; + itcLoginViewController.editAccountKey = [keyChainAccount valueForKey:kSAMKeychainAccountKey]; + itcLoginViewController.delegate = self; + [self presentViewControllerAsSheet:itcLoginViewController]; + } } #pragma mark - SelectAccountViewController Delegate @@ -68,6 +87,7 @@ -(void)selectedAccountType:(AccountType)accountType{ case AccountTypeITC: { ITCLoginViewController *itcLoginViewController = [storyBoard instantiateControllerWithIdentifier:NSStringFromClass([ITCLoginViewController class])]; + itcLoginViewController.isNewAccount = @YES; itcLoginViewController.delegate = self; [self presentViewControllerAsSheet:itcLoginViewController]; }break; diff --git a/AppBox/ViewController/PreferencesViewController/AccountPreferencesViewController/AccountPreferencesViewController.xib b/AppBox/ViewController/PreferencesViewController/AccountPreferencesViewController/AccountPreferencesViewController.xib index afb6eaa2..b3537764 100644 --- a/AppBox/ViewController/PreferencesViewController/AccountPreferencesViewController/AccountPreferencesViewController.xib +++ b/AppBox/ViewController/PreferencesViewController/AccountPreferencesViewController/AccountPreferencesViewController.xib @@ -1,8 +1,8 @@ - + - + @@ -13,7 +13,8 @@ - + + @@ -217,6 +218,16 @@ + @@ -230,6 +241,8 @@ + + From bae6123a1517c5fd6248c6525049ecdc25240cf1 Mon Sep 17 00:00:00 2001 From: Vineet Choudhary Date: Wed, 26 Dec 2018 18:58:18 +0530 Subject: [PATCH 3/3] Changed version number to 2.7.1 --- AppBox/Info.plist | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/AppBox/Info.plist b/AppBox/Info.plist index 3dc9b8ee..a63c0a80 100644 --- a/AppBox/Info.plist +++ b/AppBox/Info.plist @@ -104,7 +104,7 @@ CFBundlePackageType APPL CFBundleShortVersionString - 2.8.0 + 2.7.1 CFBundleSignature ???? CFBundleURLTypes @@ -132,7 +132,7 @@ CFBundleVersion - 2 + 1 Fabric APIKey