Show alerts for missing or invalid phone numbers in registration view.

// FREEBIE
This commit is contained in:
Matthew Chen 2017-05-18 09:40:56 -04:00
parent 1ab8fb29bf
commit 54faff2db2
2 changed files with 51 additions and 25 deletions

View File

@ -119,44 +119,58 @@ static NSString *const kCodeSentSegue = @"codeSent";
{
DDLogInfo(@"called %s", __PRETTY_FUNCTION__);
NSString *alertTitleFormat = NSLocalizedString(@"EXISTING_USER_REGISTRATION_ALERT_TITLE",
@"during registration, embeds {{device type}}, e.g. \"iPhone\" or \"iPad\"");
NSString *alertTitle = [NSString stringWithFormat:alertTitleFormat, [UIDevice currentDevice].localizedModel];
NSString *alertBody = NSLocalizedString(@"EXISTING_USER_REGISTRATION_ALERT_BODY", @"during registration");
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:alertTitle
message:alertBody
preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *cancelAction =
[UIAlertAction actionWithTitle:NSLocalizedString(@"OK", nil) style:UIAlertActionStyleCancel handler:nil];
[alertController addAction:cancelAction];
[self presentViewController:alertController animated:YES completion:nil];
[OWSAlerts
showAlertWithTitle:
[NSString stringWithFormat:NSLocalizedString(@"EXISTING_USER_REGISTRATION_ALERT_TITLE",
@"during registration, embeds {{device type}}, e.g. \"iPhone\" or \"iPad\""),
[UIDevice currentDevice].localizedModel]
message:NSLocalizedString(@"EXISTING_USER_REGISTRATION_ALERT_BODY", @"during registration")];
}
- (IBAction)sendCodeAction:(id)sender {
NSString *phoneNumber = [NSString stringWithFormat:@"%@%@", _callingCode, _phoneNumberTextField.text];
NSString *phoneNumberText =
[_phoneNumberTextField.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
if (phoneNumberText.length < 1) {
[OWSAlerts
showAlertWithTitle:NSLocalizedString(@"REGISTRATION_VIEW_NO_PHONE_NUMBER_ALERT_TITLE",
@"Title of alert indicating that users needs to enter a phone number to register.")
message:
NSLocalizedString(@"REGISTRATION_VIEW_NO_PHONE_NUMBER_ALERT_MESSAGE",
@"Message of alert indicating that users needs to enter a phone number to register.")];
return;
}
NSString *phoneNumber = [NSString stringWithFormat:@"%@%@", _callingCode, phoneNumberText];
PhoneNumber *localNumber = [PhoneNumber tryParsePhoneNumberFromUserSpecifiedText:phoneNumber];
NSString *parsedPhoneNumber = localNumber.toE164;
if (parsedPhoneNumber.length < 1) {
[OWSAlerts showAlertWithTitle:
NSLocalizedString(@"REGISTRATION_VIEW_INVALID_PHONE_NUMBER_ALERT_TITLE",
@"Title of alert indicating that users needs to enter a valid phone number to register.")
message:NSLocalizedString(@"REGISTRATION_VIEW_INVALID_PHONE_NUMBER_ALERT_MESSAGE",
@"Message of alert indicating that users needs to enter a valid phone number "
@"to register.")];
return;
}
[_sendCodeButton setEnabled:NO];
[_spinnerView startAnimating];
[_phoneNumberTextField resignFirstResponder];
[TSAccountManager registerWithPhoneNumber:localNumber.toE164
[TSAccountManager registerWithPhoneNumber:parsedPhoneNumber
success:^{
[self performSegueWithIdentifier:@"codeSent" sender:self];
[_spinnerView stopAnimating];
[self performSegueWithIdentifier:@"codeSent" sender:self];
[_spinnerView stopAnimating];
}
failure:^(NSError *error) {
if (error.code == 400) {
[OWSAlerts showAlertWithTitle:NSLocalizedString(@"REGISTRATION_ERROR", nil)
message:NSLocalizedString(@"REGISTRATION_NON_VALID_NUMBER", nil)];
} else {
[OWSAlerts showAlertWithTitle:error.localizedDescription message:error.localizedRecoverySuggestion];
}
if (error.code == 400) {
[OWSAlerts showAlertWithTitle:NSLocalizedString(@"REGISTRATION_ERROR", nil)
message:NSLocalizedString(@"REGISTRATION_NON_VALID_NUMBER", nil)];
} else {
[OWSAlerts showAlertWithTitle:error.localizedDescription message:error.localizedRecoverySuggestion];
}
[_sendCodeButton setEnabled:YES];
[_spinnerView stopAnimating];
[_sendCodeButton setEnabled:YES];
[_spinnerView stopAnimating];
}
smsVerification:YES];
}

View File

@ -997,6 +997,18 @@
/* No comment provided by engineer. */
"REGISTRATION_VERIFY_DEVICE" = "Activate This Device";
/* Message of alert indicating that users needs to enter a valid phone number to register. */
"REGISTRATION_VIEW_INVALID_PHONE_NUMBER_ALERT_MESSAGE" = "Please enter a valid phone number to register.";
/* Title of alert indicating that users needs to enter a valid phone number to register. */
"REGISTRATION_VIEW_INVALID_PHONE_NUMBER_ALERT_TITLE" = "Invalid Phone Number";
/* Message of alert indicating that users needs to enter a phone number to register. */
"REGISTRATION_VIEW_NO_PHONE_NUMBER_ALERT_MESSAGE" = "Please enter a phone number to register.";
/* Title of alert indicating that users needs to enter a phone number to register. */
"REGISTRATION_VIEW_NO_PHONE_NUMBER_ALERT_TITLE" = "No Phone Number";
/* No comment provided by engineer. */
"REJECT_CALL_BUTTON_TITLE" = "Reject";