Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed Account section crash in AppBox Preferences #156

Merged
merged 3 commits into from
Dec 26, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion AppBox/Common/ITCLoginClient/ITCLogin.m
Original file line number Diff line number Diff line change
Expand Up @@ -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 @"'"
Expand Down
1 change: 1 addition & 0 deletions AppBox/Common/KeychainHandler/KeychainHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
@interface KeychainHandler : NSObject

+ (NSArray *)getAllTeamId;
+ (NSArray *)getAllITCAccounts;
+ (void)removeAllStoredCredentials;
+ (void)installPrivateKeyFromPath:(NSString *)path withPassword:(NSString *)password;

Expand Down
12 changes: 12 additions & 0 deletions AppBox/Common/KeychainHandler/KeychainHandler.m
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down
4 changes: 2 additions & 2 deletions AppBox/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>2.8.0</string>
<string>2.7.1</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleURLTypes</key>
Expand Down Expand Up @@ -132,7 +132,7 @@
</dict>
</array>
<key>CFBundleVersion</key>
<string>2</string>
<string>1</string>
<key>Fabric</key>
<dict>
<key>APIKey</key>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@

@property(nonatomic, strong) XCProject *project;
@property(weak) id <ITCLoginDelegate> delegate;
@property(nonatomic, strong) NSNumber *isNewAccount;
@property(nonatomic, strong) NSString *editAccountKey;

- (IBAction)buttonLoginTapped:(NSButton *)sender;
- (IBAction)buttonCancelTapped:(NSButton *)sender;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,27 +21,50 @@ - (void)viewDidLoad {
[super viewDidLoad];
[EventTracker logScreen:@"Apple Developer Login"];

//Load iTunes UserName and password
itcAccounts = [SAMKeychain accountsForService:abiTunesConnectService];
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
- (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];
Expand All @@ -65,6 +88,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."];
Expand Down Expand Up @@ -132,4 +159,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
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ - (void)viewDidLoad {
}

-(void)loadAccounts{
itcAccounts = [SAMKeychain accountsForService:abiTunesConnectService];
itcAccounts = [KeychainHandler getAllITCAccounts];
}

#pragma mark - AccountPreferencesViewController Delegate
Expand Down Expand Up @@ -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
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="14313.18" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="14460.31" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
<dependencies>
<deployment identifier="macosx"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="14313.18"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="14460.31"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<objects>
Expand All @@ -13,7 +13,8 @@
<outlet property="accountNameLabel" destination="2eG-h7-GB4" id="d0y-6P-tPY"/>
<outlet property="accountTableView" destination="Atw-PS-fJk" id="qVI-2Q-kPA"/>
<outlet property="addAccountButton" destination="I5i-WL-49k" id="OXI-ci-r3u"/>
<outlet property="deleteAccount" destination="kRF-zj-szT" id="Le2-xy-l6m"/>
<outlet property="deleteAccountButton" destination="kRF-zj-szT" id="4CY-SO-uPY"/>
<outlet property="updateAccountButton" destination="zWR-NC-uh3" id="fAe-o9-hj2"/>
<outlet property="view" destination="c22-O7-iKe" id="ooY-yC-Uve"/>
</connections>
</customObject>
Expand Down Expand Up @@ -217,6 +218,16 @@
<color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
</textField>
<button verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="zWR-NC-uh3">
<rect key="frame" x="341" y="3" width="85" height="32"/>
<buttonCell key="cell" type="push" title="Update" bezelStyle="rounded" alignment="center" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="kNi-xz-wHD">
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
<font key="font" metaFont="system"/>
</buttonCell>
<connections>
<action selector="updateAccountButtonTapped:" target="-2" id="Edr-Rd-jFg"/>
</connections>
</button>
</subviews>
<constraints>
<constraint firstItem="dLy-W7-B5U" firstAttribute="top" secondItem="3i4-JX-aZZ" secondAttribute="bottom" constant="10" id="2tM-ef-rIh"/>
Expand All @@ -230,6 +241,8 @@
<constraint firstItem="2eG-h7-GB4" firstAttribute="leading" secondItem="hFF-KE-Kie" secondAttribute="leading" constant="10" id="Qfh-Rk-mZ1"/>
<constraint firstAttribute="trailing" secondItem="uue-bT-doF" secondAttribute="trailing" id="R5a-QK-8Nt"/>
<constraint firstItem="3i4-JX-aZZ" firstAttribute="leading" secondItem="dLy-W7-B5U" secondAttribute="leading" id="Y77-7S-yfh"/>
<constraint firstAttribute="trailing" secondItem="zWR-NC-uh3" secondAttribute="trailing" constant="10" id="cNP-Uv-uod"/>
<constraint firstAttribute="bottom" secondItem="zWR-NC-uh3" secondAttribute="bottom" constant="10" id="dF0-xY-gpx"/>
<constraint firstItem="dLy-W7-B5U" firstAttribute="centerY" secondItem="Gub-si-xNs" secondAttribute="centerY" id="gO8-Wd-9Bx"/>
<constraint firstItem="uue-bT-doF" firstAttribute="top" secondItem="2eG-h7-GB4" secondAttribute="bottom" constant="5" id="iRd-7b-GYQ"/>
<constraint firstItem="pAe-4d-QNW" firstAttribute="trailing" secondItem="Gub-si-xNs" secondAttribute="trailing" id="lIZ-kc-R0n"/>
Expand Down
11 changes: 4 additions & 7 deletions AppBox/ViewController/Storyboard/Main.storyboard
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.Storyboard.XIB" version="3.0" toolsVersion="14313.18" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" initialViewController="B8D-0N-5wS">
<document type="com.apple.InterfaceBuilder3.Cocoa.Storyboard.XIB" version="3.0" toolsVersion="14460.31" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" initialViewController="B8D-0N-5wS">
<dependencies>
<deployment identifier="macosx"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="14313.18"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="14460.31"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<scenes>
Expand Down Expand Up @@ -1042,9 +1042,6 @@ DQ
<buttonCell key="cell" type="push" title="Use without Login" bezelStyle="rounded" alignment="center" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="hgJ-EJ-Kl5">
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
<font key="font" metaFont="system"/>
<string key="keyEquivalent" base64-UTF8="YES">
Gw
</string>
</buttonCell>
<connections>
<action selector="buttonUseWithoutLoginTapped:" target="PbW-uV-2L2" id="tAn-Nr-keD"/>
Expand Down Expand Up @@ -2214,7 +2211,7 @@ Gw
<image name="QRCode" width="51.200000762939453" height="51.200000762939453"/>
</resources>
<inferredMetricsTieBreakers>
<segue reference="Uyb-q3-B4B"/>
<segue reference="LeW-rl-CQd"/>
<segue reference="4nc-Zt-qRE"/>
<segue reference="RSW-RI-e7e"/>
</inferredMetricsTieBreakers>
</document>