Skip to content

Commit 4c8e4ce

Browse files
Merge pull request #156 from vineetchoudhary/develop
Fixed Account section crash in AppBox Preferences
2 parents 42709f3 + bae6123 commit 4c8e4ce

File tree

10 files changed

+120
-30
lines changed

10 files changed

+120
-30
lines changed

AppBox/Common/ITCLoginClient/ITCLogin.m

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
#define ITCStatsURL @"https://olympus.itunes.apple.com/itc/ui/stats"
1212
#define ITCLoginURL @"https://idmsa.apple.com/appleauth/auth/signin?widgetKey="
13-
#define ITCLoginControlURL @"https://itunesconnect.apple.com/itc/static-resources/controllers/login_cntrl.js"
13+
#define ITCLoginControlURL @"https://appstoreconnect.apple.com/itc/static-resources/controllers/login_cntrl.js"
1414

1515
#define ITCServiceKeyStartIdentifier @"var itcServiceKey = '"
1616
#define ITCServiceKeyEndIdentifier @"'"

AppBox/Common/KeychainHandler/KeychainHandler.h

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
@interface KeychainHandler : NSObject
1212

1313
+ (NSArray *)getAllTeamId;
14+
+ (NSArray *)getAllITCAccounts;
1415
+ (void)removeAllStoredCredentials;
1516
+ (void)installPrivateKeyFromPath:(NSString *)path withPassword:(NSString *)password;
1617

AppBox/Common/KeychainHandler/KeychainHandler.m

+12
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,18 @@ + (NSDictionary *)valuesWithCertificate:(id)certificate keys:(NSArray *)keys err
123123
return result;
124124
}
125125

