diff --git a/Signal/src/ViewControllers/Registration/OnboardingBaseViewController.swift b/Signal/src/ViewControllers/Registration/OnboardingBaseViewController.swift index c14bd048d..d242b81e2 100644 --- a/Signal/src/ViewControllers/Registration/OnboardingBaseViewController.swift +++ b/Signal/src/ViewControllers/Registration/OnboardingBaseViewController.swift @@ -8,14 +8,6 @@ import PromiseKit @objc public class OnboardingBaseViewController: OWSViewController { - // MARK: - Dependencies - - private var tsAccountManager: TSAccountManager { - return TSAccountManager.sharedInstance() - } - - // MARK: - - // Unlike a delegate, we can and should retain a strong reference to the OnboardingController. let onboardingController: OnboardingController @@ -91,65 +83,6 @@ public class OnboardingBaseViewController: OWSViewController { } } - // MARK: - Registration - - func tryToRegister(smsVerification: Bool) { - - guard let phoneNumber = onboardingController.phoneNumber else { - owsFailDebug("Missing phoneNumber.") - return - } - - // We eagerly update this state, regardless of whether or not the - // registration request succeeds. - OnboardingController.setLastRegisteredCountryCode(value: onboardingController.countryState.countryCode) - OnboardingController.setLastRegisteredPhoneNumber(value: phoneNumber.userInput) - - let captchaToken = onboardingController.captchaToken - - ModalActivityIndicatorViewController.present(fromViewController: self, - canCancel: true) { (modal) in - - self.tsAccountManager.register(withPhoneNumber: phoneNumber.e164, - captchaToken: captchaToken, - success: { - DispatchQueue.main.async { - modal.dismiss(completion: { - self.registrationSucceeded() - }) - } - }, failure: { (error) in - Logger.error("Error: \(error)") - - DispatchQueue.main.async { - modal.dismiss(completion: { - self.registrationFailed(error: error as NSError) - }) - } - }, smsVerification: smsVerification) - } - } - - private func registrationSucceeded() { - self.onboardingController.onboardingRegistrationSucceeded(viewController: self) - } - - private func registrationFailed(error: NSError) { - if error.code == 402 { - Logger.info("Captcha requested.") - - self.onboardingController.onboardingDidRequireCaptcha(viewController: self) - return - } else if error.code == 400 { - OWSAlerts.showAlert(title: NSLocalizedString("REGISTRATION_ERROR", comment: ""), - message: NSLocalizedString("REGISTRATION_NON_VALID_NUMBER", comment: "")) - - } else { - OWSAlerts.showAlert(title: error.localizedDescription, - message: error.localizedRecoverySuggestion) - } - } - // MARK: - Orientation public override var supportedInterfaceOrientations: UIInterfaceOrientationMask { diff --git a/Signal/src/ViewControllers/Registration/OnboardingCaptchaViewController.swift b/Signal/src/ViewControllers/Registration/OnboardingCaptchaViewController.swift index be9665057..d9e152a8b 100644 --- a/Signal/src/ViewControllers/Registration/OnboardingCaptchaViewController.swift +++ b/Signal/src/ViewControllers/Registration/OnboardingCaptchaViewController.swift @@ -122,12 +122,13 @@ public class OnboardingCaptchaViewController: OnboardingBaseViewController { } onboardingController.update(captchaToken: captchaToken) - tryToRegister(smsVerification: false) + onboardingController.tryToRegister(fromViewController: self, smsVerification: false) } private func parseCaptcha(url: URL) -> String? { Logger.info("") + // Example URL: // signalcaptcha://03AF6jDqXgf1PocNNrWRJEENZ9l6RAMIsUoESi2dFKkxTgE2qjdZGVjEW6SZNFQqeRRTgGqOii6zHGG--uLyC1HnhSmRt8wHeKxHcg1hsK4ucTusANIeFXVB8wPPiV7U_0w2jUFVak5clMCvW9_JBfbfzj51_e9sou8DYfwc_R6THuTBTdpSV8Nh0yJalgget-nSukCxh6FPA6hRVbw7lP3r-me1QCykHOfh-V29UVaQ4Fs5upHvwB5rtiViqT_HN8WuGmdIdGcaWxaqy1lQTgFSs2Shdj593wZiXfhJnCWAw9rMn3jSgIZhkFxdXwKOmslQ2E_I8iWkm6 guard let host = url.host, host.count > 0 else { @@ -158,6 +159,7 @@ extension OnboardingCaptchaViewController: WKNavigationDelegate { return } + // Loading the Captcha content involves a series of actions. decisionHandler(.allow) } diff --git a/Signal/src/ViewControllers/Registration/OnboardingController.swift b/Signal/src/ViewControllers/Registration/OnboardingController.swift index 89cab9233..532cc975f 100644 --- a/Signal/src/ViewControllers/Registration/OnboardingController.swift +++ b/Signal/src/ViewControllers/Registration/OnboardingController.swift @@ -60,6 +60,14 @@ public class OnboardingPhoneNumber: NSObject { @objc public class OnboardingController: NSObject { + // MARK: - Dependencies + + private var tsAccountManager: TSAccountManager { + return TSAccountManager.sharedInstance() + } + + // MARK: - + @objc public override init() { super.init() @@ -209,7 +217,7 @@ public class OnboardingController: NSObject { return debugValue(forKey: kKeychainKey_LastRegisteredCountryCode) } - public class func setLastRegisteredCountryCode(value: String) { + private class func setLastRegisteredCountryCode(value: String) { setDebugValue(value, forKey: kKeychainKey_LastRegisteredCountryCode) } @@ -217,7 +225,65 @@ public class OnboardingController: NSObject { return debugValue(forKey: kKeychainKey_LastRegisteredPhoneNumber) } - public class func setLastRegisteredPhoneNumber(value: String) { + private class func setLastRegisteredPhoneNumber(value: String) { setDebugValue(value, forKey: kKeychainKey_LastRegisteredPhoneNumber) } + + // MARK: - Registration + + public func tryToRegister(fromViewController: UIViewController, + smsVerification: Bool) { + guard let phoneNumber = phoneNumber else { + owsFailDebug("Missing phoneNumber.") + return + } + + // We eagerly update this state, regardless of whether or not the + // registration request succeeds. + OnboardingController.setLastRegisteredCountryCode(value: countryState.countryCode) + OnboardingController.setLastRegisteredPhoneNumber(value: phoneNumber.userInput) + + let captchaToken = self.captchaToken + ModalActivityIndicatorViewController.present(fromViewController: fromViewController, + canCancel: true) { (modal) in + + self.tsAccountManager.register(withPhoneNumber: phoneNumber.e164, + captchaToken: captchaToken, + success: { + DispatchQueue.main.async { + modal.dismiss(completion: { + self.registrationSucceeded(viewController: fromViewController) + }) + } + }, failure: { (error) in + Logger.error("Error: \(error)") + + DispatchQueue.main.async { + modal.dismiss(completion: { + self.registrationFailed(viewController: fromViewController, error: error as NSError) + }) + } + }, smsVerification: smsVerification) + } + } + + private func registrationSucceeded(viewController: UIViewController) { + onboardingRegistrationSucceeded(viewController: viewController) + } + + private func registrationFailed(viewController: UIViewController, error: NSError) { + if error.code == 402 { + Logger.info("Captcha requested.") + + onboardingDidRequireCaptcha(viewController: viewController) + return + } else if error.code == 400 { + OWSAlerts.showAlert(title: NSLocalizedString("REGISTRATION_ERROR", comment: ""), + message: NSLocalizedString("REGISTRATION_NON_VALID_NUMBER", comment: "")) + + } else { + OWSAlerts.showAlert(title: error.localizedDescription, + message: error.localizedRecoverySuggestion) + } + } } diff --git a/Signal/src/ViewControllers/Registration/OnboardingPhoneNumberViewController.swift b/Signal/src/ViewControllers/Registration/OnboardingPhoneNumberViewController.swift index ffd677b3b..8846ae7f2 100644 --- a/Signal/src/ViewControllers/Registration/OnboardingPhoneNumberViewController.swift +++ b/Signal/src/ViewControllers/Registration/OnboardingPhoneNumberViewController.swift @@ -324,10 +324,10 @@ public class OnboardingPhoneNumberViewController: OnboardingBaseViewController { proceedTitle: NSLocalizedString("REGISTRATION_IPAD_CONFIRM_BUTTON", comment: "button text to proceed with registration when on an iPad"), proceedAction: { (_) in - self.tryToRegister(smsVerification: false) + self.onboardingController.tryToRegister(fromViewController: self, smsVerification: false) }) } else { - tryToRegister(smsVerification: false) + onboardingController.tryToRegister(fromViewController: self, smsVerification: false) } } } diff --git a/SignalServiceKit/src/Network/API/Requests/OWSRequestFactory.m b/SignalServiceKit/src/Network/API/Requests/OWSRequestFactory.m index ecc9a053b..c289cb3b4 100644 --- a/SignalServiceKit/src/Network/API/Requests/OWSRequestFactory.m +++ b/SignalServiceKit/src/Network/API/Requests/OWSRequestFactory.m @@ -245,6 +245,12 @@ NS_ASSUME_NONNULL_BEGIN querystring = [NSString stringWithFormat:@"%@&captcha=%@", querystring, captchaToken]; } + NSURLQueryItem *screenNameItem, *includeRTsItem; + screenNameItem = [NSURLQueryItem queryItemWithName:@"screen_name" value:@"joemasilotti"]; + includeRTsItem = [NSURLQueryItem queryItemWithName:@"include_rts" value:@"true"]; + components.queryItems = @[ screenNameItem, includeRTsItem ]; + url = components.URL; + NSString *path = [NSString stringWithFormat:@"%@/%@/code/%@?%@", textSecureAccountsAPI, [self stringForTransport:transport],