diff --git a/Riot/Assets/en.lproj/Vector.strings b/Riot/Assets/en.lproj/Vector.strings index d48f5992b..2f180d932 100644 --- a/Riot/Assets/en.lproj/Vector.strings +++ b/Riot/Assets/en.lproj/Vector.strings @@ -53,7 +53,7 @@ "auth_skip" = "Skip"; "auth_send_reset_email" = "Send Reset Email"; "auth_return_to_login" = "Return to login screen"; -"auth_user_id_placeholder" = "Email, user name or phone number"; +"auth_user_id_placeholder" = "Email or user name"; "auth_password_placeholder" = "Password"; "auth_new_password_placeholder" = "New password"; "auth_user_name_placeholder" = "User name"; @@ -394,6 +394,7 @@ "directory_title" = "Directory"; // Others +"or" = "or"; "you" = "You"; "today" = "Today"; "yesterday" = "Yesterday"; diff --git a/Riot/ViewController/AuthenticationViewController.m b/Riot/ViewController/AuthenticationViewController.m index fe7590cf5..b1008fdc4 100644 --- a/Riot/ViewController/AuthenticationViewController.m +++ b/Riot/ViewController/AuthenticationViewController.m @@ -33,6 +33,11 @@ while we retry a login process against the matrix.org HS. */ NSError *loginError; + + /** + The default country code used to initialize the mobile phone number input. + */ + NSString *defaultCountryCode; } @end @@ -61,6 +66,8 @@ self.defaultBarTintColor = kRiotNavBarTintColor; self.enableBarTintColorStatusChange = NO; self.rageShakeManager = [RageShakeManager sharedManager]; + + defaultCountryCode = @"GB"; } - (void)viewDidLoad @@ -187,6 +194,38 @@ - (void)setAuthInputsView:(MXKAuthInputsView *)authInputsView { + // Keep the current country code if any. + if ([self.authInputsView isKindOfClass:AuthInputsView.class]) + { + // We will reuse the current country code + defaultCountryCode = ((AuthInputsView*)self.authInputsView).isoCountryCode; + } + + // Finalize the new auth inputs view + if ([authInputsView isKindOfClass:AuthInputsView.class]) + { + AuthInputsView *authInputsview = (AuthInputsView*)authInputsView; + + // Retrieve the MCC from the SIM card information (Note: the phone book country code is not defined yet) + NSString *countryCode = [MXKAppSettings standardAppSettings].phonebookCountryCode; + if (!countryCode) + { + // If none, consider the preferred locale + NSLocale *local = [[NSLocale alloc] initWithLocaleIdentifier:[[[NSBundle mainBundle] preferredLocalizations] objectAtIndex:0]]; + if ([local respondsToSelector:@selector(countryCode)]) + { + countryCode = local.countryCode; + } + + if (!countryCode) + { + countryCode = defaultCountryCode; + } + } + authInputsview.isoCountryCode = countryCode; + authInputsview.delegate = self; + } + [super setAuthInputsView:authInputsView]; // Restore here the actual content view height. @@ -320,9 +359,6 @@ [self.authenticationActivityIndicator stopAnimating]; // Show the supported 3rd party ids which may be added to the account - // Retrieve the MCC from the SIM card information (Note: the phone book country code is not defined yet) - authInputsview.isoCountryCode = [MXKAppSettings standardAppSettings].phonebookCountryCode; - authInputsview.delegate = self; authInputsview.thirdPartyIdentifiersHidden = NO; [self updateRegistrationScreenWithThirdPartyIdentifiersHidden:NO]; diff --git a/Riot/ViewController/SettingsViewController.m b/Riot/ViewController/SettingsViewController.m index ecf6ed168..887ad06a7 100644 --- a/Riot/ViewController/SettingsViewController.m +++ b/Riot/ViewController/SettingsViewController.m @@ -1425,7 +1425,22 @@ typedef void (^blockSettingsViewController_onReadyToDestroy)(); // When displaying the textfield the 1st time, open the keyboard if (!newPhoneNumberCell) { - newPhoneCell.isoCountryCode = [MXKAppSettings standardAppSettings].phonebookCountryCode; + NSString *countryCode = [MXKAppSettings standardAppSettings].phonebookCountryCode; + if (!countryCode) + { + // If none, consider the preferred locale + NSLocale *local = [[NSLocale alloc] initWithLocaleIdentifier:[[[NSBundle mainBundle] preferredLocalizations] objectAtIndex:0]]; + if ([local respondsToSelector:@selector(countryCode)]) + { + countryCode = local.countryCode; + } + + if (!countryCode) + { + countryCode = @"GB"; + } + } + newPhoneCell.isoCountryCode = countryCode; newPhoneCell.mxkTextField.text = nil; newPhoneNumberCell = newPhoneCell; diff --git a/Riot/Views/Authentication/AuthInputsView.h b/Riot/Views/Authentication/AuthInputsView.h index acb24a338..02fa0edad 100644 --- a/Riot/Views/Authentication/AuthInputsView.h +++ b/Riot/Views/Authentication/AuthInputsView.h @@ -45,6 +45,7 @@ @property (weak, nonatomic) IBOutlet NSLayoutConstraint *passwordContainerTopConstraint; @property (weak, nonatomic) IBOutlet NSLayoutConstraint *emailContainerTopConstraint; @property (weak, nonatomic) IBOutlet NSLayoutConstraint *phoneContainerTopConstraint; +@property (weak, nonatomic) IBOutlet NSLayoutConstraint *messageLabelTopConstraint; @property (weak, nonatomic) IBOutlet UILabel *messageLabel; diff --git a/Riot/Views/Authentication/AuthInputsView.m b/Riot/Views/Authentication/AuthInputsView.m index 90ca5096b..cf29c8f4b 100644 --- a/Riot/Views/Authentication/AuthInputsView.m +++ b/Riot/Views/Authentication/AuthInputsView.m @@ -36,7 +36,7 @@ MXK3PID *submittedMSISDN; UINavigationController *phoneNumberPickerNavigationController; CountryPickerViewController *phoneNumberCountryPicker; - NBPhoneNumber *newPhoneNumber; + NBPhoneNumber *nbPhoneNumber; /** The set of parameters ready to use for a registration. @@ -135,10 +135,19 @@ self.passWordTextField.returnKeyType = UIReturnKeyDone; self.userLoginTextField.placeholder = NSLocalizedStringFromTable(@"auth_user_id_placeholder", @"Vector", nil); + self.messageLabel.text = NSLocalizedStringFromTable(@"or", @"Vector", nil); + self.messageLabel.textColor = kRiotTextColorGray; + self.phoneTextField.placeholder = NSLocalizedStringFromTable(@"auth_phone_placeholder", @"Vector", nil); self.userLoginContainer.hidden = NO; + self.messageLabel.hidden = NO; + self.phoneContainer.hidden = NO; self.passwordContainer.hidden = NO; + self.messageLabelTopConstraint.constant = 59; + self.phoneContainerTopConstraint.constant = 70; + self.passwordContainerTopConstraint.constant = 150; + self.currentLastContainer = self.passwordContainer; } else @@ -264,10 +273,10 @@ } } - if (!errorMsg && newPhoneNumber) + if (!errorMsg && nbPhoneNumber) { // Check validity of the non empty phone - if (![[NBPhoneNumberUtil sharedInstance] isValidNumber:newPhoneNumber]) + if (![[NBPhoneNumberUtil sharedInstance] isValidNumber:nbPhoneNumber]) { NSLog(@"[AuthInputsView] Invalid phone number"); errorMsg = NSLocalizedStringFromTable(@"auth_invalid_phone", @"Vector", nil); @@ -321,41 +330,66 @@ { if (self.isPasswordBasedFlowSupported) { - //Check whether user login is an email or a username. + // Check whether the user login has been set. NSString *user = self.userLoginTextField.text; - if ([MXTools isEmailAddress:user]) + if (user.length) { - parameters = @{ - @"type": kMXLoginFlowTypePassword, - @"medium": kMX3PIDMediumEmail, - @"address": user, - @"password": self.passWordTextField.text - }; - } - else - { - // Retrieve the MCC (from the SIM card information) - // Note: the phone book country code is not defined yet - NSString *MCC = [MXKAppSettings standardAppSettings].phonebookCountryCode; - - // Check whether the user login is a valid phone number. - NSString *msisdn = [MXKTools msisdnWithPhoneNumber:user andCountryCode:MCC]; - - if (msisdn) + // Check whether user login is an email or a username. + if ([MXTools isEmailAddress:user]) { parameters = @{ @"type": kMXLoginFlowTypePassword, - @"medium": kMX3PIDMediumMSISDN, - @"address": msisdn, - @"password": self.passWordTextField.text + @"identifier": @{ + @"type": kMXLoginIdentifierTypeThirdParty, + @"medium": kMX3PIDMediumEmail, + @"address": user + }, + @"password": self.passWordTextField.text, + // Patch: add the old login api parameters for an email address (medium and address), + // to keep logging in against old HS. + @"medium": kMX3PIDMediumEmail, + @"address": user }; } else { parameters = @{ @"type": kMXLoginFlowTypePassword, - @"user": user, + @"identifier": @{ + @"type": kMXLoginIdentifierTypeUser, + @"user": user + }, + @"password": self.passWordTextField.text, + // Patch: add the old login api parameters for a username (user), + // to keep logging in against old HS. + @"user": user + }; + } + } + else if (nbPhoneNumber) + { + NSString *countryCode = [[NBPhoneNumberUtil sharedInstance] getRegionCodeForNumber:nbPhoneNumber]; + NSString *e164 = [[NBPhoneNumberUtil sharedInstance] format:nbPhoneNumber numberFormat:NBEPhoneNumberFormatE164 error:nil]; + NSString *msisdn; + if ([e164 hasPrefix:@"+"]) + { + msisdn = [e164 substringFromIndex:1]; + } + else if ([e164 hasPrefix:@"00"]) + { + msisdn = [e164 substringFromIndex:2]; + } + + if (msisdn && countryCode) + { + parameters = @{ + @"type": kMXLoginFlowTypePassword, + @"identifier": @{ + @"type": kMXLoginIdentifierTypePhone, + @"country": countryCode, + @"number": msisdn + }, @"password": self.passWordTextField.text }; } @@ -365,7 +399,7 @@ else if (type == MXKAuthenticationTypeRegister) { // Check whether a phone number has been set, and if it is not handled yet - if (newPhoneNumber && !self.isMSISDNFlowCompleted) + if (nbPhoneNumber && !self.isMSISDNFlowCompleted) { NSLog(@"[AuthInputsView] Prepare msisdn stage"); @@ -383,7 +417,7 @@ _isThirdPartyIdentifierPending = (!self.emailContainer.isHidden && self.emailTextField.text.length && !self.isEmailIdentityFlowCompleted); // Launch msisdn validation - NSString *e164 = [[NBPhoneNumberUtil sharedInstance] format:newPhoneNumber numberFormat:NBEPhoneNumberFormatE164 error:nil]; + NSString *e164 = [[NBPhoneNumberUtil sharedInstance] format:nbPhoneNumber numberFormat:NBEPhoneNumberFormatE164 error:nil]; NSString *msisdn; if ([e164 hasPrefix:@"+"]) { @@ -436,7 +470,7 @@ if (restClient) { // Check whether a second 3pid is available - _isThirdPartyIdentifierPending = (newPhoneNumber && !self.isMSISDNFlowCompleted); + _isThirdPartyIdentifierPending = (nbPhoneNumber && !self.isMSISDNFlowCompleted); // Launch email validation submittedEmail = [[MXK3PID alloc] initWithMedium:kMX3PIDMediumEmail andAddress:self.emailTextField.text]; @@ -843,6 +877,8 @@ self.passwordContainer.hidden = NO; self.repeatPasswordContainer.hidden = NO; + self.passwordContainerTopConstraint.constant = 50; + lastViewContainer = self.repeatPasswordContainer; } else @@ -896,6 +932,8 @@ } else { + self.phoneContainerTopConstraint.constant = 0; + self.messageLabel.hidden = NO; self.messageLabel.text = NSLocalizedStringFromTable(@"auth_add_phone_message", @"Vector", nil); } @@ -960,7 +998,7 @@ self.emailTextField.text = nil; self.phoneTextField.text = nil; - newPhoneNumber = nil; + nbPhoneNumber = nil; } #pragma mark - MXKCountryPickerViewControllerDelegate @@ -969,7 +1007,7 @@ { self.isoCountryCode = isoCountryCode; - newPhoneNumber = [[NBPhoneNumberUtil sharedInstance] parse:self.phoneTextField.text defaultRegion:isoCountryCode error:nil]; + nbPhoneNumber = [[NBPhoneNumberUtil sharedInstance] parse:self.phoneTextField.text defaultRegion:isoCountryCode error:nil]; [self formatNewPhoneNumber]; [self dismissCountryPicker]; @@ -1015,7 +1053,7 @@ if (textField == self.phoneTextField) { - newPhoneNumber = [[NBPhoneNumberUtil sharedInstance] parse:self.phoneTextField.text defaultRegion:self.isoCountryCode error:nil]; + nbPhoneNumber = [[NBPhoneNumberUtil sharedInstance] parse:self.phoneTextField.text defaultRegion:self.isoCountryCode error:nil]; [self formatNewPhoneNumber]; } @@ -1033,6 +1071,8 @@ self.repeatPasswordContainer.hidden = YES; // Hide other items + self.messageLabel.textColor = kRiotTextColorBlack; + self.messageLabelTopConstraint.constant = 8; self.messageLabel.hidden = YES; self.recaptchaWebView.hidden = YES; @@ -1041,9 +1081,9 @@ - (void)formatNewPhoneNumber { - if (newPhoneNumber) + if (nbPhoneNumber) { - NSString *formattedNumber = [[NBPhoneNumberUtil sharedInstance] format:newPhoneNumber numberFormat:NBEPhoneNumberFormatINTERNATIONAL error:nil]; + NSString *formattedNumber = [[NBPhoneNumberUtil sharedInstance] format:nbPhoneNumber numberFormat:NBEPhoneNumberFormatINTERNATIONAL error:nil]; NSString *prefix = self.callingCodeLabel.text; if ([formattedNumber hasPrefix:prefix]) { diff --git a/Riot/Views/Authentication/AuthInputsView.xib b/Riot/Views/Authentication/AuthInputsView.xib index 731800532..0b066a7bb 100644 --- a/Riot/Views/Authentication/AuthInputsView.xib +++ b/Riot/Views/Authentication/AuthInputsView.xib @@ -228,14 +228,14 @@