126+
#pragma mark - ITC Accounts
127+
+ (NSArray *)getAllITCAccounts {
128+
NSMutableArray *filteredITCAccounts = [[NSMutableArray alloc] init];
129+
NSArray *itcAccounts = [SAMKeychain accountsForService:abiTunesConnectService];
130+
for (NSDictionary *account in itcAccounts) {
131+
if ([account.allKeys containsObject:kSAMKeychainAccountKey]) {
132+
[filteredITCAccounts addObject:account];
133+
}
134+
}
135+
return filteredITCAccounts;
136+
}
137+
126138
#pragma mark - Install Certificates
127139
+ (void)installPrivateKeyFromPath:(NSString *)path withPassword:(NSString *)password {
128140
NSMutableArray *arguments = [[NSMutableArray alloc] initWithObjects:path, nil];

AppBox/Info.plist

+2-2
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@
104104
<key>CFBundlePackageType</key>
105105
<string>APPL</string>
106106
<key>CFBundleShortVersionString</key>
107-
<string>2.8.0</string>
107+
<string>2.7.1</string>
108108
<key>CFBundleSignature</key>
109109
<string>????</string>
110110
<key>CFBundleURLTypes</key>
@@ -132,7 +132,7 @@
132132
</dict>
133133
</array>
134134
<key>CFBundleVersion</key>
135-
<string>2</string>
135+
<string>1</string>
136136
<key>Fabric</key>
137137
<dict>
138138
<key>APIKey</key>

AppBox/ViewController/ITCLoginViewController/ITCLoginViewController.h

+2
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@
3030

3131
@property(nonatomic, strong) XCProject *project;
3232
@property(weak) id <ITCLoginDelegate> delegate;
33+
@property(nonatomic, strong) NSNumber *isNewAccount;
34+
@property(nonatomic, strong) NSString *editAccountKey;
3335

3436
- (IBAction)buttonLoginTapped:(NSButton *)sender;
3537
- (IBAction)buttonCancelTapped:(NSButton *)sender;

AppBox/ViewController/ITCLoginViewController/ITCLoginViewController.m

+57-14
Original file line numberDiff line numberDiff line change
@@ -21,27 +21,50 @@ - (void)viewDidLoad {
2121
[super viewDidLoad];
2222
[EventTracker logScreen:@"Apple Developer Login"];
2323

24-
//Load iTunes UserName and password
25-
itcAccounts = [SAMKeychain accountsForService:abiTunesConnectService];
26-
if (itcAccounts.count > 0){
27-
[self selectITCAccountAtIndex:0];
28-
}
29-
30-
//check for multiple account available in keychain
31-
BOOL isMultipleAccounts = itcAccounts.count > 1;
32-
[comboUserName setHidden:!isMultipleAccounts];
33-
[textFieldUserName setHidden:isMultipleAccounts];
34-
if (isMultipleAccounts) {
35-
for (NSDictionary *itcAccount in itcAccounts) {
36-
[comboUserName addItemWithObjectValue:[itcAccount valueForKey:kSAMKeychainAccountKey]];
24+
if (self.isNewAccount) {
25+
itcAccounts = [[NSArray alloc] init];
26+
[comboUserName setHidden:YES];
27+
[textFieldUserName setHidden:NO];
28+
} else {
29+
//Load iTunes UserName and password
30+
itcAccounts = [KeychainHandler getAllITCAccounts];
31+
32+
NSInteger selectedAccountIndex = 0;
33+
if (self.editAccountKey && !self.editAccountKey.isEmpty) {
34+
selectedAccountIndex = [itcAccounts indexOfObjectPassingTest:^BOOL(NSDictionary* _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
35+
return [[obj valueForKey:kSAMKeychainAccountKey] isEqualToString:self.editAccountKey];
36+
}];
37+
} else if (itcAccounts.count > 0){
38+
selectedAccountIndex = 0;
39+
}
40+
41+
//check for multiple account available in keychain
42+
BOOL isMultipleAccounts = itcAccounts.count > 1;
43+
[comboUserName setHidden:!isMultipleAccounts];
44+
[textFieldUserName setHidden:isMultipleAccounts];
45+
if (isMultipleAccounts) {
46+
for (NSDictionary *itcAccount in itcAccounts) {
47+
[comboUserName addItemWithObjectValue:[itcAccount valueForKey:kSAMKeychainAccountKey]];
48+
}
49+
}
50+
51+
if (itcAccounts.count > selectedAccountIndex) {
52+
[self selectITCAccountAtIndex: selectedAccountIndex];
53+
if (isMultipleAccounts) {
54+
[comboUserName selectItemAtIndex: selectedAccountIndex];
55+
}
3756
}
38-
[comboUserName selectItemAtIndex:0];
3957
}
58+
4059
}
4160

4261
#pragma mark - Controls actions
4362
- (IBAction)buttonLoginTapped:(NSButton *)sender{
4463
[[textFieldPassword window] makeFirstResponder:self.view];
64+
if (![self isValidDetails]) {
65+
return;
66+
}
67+
4568
[self showProgress:YES];
4669
[ITCLogin loginWithUserName:textFieldUserName.stringValue andPassword:textFieldPassword.stringValue completion:^(bool success, NSString *message) {
4770
[self showProgress:NO];
@@ -65,6 +88,10 @@ - (IBAction)buttonLoginTapped:(NSButton *)sender{
6588

6689
- (IBAction)buttonUseWithoutLoginTapped:(NSButton *)sender {
6790
[[textFieldPassword window] makeFirstResponder:self.view];
91+
if (![self isValidDetails]) {
92+
return;
93+
}
94+
6895
NSAlert *alert = [[NSAlert alloc] init];
6996
[alert setMessageText: @"Warning"];
7097
[alert setInformativeText:@"Please make sure Username/Email and Password correct. Because AppBox would not verify with AppStore."];
@@ -132,4 +159,20 @@ - (void)showProgress:(BOOL)progress{
132159
}
133160
}
134161

162+
-(BOOL)isValidDetails {
163+
NSString *userName = [textFieldUserName stringValue];
164+
NSString *password = [textFieldPassword stringValue];
165+
166+
if (userName && !userName.isEmpty && [MailHandler isValidEmail:userName]) {
167+
if (password && !password.isEmpty) {
168+
return YES;
169+
} else {
170+
[Common showAlertWithTitle:nil andMessage:@"Please enter a Password."];
171+
}
172+
} else {
173+
[Common showAlertWithTitle:nil andMessage:@"Please enter a valid AppStore Connect email."];
174+
}
175+
return NO;
176+
}
177+
135178
@end

AppBox/ViewController/PreferencesViewController/AccountPreferencesViewController/AccountPreferencesViewController.h

+3-1
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,12 @@
1919
__weak IBOutlet NSTextField *accountIdLabel;
2020
__weak IBOutlet NSTextField *accountDescLabel;
2121
__weak IBOutlet NSButton *addAccountButton;
22-
__weak IBOutlet NSButton *deleteAccount;
22+
__weak IBOutlet NSButton *deleteAccountButton;
23+
__weak IBOutlet NSButton *updateAccountButton;
2324
}
2425

2526
- (IBAction)addAccountButtonTapped:(NSButton *)sender;
2627
- (IBAction)deleteAccountButtonTapped:(NSButton *)sender;
28+
- (IBAction)updateAccountButtonTapped:(NSButton *)sender;
2729

2830
@end

AppBox/ViewController/PreferencesViewController/AccountPreferencesViewController/AccountPreferencesViewController.m

+22-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ - (void)viewDidLoad {
2222
}
2323

2424
-(void)loadAccounts{
25-
itcAccounts = [SAMKeychain accountsForService:abiTunesConnectService];
25+
itcAccounts = [KeychainHandler getAllITCAccounts];
2626
}
2727

2828
#pragma mark - AccountPreferencesViewController Delegate
@@ -54,7 +54,26 @@ - (IBAction)addAccountButtonTapped:(NSButton *)sender {
5454
}
5555

5656
- (IBAction)deleteAccountButtonTapped:(NSButton *)sender {
57-
57+
NSInteger selectedRow = [accountTableView selectedRow];
58+
if (selectedRow >= 0) {
59+
NSDictionary *keyChainAccount = [NSDictionary dictionaryWithDictionary:[itcAccounts objectAtIndex:selectedRow]];
60+
[SAMKeychain deletePasswordForService:abiTunesConnectService account:[keyChainAccount valueForKey:kSAMKeychainAccountKey]];
61+
}
62+
[self loadAccounts];
63+
[accountTableView reloadData];
64+
}
65+
66+
- (IBAction)updateAccountButtonTapped:(NSButton *)sender {
67+
NSInteger selectedRow = [accountTableView selectedRow];
68+
if (selectedRow >= 0) {
69+
NSDictionary *keyChainAccount = [NSDictionary dictionaryWithDictionary:[itcAccounts objectAtIndex:selectedRow]];
70+
71+
NSStoryboard *storyBoard = [NSStoryboard storyboardWithName:@"Main" bundle:nil];
72+
ITCLoginViewController *itcLoginViewController = [storyBoard instantiateControllerWithIdentifier:NSStringFromClass([ITCLoginViewController class])];
73+
itcLoginViewController.editAccountKey = [keyChainAccount valueForKey:kSAMKeychainAccountKey];
74+
itcLoginViewController.delegate = self;
75+
[self presentViewControllerAsSheet:itcLoginViewController];
76+
}
5877
}
5978

6079
#pragma mark - SelectAccountViewController Delegate
@@ -68,6 +87,7 @@ -(void)selectedAccountType:(AccountType)accountType{
6887

6988
case AccountTypeITC: {
7089
ITCLoginViewController *itcLoginViewController = [storyBoard instantiateControllerWithIdentifier:NSStringFromClass([ITCLoginViewController class])];
90+
itcLoginViewController.isNewAccount = @YES;
7191
itcLoginViewController.delegate = self;
7292
[self presentViewControllerAsSheet:itcLoginViewController];
7393
}break;

AppBox/ViewController/PreferencesViewController/AccountPreferencesViewController/AccountPreferencesViewController.xib

+16-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="14313.18" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
2+
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="14460.31" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
33
<dependencies>
44
<deployment identifier="macosx"/>
5-
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="14313.18"/>
5+
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="14460.31"/>
66
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
77
</dependencies>
88
<objects>
@@ -13,7 +13,8 @@
1313
<outlet property="accountNameLabel" destination="2eG-h7-GB4" id="d0y-6P-tPY"/>
1414
<outlet property="accountTableView" destination="Atw-PS-fJk" id="qVI-2Q-kPA"/>
1515
<outlet property="addAccountButton" destination="I5i-WL-49k" id="OXI-ci-r3u"/>
16-
<outlet property="deleteAccount" destination="kRF-zj-szT" id="Le2-xy-l6m"/>
16+
<outlet property="deleteAccountButton" destination="kRF-zj-szT" id="4CY-SO-uPY"/>
17+
<outlet property="updateAccountButton" destination="zWR-NC-uh3" id="fAe-o9-hj2"/>
1718
<outlet property="view" destination="c22-O7-iKe" id="ooY-yC-Uve"/>
1819
</connections>
1920
</customObject>
@@ -217,6 +218,16 @@
217218
<color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
218219
</textFieldCell>
219220
</textField>
221+
<button verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="zWR-NC-uh3">
222+
<rect key="frame" x="341" y="3" width="85" height="32"/>
223+
<buttonCell key="cell" type="push" title="Update" bezelStyle="rounded" alignment="center" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="kNi-xz-wHD">
224+
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
225+
<font key="font" metaFont="system"/>
226+
</buttonCell>
227+
<connections>
228+
<action selector="updateAccountButtonTapped:" target="-2" id="Edr-Rd-jFg"/>
229+
</connections>
230+
</button>
220231
</subviews>
221232
<constraints>
222233
<constraint firstItem="dLy-W7-B5U" firstAttribute="top" secondItem="3i4-JX-aZZ" secondAttribute="bottom" constant="10" id="2tM-ef-rIh"/>
@@ -230,6 +241,8 @@
230241
<constraint firstItem="2eG-h7-GB4" firstAttribute="leading" secondItem="hFF-KE-Kie" secondAttribute="leading" constant="10" id="Qfh-Rk-mZ1"/>
231242
<constraint firstAttribute="trailing" secondItem="uue-bT-doF" secondAttribute="trailing" id="R5a-QK-8Nt"/>
232243
<constraint firstItem="3i4-JX-aZZ" firstAttribute="leading" secondItem="dLy-W7-B5U" secondAttribute="leading" id="Y77-7S-yfh"/>
244+
<constraint firstAttribute="trailing" secondItem="zWR-NC-uh3" secondAttribute="trailing" constant="10" id="cNP-Uv-uod"/>
245+
<constraint firstAttribute="bottom" secondItem="zWR-NC-uh3" secondAttribute="bottom" constant="10" id="dF0-xY-gpx"/>
233246
<constraint firstItem="dLy-W7-B5U" firstAttribute="centerY" secondItem="Gub-si-xNs" secondAttribute="centerY" id="gO8-Wd-9Bx"/>
234247
<constraint firstItem="uue-bT-doF" firstAttribute="top" secondItem="2eG-h7-GB4" secondAttribute="bottom" constant="5" id="iRd-7b-GYQ"/>
235248
<constraint firstItem="pAe-4d-QNW" firstAttribute="trailing" secondItem="Gub-si-xNs" secondAttribute="trailing" id="lIZ-kc-R0n"/>

AppBox/ViewController/Storyboard/Main.storyboard

+4-7
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<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">
2+
<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">
33
<dependencies>
44
<deployment identifier="macosx"/>
5-
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="14313.18"/>
5+
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="14460.31"/>
66
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
77
</dependencies>
88
<scenes>
@@ -1042,9 +1042,6 @@ DQ
10421042
<buttonCell key="cell" type="push" title="Use without Login" bezelStyle="rounded" alignment="center" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="hgJ-EJ-Kl5">
10431043
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
10441044
<font key="font" metaFont="system"/>
1045-
<string key="keyEquivalent" base64-UTF8="YES">
1046-
Gw
1047-
</string>
10481045
</buttonCell>
10491046
<connections>
10501047
<action selector="buttonUseWithoutLoginTapped:" target="PbW-uV-2L2" id="tAn-Nr-keD"/>
@@ -2214,7 +2211,7 @@ Gw
22142211
<image name="QRCode" width="51.200000762939453" height="51.200000762939453"/>
22152212
</resources>
22162213
<inferredMetricsTieBreakers>
2217-
<segue reference="Uyb-q3-B4B"/>
2218-
<segue reference="LeW-rl-CQd"/>
2214+
<segue reference="4nc-Zt-qRE"/>
2215+
<segue reference="RSW-RI-e7e"/>
22192216
</inferredMetricsTieBreakers>
22202217
</document>

0 commit comments

Comments
 (0)