diff --git a/matrixConsole.xcodeproj/project.pbxproj b/matrixConsole.xcodeproj/project.pbxproj index f5af3ac25..9b28ec80c 100644 --- a/matrixConsole.xcodeproj/project.pbxproj +++ b/matrixConsole.xcodeproj/project.pbxproj @@ -52,7 +52,6 @@ F08B6FCC1A1DE7F80094A35B /* matrixConsole.jpg in Resources */ = {isa = PBXBuildFile; fileRef = F08B6FCB1A1DE7F80094A35B /* matrixConsole.jpg */; }; F08DB7811A9B7C9300B73403 /* PublicRoomTableCell.m in Sources */ = {isa = PBXBuildFile; fileRef = F08DB7801A9B7C9300B73403 /* PublicRoomTableCell.m */; }; F08DCBDB1A093BFA008C65B6 /* MobileCoreServices.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F08DCBDA1A093BFA008C65B6 /* MobileCoreServices.framework */; }; - F08E67961A77965A00AABD4C /* MXC3PID.m in Sources */ = {isa = PBXBuildFile; fileRef = F08E67931A77965A00AABD4C /* MXC3PID.m */; }; F0ADEFFB1AD7D2B3008A4F21 /* RoomMembersViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = F0ADEFFA1AD7D2B3008A4F21 /* RoomMembersViewController.m */; }; F0CEA5AE19E6895E00E47915 /* logoHighRes.png in Resources */ = {isa = PBXBuildFile; fileRef = F0CEA5AC19E6895E00E47915 /* logoHighRes.png */; }; F0CEA5AF19E6895E00E47915 /* tab_recents.png in Resources */ = {isa = PBXBuildFile; fileRef = F0CEA5AD19E6895E00E47915 /* tab_recents.png */; }; @@ -150,8 +149,6 @@ F08DB77F1A9B7C9300B73403 /* PublicRoomTableCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PublicRoomTableCell.h; sourceTree = ""; }; F08DB7801A9B7C9300B73403 /* PublicRoomTableCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PublicRoomTableCell.m; sourceTree = ""; }; F08DCBDA1A093BFA008C65B6 /* MobileCoreServices.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = MobileCoreServices.framework; path = System/Library/Frameworks/MobileCoreServices.framework; sourceTree = SDKROOT; }; - F08E67921A77965A00AABD4C /* MXC3PID.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MXC3PID.h; sourceTree = ""; }; - F08E67931A77965A00AABD4C /* MXC3PID.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MXC3PID.m; sourceTree = ""; }; F0ADEFF91AD7D2B3008A4F21 /* RoomMembersViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RoomMembersViewController.h; sourceTree = ""; }; F0ADEFFA1AD7D2B3008A4F21 /* RoomMembersViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RoomMembersViewController.m; sourceTree = ""; }; F0CEA5AC19E6895E00E47915 /* logoHighRes.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = logoHighRes.png; sourceTree = ""; }; @@ -309,8 +306,6 @@ F0465AF71A251F85003639F9 /* Model */ = { isa = PBXGroup; children = ( - F08E67921A77965A00AABD4C /* MXC3PID.h */, - F08E67931A77965A00AABD4C /* MXC3PID.m */, 71193D301A6E49F000E59A9E /* MXCContact.h */, 71193D311A6E49F000E59A9E /* MXCContact.m */, 710CC3C01A70F28F006EE973 /* MXCContactField.h */, @@ -567,7 +562,6 @@ F03EF5F619F171EB00A0EE52 /* HomeViewController.m in Sources */, 71DB9DC11A495B6400504A09 /* MemberViewController.m in Sources */, F03EF5F919F171EB00A0EE52 /* RecentsViewController.m in Sources */, - F08E67961A77965A00AABD4C /* MXC3PID.m in Sources */, 71193D291A6E3DC000E59A9E /* ContactsViewController.m in Sources */, F0E84D401A1F9AEC005F2E42 /* RecentsTableViewCell.m in Sources */, 71193D381A6E49F000E59A9E /* MXCPhoneNumber.m in Sources */, diff --git a/matrixConsole/Model/MXC3PID.h b/matrixConsole/Model/MXC3PID.h deleted file mode 100644 index 146fe9711..000000000 --- a/matrixConsole/Model/MXC3PID.h +++ /dev/null @@ -1,97 +0,0 @@ -/* - Copyright 2014 OpenMarket Ltd - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. - */ - -#import - -#import "MXRestClient.h" - -typedef enum : NSUInteger { - MXC3PIDAuthStateUnknown, - MXC3PIDAuthStateTokenRequested, - MXC3PIDAuthStateTokenReceived, - MXC3PIDAuthStateTokenSubmitted, - MXC3PIDAuthStateAuthenticated -} MXC3PIDAuthState; - - -@interface MXC3PID : NSObject - -/** - The 3rd party system where the user is defined. - */ -@property (nonatomic, readonly) MX3PIDMedium medium; - -/** - The id of the user in the 3rd party system. - */ -@property (nonatomic, readonly) NSString *address; - -/** - The id of the user on Matrix. - nil if unknown or not yet resolved. - */ -@property (nonatomic) NSString *userId; - -@property (nonatomic, readonly) MXC3PIDAuthState validationState; - -/** - Initialise the instance with a 3PID. - - @param medium the medium. - @param address the id of the contact on this medium. - @return the new instance. - */ -- (instancetype)initWithMedium:(NSString*)medium andAddress:(NSString*)address; - -/** - Start the validation process - The identity server will send a validation token to the user's address. - This validation token must be then send back to the identity server with [MXC3PID validateWithToken] - in order to complete the 3PID authentication. - - @param restClient used to make matrix API requests during validation process. - @param success A block object called when the operation succeeds. - @param failure A block object called when the operation fails. - */ -- (void)requestValidationTokenWithMatrixRestClient:(MXRestClient*)restClient - success:(void (^)())success - failure:(void (^)(NSError *error))failure; - -/** - Complete the 3rd party id validation by sending the validation token the user received. - - @param validationToken the validation token the user received. - @param success A block object called when the operation succeeds. It indicates if the - validation has succeeded. - @param failure A block object called when the operation fails. - */ -- (void)validateWithToken:(NSString*)validationToken - success:(void (^)(BOOL success))success - failure:(void (^)(NSError *error))failure; - -/** - Link an authenticated 3rd party id to a Matrix user id. - - @param userId the Matrix user id to link the 3PID with. - @param success A block object called when the operation succeeds. It provides the raw - server response. - @param failure A block object called when the operation fails. - */ -- (void)bindWithUserId:(NSString*)userId - success:(void (^)())success - failure:(void (^)(NSError *error))failure; - -@end \ No newline at end of file diff --git a/matrixConsole/Model/MXC3PID.m b/matrixConsole/Model/MXC3PID.m deleted file mode 100644 index 0458d8b11..000000000 --- a/matrixConsole/Model/MXC3PID.m +++ /dev/null @@ -1,194 +0,0 @@ -/* - Copyright 2014 OpenMarket Ltd - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. - */ - -#import "MXC3PID.h" -#import "MXTools.h" - -@interface MXC3PID () { - MXRestClient *mxRestClient; - MXHTTPOperation *currentRequest; -} -@property (nonatomic) NSString *clientSecret; -@property (nonatomic) NSUInteger sendAttempt; -@property (nonatomic) NSString *sid; -@end - -@implementation MXC3PID - -- (instancetype)initWithMedium:(NSString *)medium andAddress:(NSString *)address -{ - self = [super init]; - if (self) - { - _medium = [medium copy]; - _address = [address copy]; - } - return self; -} - -- (void)resetValidationParameters { - _validationState = MXC3PIDAuthStateUnknown; - - [currentRequest cancel]; - currentRequest = nil; - mxRestClient = nil; - - self.clientSecret = nil; - self.sendAttempt = 1; - self.sid = nil; - // Removed potential linked userId - self.userId = nil; -} - -- (void)requestValidationTokenWithMatrixRestClient:(MXRestClient*)restClient - success:(void (^)())success - failure:(void (^)(NSError *error))failure { - // Sanity Check - if (_validationState != MXC3PIDAuthStateTokenRequested && restClient) { - - // Reset if the current state is different than "Unknown" - if (_validationState != MXC3PIDAuthStateUnknown) { - [self resetValidationParameters]; - } - - if ([self.medium isEqualToString:kMX3PIDMediumEmail]) { - self.clientSecret = [MXTools generateSecret]; - _validationState = MXC3PIDAuthStateTokenRequested; - mxRestClient = restClient; - - currentRequest = [mxRestClient requestEmailValidation:self.address clientSecret:self.clientSecret sendAttempt:self.sendAttempt success:^(NSString *sid) { - _validationState = MXC3PIDAuthStateTokenReceived; - currentRequest = nil; - self.sid = sid; - - if (success) { - success(); - } - } failure:^(NSError *error) { - // Return in unknown state - _validationState = MXC3PIDAuthStateUnknown; - currentRequest = nil; - // Increment attempt counter - self.sendAttempt++; - - if (failure) { - failure (error); - } - }]; - - return; - } else if ([self.medium isEqualToString:kMX3PIDMediumMSISDN]) { - // FIXME: support msisdn as soon as identity server supports it - NSLog(@"[MXC3PID] requestValidationToken: is not supported for this 3PID: %@ (%@)", self.address, self.medium); - } else { - NSLog(@"[MXC3PID] requestValidationToken: is not supported for this 3PID: %@ (%@)", self.address, self.medium); - } - } else { - NSLog(@"[MXC3PID] Failed to request validation token for 3PID: %@ (%@), state: %lu", self.address, self.medium, (unsigned long)_validationState); - } -} - -- (void)validateWithToken:(NSString*)validationToken - success:(void (^)(BOOL success))success - failure:(void (^)(NSError *error))failure { - // Sanity check - if (_validationState == MXC3PIDAuthStateTokenReceived) { - - if ([self.medium isEqualToString:kMX3PIDMediumEmail]) { - _validationState = MXC3PIDAuthStateTokenSubmitted; - - currentRequest = [mxRestClient validateEmail:self.sid validationToken:validationToken clientSecret:self.clientSecret success:^(BOOL successFlag) { - if (successFlag) { - // Validation is complete - _validationState = MXC3PIDAuthStateAuthenticated; - } else { - // Return in previous step - _validationState = MXC3PIDAuthStateTokenReceived; - } - - currentRequest = nil; - - if (success) { - success(successFlag); - } - } failure:^(NSError *error) { - // Return in previous step - _validationState = MXC3PIDAuthStateTokenReceived; - currentRequest = nil; - - if (failure) { - failure (error); - } - }]; - - return; - } else if ([self.medium isEqualToString:kMX3PIDMediumMSISDN]) { - // FIXME: support msisdn as soon as identity server supports it - NSLog(@"[MXC3PID] validateWithToken: is not supported for this 3PID: %@ (%@)", self.address, self.medium); - } else { - NSLog(@"[MXC3PID] validateWithToken: is not supported for this 3PID: %@ (%@)", self.address, self.medium); - } - } else { - NSLog(@"[MXC3PID] Failed to valid with token 3PID: %@ (%@), state: %lu", self.address, self.medium, (unsigned long)_validationState); - } - - // Here the validation process failed - if (failure) { - failure (nil); - } -} - -- (void)bindWithUserId:(NSString*)userId - success:(void (^)())success - failure:(void (^)(NSError *error))failure { - // Sanity check - if (_validationState == MXC3PIDAuthStateAuthenticated) { - - if ([self.medium isEqualToString:kMX3PIDMediumEmail]) { - currentRequest = [mxRestClient bind3PID:userId sid:self.sid clientSecret:self.clientSecret success:^(NSDictionary *JSONResponse) { - // Update linked userId in 3PID - self.userId = userId; - currentRequest = nil; - - if (success) { - success(); - } - } failure:^(NSError *error) { - currentRequest = nil; - - if (failure) { - failure (error); - } - }]; - - return; - } else if ([self.medium isEqualToString:kMX3PIDMediumMSISDN]) { - // FIXME: support msisdn as soon as identity server supports it - NSLog(@"[MXC3PID] bindWithUserId: is not supported for this 3PID: %@ (%@)", self.address, self.medium); - } else { - NSLog(@"[MXC3PID] bindWithUserId: is not supported for this 3PID: %@ (%@)", self.address, self.medium); - } - } else { - NSLog(@"[MXC3PID] Failed to bind 3PID: %@ (%@), state: %lu", self.address, self.medium, (unsigned long)_validationState); - } - - // Here the validation process failed - if (failure) { - failure (nil); - } -} - -@end diff --git a/matrixConsole/ViewController/SettingsViewController.m b/matrixConsole/ViewController/SettingsViewController.m index 962437b8c..964a6337f 100644 --- a/matrixConsole/ViewController/SettingsViewController.m +++ b/matrixConsole/ViewController/SettingsViewController.m @@ -20,7 +20,6 @@ #import "AppDelegate.h" #import "APNSHandler.h" -#import "MXC3PID.h" #import "ContactManager.h" @@ -70,7 +69,7 @@ NSString* const kCommandsDescriptionText = @"The following commands are availabl // Linked emails NSMutableArray *linkedEmails; - MXC3PID *submittedEmail; + MXK3PID *submittedEmail; SettingsCellWithTextFieldAndButton* submittedEmailCell; SettingsCellWithLabelTextFieldAndButton* emailTokenCell; // Dynamic rows in the Linked emails section @@ -617,7 +616,7 @@ NSString* const kCommandsDescriptionText = @"The following commands are availabl [[AppDelegate theDelegate] logout]; } else if (sender == submittedEmailCell.settingButton) { if (!submittedEmail || ![submittedEmail.address isEqualToString:submittedEmailCell.settingTextField.text]) { - submittedEmail = [[MXC3PID alloc] initWithMedium:kMX3PIDMediumEmail andAddress:submittedEmailCell.settingTextField.text]; + submittedEmail = [[MXK3PID alloc] initWithMedium:kMX3PIDMediumEmail andAddress:submittedEmailCell.settingTextField.text]; } submittedEmailCell.settingButton.enabled = NO; @@ -764,7 +763,7 @@ NSString* const kCommandsDescriptionText = @"The following commands are availabl count = linkedEmails.count; submittedEmailRowIndex = count++; - if (submittedEmail && submittedEmail.validationState >= MXC3PIDAuthStateTokenReceived) { + if (submittedEmail && submittedEmail.validationState >= MXK3PIDAuthStateTokenReceived) { emailTokenRowIndex = count++; } else { emailTokenCell = nil;