Skip to content
This repository was archived by the owner on Feb 5, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion WordPressAuthenticator.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = "WordPressAuthenticator"
s.version = "1.35.0"
s.version = "1.35.1"
s.summary = "WordPressAuthenticator implements an easy and elegant way to authenticate your WordPress Apps."

s.description = <<-DESC
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public struct WordPressAuthenticatorDisplayStrings {
public let openMailSignupInstructions: String
public let openMailLoginInstructions: String
public let checkSpamInstructions: String
public let oopsInstructions: String
public let googleSignupInstructions: String
public let googlePasswordInstructions: String
public let applePasswordInstructions: String
Expand Down Expand Up @@ -67,6 +68,7 @@ public struct WordPressAuthenticatorDisplayStrings {
openMailSignupInstructions: String = defaultStrings.openMailSignupInstructions,
openMailLoginInstructions: String = defaultStrings.openMailLoginInstructions,
checkSpamInstructions: String = defaultStrings.checkSpamInstructions,
oopsInstructions: String = defaultStrings.oopsInstructions,
googleSignupInstructions: String = defaultStrings.googleSignupInstructions,
googlePasswordInstructions: String = defaultStrings.googlePasswordInstructions,
applePasswordInstructions: String = defaultStrings.applePasswordInstructions,
Expand Down Expand Up @@ -102,6 +104,7 @@ public struct WordPressAuthenticatorDisplayStrings {
self.openMailSignupInstructions = openMailSignupInstructions
self.openMailLoginInstructions = openMailLoginInstructions
self.checkSpamInstructions = checkSpamInstructions
self.oopsInstructions = oopsInstructions
self.googleSignupInstructions = googleSignupInstructions
self.googlePasswordInstructions = googlePasswordInstructions
self.applePasswordInstructions = applePasswordInstructions
Expand Down Expand Up @@ -153,6 +156,7 @@ public extension WordPressAuthenticatorDisplayStrings {
openMailLoginInstructions: NSLocalizedString("Check your email on this device, and tap the link in the email you receive from WordPress.com.",
comment: "Instruction text after a login Magic Link was requested."),
checkSpamInstructions: NSLocalizedString("Not seeing the email? Check your Spam or Junk Mail folder.", comment: "Instructions after a Magic Link was sent, but the email can't be found in their inbox."),
oopsInstructions: NSLocalizedString("Didn't mean to create a new account? Go back to re-enter your email address.", comment: "Instructions after a Magic Link was sent, but email is incorrect."),
googleSignupInstructions: NSLocalizedString("We'll use this email address to create your new WordPress.com account.", comment: "Text confirming email address to be used for new account."),
googlePasswordInstructions: NSLocalizedString("To proceed with this Google account, please first log in with your WordPress.com password. This will only be asked once.",
comment: "Instructional text shown when requesting the user's password for Google login."),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ private extension GetStartedViewController {
let errorCode = userInfo[WordPressComRestApi.ErrorKeyErrorCode] as? String

if errorCode == "unknown_user" {
self.showSignupViewIfNecessary(error)
self.sendEmail()
} else if errorCode == "email_login_not_allowed" {
// If we get this error, we know we have a WordPress.com user but their
// email address is flagged as suspicious. They need to login via their
Expand All @@ -411,36 +411,45 @@ private extension GetStartedViewController {
self.displayError(error as NSError, sourceTag: self.sourceTag)
}
}

// MARK: - Send email

/// Offer host apps the opportunity to decide if they want to allow signups
/// Makes the call to request a magic signup link be emailed to the user.
///
func showSignupViewIfNecessary(_ error: Error) {
guard let authenticationDelegate = WordPressAuthenticator.shared.delegate, authenticationDelegate.shouldHandleError(error) else {
showSignupView()
return
}
private func sendEmail() {
tracker.set(flow: .signup)
loginFields.meta.emailMagicLinkSource = .signup

/// Hand over control to the host app.
authenticationDelegate.handleError(error) { customUI in
// Setting the rightBarButtonItems of the custom UI before pushing the view controller
// and resetting the navigationController's navigationItem after the push seems to be the
// only combination that gets the Help button to show up.
customUI.navigationItem.rightBarButtonItems = self.navigationItem.rightBarButtonItems
self.navigationController?.navigationItem.rightBarButtonItems = self.navigationItem.rightBarButtonItems
configureSubmitButton(animating: true)

self.navigationController?.pushViewController(customUI, animated: true)
}
let service = WordPressComAccountService()
service.requestSignupLink(for: loginFields.username,
success: { [weak self] in
self?.didRequestSignupLink()
self?.configureSubmitButton(animating: false)

}, failure: { [weak self] (error: Error) in
DDLogError("Request for signup link email failed.")

guard let self = self else {
return
}

self.tracker.track(failure: error.localizedDescription)
self.displayError(error as NSError, sourceTag: self.sourceTag)
self.configureSubmitButton(animating: false)
})
}

/// Show the Sign Up view.
///
func showSignupView() {
guard let vc = UnifiedSignupViewController.instantiate(from: .unifiedSignup) else {
DDLogError("Failed to navigate to UnifiedSignupViewController from GetStartedViewController")

private func didRequestSignupLink() {
guard let vc = SignupMagicLinkViewController.instantiate(from: .unifiedSignup) else {
DDLogError("Failed to navigate from UnifiedSignupViewController to SignupMagicLinkViewController")
return
}

vc.loginFields = loginFields
vc.loginFields.restrictToWPCom = true

navigationController?.pushViewController(vc, animated: true)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ private extension SignupMagicLinkViewController {
/// Describes how the tableView rows should be rendered.
///
func loadRows() {
rows = [.persona, .instructions, .checkSpam]
rows = [.persona, .instructions, .checkSpam, .oops]
}

/// Configure cells.
Expand All @@ -145,6 +145,8 @@ private extension SignupMagicLinkViewController {
configureInstructionLabel(cell)
case let cell as TextLabelTableViewCell where row == .checkSpam:
configureCheckSpamLabel(cell)
case let cell as TextLabelTableViewCell where row == .oops:
configureoopsLabel(cell)
default:
DDLogError("Error: Unidentified tableViewCell type found.")
}
Expand All @@ -167,6 +169,12 @@ private extension SignupMagicLinkViewController {
func configureCheckSpamLabel(_ cell: TextLabelTableViewCell) {
cell.configureLabel(text: WordPressAuthenticator.shared.displayStrings.checkSpamInstructions, style: .body)
}

/// Configure the "Check spam" cell.
///
func configureoopsLabel(_ cell: TextLabelTableViewCell) {
cell.configureLabel(text: WordPressAuthenticator.shared.displayStrings.oopsInstructions, style: .body)
}

// MARK: - Private Constants

Expand All @@ -176,12 +184,13 @@ private extension SignupMagicLinkViewController {
case persona
case instructions
case checkSpam
case oops

var reuseIdentifier: String {
switch self {
case .persona:
return GravatarEmailTableViewCell.reuseIdentifier
case .instructions, .checkSpam:
case .instructions, .checkSpam, .oops:
return TextLabelTableViewCell.reuseIdentifier
}
}
Expand Down