Skip to content
This repository was archived by the owner on Feb 5, 2025. It is now read-only.

Commit 5c44ca8

Browse files
authored
Merge pull request #630 from wordpress-mobile/fix/username-autofill
Improve username handling with password autofill
2 parents 28205e1 + 926667a commit 5c44ca8

File tree

2 files changed

+32
-7
lines changed

2 files changed

+32
-7
lines changed

WordPressAuthenticator.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
Pod::Spec.new do |s|
44
s.name = 'WordPressAuthenticator'
5-
s.version = '1.42.2-beta.1'
5+
s.version = '1.42.2-beta.2'
66

77
s.summary = 'WordPressAuthenticator implements an easy and elegant way to authenticate your WordPress Apps.'
88
s.description = <<-DESC

WordPressAuthenticator/Unified Auth/View Related/Get Started/GetStartedViewController.swift

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,11 @@ class GetStartedViewController: LoginViewController {
6060

6161
override func viewWillAppear(_ animated: Bool) {
6262
super.viewWillAppear(animated)
63-
configureSubmitButton(animating: false)
63+
64+
refreshEmailField()
65+
66+
// Ensure the continue button matches the validity of the email field
67+
configureContinueButton(animating: false)
6468

6569
if errorMessage != nil {
6670
shouldChangeVoiceOverFocus = true
@@ -116,6 +120,11 @@ class GetStartedViewController: LoginViewController {
116120
return !animating && canSubmit()
117121
}
118122

123+
private func refreshEmailField() {
124+
// It's possible that the password screen could have changed the loginFields username, for example when using
125+
// autofill from a password manager. Let's ensure the loginFields matches the email field.
126+
loginFields.username = emailField?.nonNilTrimmedText() ?? loginFields.username
127+
}
119128
}
120129

121130
// MARK: - UITableViewDataSource
@@ -337,12 +346,11 @@ private extension GetStartedViewController {
337346
/// social signin does not require form validation.
338347
///
339348
func validateForm() {
340-
341349
loginFields.meta.socialService = nil
342350
displayError(message: "")
343351

344352
guard EmailFormatValidator.validate(string: loginFields.username) else {
345-
present(buildInvalidEmailAlert(), animated: true, completion: nil)
353+
present(buildInvalidEmailAlertGeneric(), animated: true, completion: nil)
346354
return
347355
}
348356

@@ -461,7 +469,7 @@ private extension GetStartedViewController {
461469

462470
let email = loginFields.username
463471
guard email.isValidEmail() else {
464-
present(buildInvalidEmailAlert(), animated: true, completion: nil)
472+
present(buildInvalidEmailLinkAlert(), animated: true, completion: nil)
465473
return
466474
}
467475

@@ -498,13 +506,30 @@ private extension GetStartedViewController {
498506
navigationController?.pushViewController(vc, animated: true)
499507
}
500508

501-
/// Build the alert message when the email address is invalid.
509+
/// Build the alert message when the email address is invalid
502510
///
503-
func buildInvalidEmailAlert() -> UIAlertController {
511+
private func buildInvalidEmailAlertGeneric() -> UIAlertController {
512+
let title = NSLocalizedString("Invalid Email Address",
513+
comment: "Title of an alert letting the user know the email address that they've entered isn't valid")
514+
let message = NSLocalizedString("Please enter a valid email address for a WordPress.com account.",
515+
comment: "An error message.")
516+
517+
return buildInvalidEmailAlert(title: title, message: message)
518+
}
519+
520+
/// Build the alert message when the email address is invalid so a link cannot be requested
521+
///
522+
private func buildInvalidEmailLinkAlert() -> UIAlertController {
504523
let title = NSLocalizedString("Can Not Request Link",
505524
comment: "Title of an alert letting the user know")
506525
let message = NSLocalizedString("A valid email address is needed to mail an authentication link. Please return to the previous screen and provide a valid email address.",
507526
comment: "An error message.")
527+
528+
return buildInvalidEmailAlert(title: title, message: message)
529+
}
530+
531+
private func buildInvalidEmailAlert(title: String, message: String) -> UIAlertController {
532+
508533
let helpActionTitle = NSLocalizedString("Need help?",
509534
comment: "Takes the user to get help")
510535
let okActionTitle = NSLocalizedString("OK",

0 commit comments

Comments
 (0)