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

Commit 03a03f9

Browse files
committed
Merge branch 'develop'
2 parents 4635a18 + 299c337 commit 03a03f9

File tree

7 files changed

+65
-25
lines changed

7 files changed

+65
-25
lines changed

WordPressAuthenticator.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Pod::Spec.new do |s|
22
s.name = "WordPressAuthenticator"
3-
s.version = "1.8.0"
3+
s.version = "1.8.1-beta.1"
44
s.summary = "WordPressAuthenticator implements an easy and elegant way to authenticate your WordPress Apps."
55

66
s.description = <<-DESC

WordPressAuthenticator/Authenticator/WordPressSupportSourceTag.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ extension WordPressSupportSourceTag {
2727
public static var loginEmail: WordPressSupportSourceTag {
2828
return WordPressSupportSourceTag(name: "loginEmail", origin: "origin:login-email")
2929
}
30+
public static var loginApple: WordPressSupportSourceTag {
31+
return WordPressSupportSourceTag(name: "loginApple", origin: "origin:login-apple")
32+
}
3033
public static var login2FA: WordPressSupportSourceTag {
3134
return WordPressSupportSourceTag(name: "login2FA", origin: "origin:login-2fa")
3235
}
@@ -57,4 +60,8 @@ extension WordPressSupportSourceTag {
5760
public static var wpComSignupMagicLink: WordPressSupportSourceTag {
5861
return WordPressSupportSourceTag(name: "wpComSignupMagicLink", origin: "origin:signup-magic-link")
5962
}
63+
public static var wpComSignupApple: WordPressSupportSourceTag {
64+
return WordPressSupportSourceTag(name: "wpComSignupApple", origin: "origin:signup-apple")
65+
}
66+
6067
}

WordPressAuthenticator/Extensions/FancyAlertViewController+LoginError.swift

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -131,25 +131,33 @@ extension FancyAlertViewController {
131131
}
132132

133133

134-
/// Shows a generic error message. The view
135-
/// is configured so the user can open Support for assistance.
134+
/// Shows a generic error message.
135+
/// If Support is enabled, the view is configured so the user can open Support for assistance.
136136
///
137137
/// - Parameter message: The error message to show.
138138
/// - Parameter sourceTag: tag of the source of the error
139139
///
140140
static func alertForGenericErrorMessageWithHelpButton(_ message: String, loginFields: LoginFields, sourceTag: WordPressSupportSourceTag) -> FancyAlertViewController {
141-
let moreHelpButton = ButtonConfig(Strings.moreHelp) { controller, _ in
142-
controller.dismiss(animated: true) {
143-
// Find the topmost view controller that we can present from
144-
guard let appDelegate = UIApplication.shared.delegate,
145-
let window = appDelegate.window,
146-
let viewController = window?.topmostPresentedViewController,
147-
WordPressAuthenticator.shared.delegate?.supportEnabled == true
148-
else {
149-
return
150-
}
151141

152-
WordPressAuthenticator.shared.delegate?.presentSupportRequest(from: viewController, sourceTag: sourceTag)
142+
// If support is not enabled, don't add a Help Button since it won't do anything.
143+
var moreHelpButton: ButtonConfig? = nil
144+
145+
if WordPressAuthenticator.shared.delegate?.supportEnabled == false {
146+
DDLogInfo("Error Alert: Support not enabled. Hiding Help button.")
147+
} else {
148+
moreHelpButton = ButtonConfig(Strings.moreHelp) { controller, _ in
149+
controller.dismiss(animated: true) {
150+
// Find the topmost view controller that we can present from
151+
guard let appDelegate = UIApplication.shared.delegate,
152+
let window = appDelegate.window,
153+
let viewController = window?.topmostPresentedViewController,
154+
WordPressAuthenticator.shared.delegate?.supportEnabled == true
155+
else {
156+
return
157+
}
158+
159+
WordPressAuthenticator.shared.delegate?.presentSupportRequest(from: viewController, sourceTag: sourceTag)
160+
}
153161
}
154162
}
155163

@@ -162,6 +170,7 @@ extension FancyAlertViewController {
162170
moreInfoButton: moreHelpButton,
163171
titleAccessoryButton: nil,
164172
dismissAction: nil)
173+
165174
return FancyAlertViewController.controllerWithConfiguration(configuration: config)
166175
}
167176

WordPressAuthenticator/Signin/AppleAuthenticator.swift

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import SVProgressHUD
77

88
@objc protocol AppleAuthenticatorDelegate {
99
func showWPComLogin(loginFields: LoginFields)
10+
func authFailedWithError(message: String)
1011
}
1112

1213
class AppleAuthenticator: NSObject {
@@ -83,20 +84,16 @@ private extension AppleAuthenticator {
8384
let wpcom = WordPressComCredentials(authToken: wpcomToken, isJetpackLogin: false, multifactor: false, siteURL: self?.loginFields.siteAddress ?? "")
8485
let credentials = AuthenticatorCredentials(wpcom: wpcom)
8586

86-
// New WP Account
87+
self?.authenticationDelegate.createdWordPressComAccount(username: wpcomUsername, authToken: wpcomToken)
88+
8789
if accountCreated {
88-
self?.authenticationDelegate.createdWordPressComAccount(username: wpcomUsername, authToken: wpcomToken)
8990
self?.signupSuccessful(with: credentials)
90-
return
9191
} else {
92-
self?.authenticationDelegate.createdWordPressComAccount(username: wpcomUsername, authToken: wpcomToken)
93-
self?.signinSuccessful(with: credentials)
94-
return
92+
self?.loginSuccessful(with: credentials)
9593
}
96-
94+
9795
}, failure: { [weak self] error in
9896
SVProgressHUD.dismiss()
99-
10097
self?.signupFailed(with: error)
10198
})
10299
}
@@ -107,7 +104,7 @@ private extension AppleAuthenticator {
107104
showSignupEpilogue(for: credentials)
108105
}
109106

110-
func signinSuccessful(with credentials: AuthenticatorCredentials) {
107+
func loginSuccessful(with credentials: AuthenticatorCredentials) {
111108
// TODO: Tracks events for login
112109
showSigninEpilogue(for: credentials)
113110
}
@@ -133,8 +130,9 @@ private extension AppleAuthenticator {
133130
}
134131

135132
func signupFailed(with error: Error) {
133+
DDLogError("Apple Authenticator: Signup failed. error: \(error.localizedDescription)")
136134
WPAnalytics.track(.signupSocialFailure)
137-
DDLogError("Apple Authenticator: signup failed. error: \(error)")
135+
delegate?.authFailedWithError(message: error.localizedDescription)
138136
}
139137

140138
func logInInstead() {
@@ -174,7 +172,16 @@ extension AppleAuthenticator: ASAuthorizationControllerDelegate {
174172
}
175173

176174
func authorizationController(controller: ASAuthorizationController, didCompleteWithError error: Error) {
177-
DDLogError("Apple Authenticator: didCompleteWithError: \(error)")
175+
176+
// Don't show error if user cancelled authentication.
177+
if let authorizationError = error as? ASAuthorizationError,
178+
authorizationError.code == .canceled {
179+
return
180+
}
181+
182+
DDLogError("Apple Authenticator: didCompleteWithError: \(error.localizedDescription)")
183+
let message = NSLocalizedString("Apple authentication failed.", comment: "Message shown when Apple authentication fails.")
184+
delegate?.authFailedWithError(message: message)
178185
}
179186

180187
}

WordPressAuthenticator/Signin/LoginEmailViewController.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -639,9 +639,15 @@ extension LoginEmailViewController: GIDSignInUIDelegate {
639639

640640
#if XCODE11
641641
extension LoginEmailViewController: AppleAuthenticatorDelegate {
642+
642643
func showWPComLogin(loginFields: LoginFields) {
643644
self.loginFields = loginFields
644645
performSegue(withIdentifier: .showWPComLogin, sender: self)
645646
}
647+
648+
func authFailedWithError(message: String) {
649+
displayErrorAlert(message, sourceTag: .wpComSignupApple)
650+
}
651+
646652
}
647653
#endif

WordPressAuthenticator/Signin/LoginPrologueViewController.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,9 +128,15 @@ class LoginPrologueViewController: LoginViewController {
128128

129129
#if XCODE11
130130
extension LoginPrologueViewController: AppleAuthenticatorDelegate {
131+
131132
func showWPComLogin(loginFields: LoginFields) {
132133
self.loginFields = loginFields
133134
performSegue(withIdentifier: .showWPComLogin, sender: self)
134135
}
136+
137+
func authFailedWithError(message: String) {
138+
displayErrorAlert(message, sourceTag: .loginApple)
139+
}
140+
135141
}
136142
#endif

WordPressAuthenticator/Signin/LoginSiteAddressViewController.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -370,9 +370,14 @@ class LoginSiteAddressViewController: LoginViewController, NUXKeyboardResponder
370370

371371
#if XCODE11
372372
extension LoginSiteAddressViewController: AppleAuthenticatorDelegate {
373+
373374
func showWPComLogin(loginFields: LoginFields) {
374375
self.loginFields = loginFields
375376
performSegue(withIdentifier: .showWPComLogin, sender: self)
376377
}
378+
379+
func authFailedWithError(message: String) {
380+
displayErrorAlert(message, sourceTag: .loginApple)
381+
}
377382
}
378383
#endif

0 commit comments

Comments
 (0)