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

Commit 1263e36

Browse files
committed
Merge remote-tracking branch 'origin/develop'
2 parents 1d2dd92 + cb877e1 commit 1263e36

File tree

7 files changed

+65
-11
lines changed

7 files changed

+65
-11
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-beta.9"
3+
s.version = "1.8.0-beta.12"
44
s.summary = "WordPressAuthenticator implements an easy and elegant way to authenticate your WordPress Apps."
55

66
s.description = <<-DESC

WordPressAuthenticator/Authenticator/WordPressAuthenticatorStyles.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ public struct WordPressAuthenticatorStyle {
5757
///
5858
public let viewControllerBackgroundColor: UIColor
5959

60+
public let textFieldBackgroundColor: UIColor
61+
6062
/// Style: nav bar
6163
///
6264
public let navBarImage: UIImage
@@ -77,7 +79,7 @@ public struct WordPressAuthenticatorStyle {
7779

7880
/// Designated initializer
7981
///
80-
public init(primaryNormalBackgroundColor: UIColor, primaryNormalBorderColor: UIColor, primaryHighlightBackgroundColor: UIColor, primaryHighlightBorderColor: UIColor, secondaryNormalBackgroundColor: UIColor, secondaryNormalBorderColor: UIColor, secondaryHighlightBackgroundColor: UIColor, secondaryHighlightBorderColor: UIColor, disabledBackgroundColor: UIColor, disabledBorderColor: UIColor, primaryTitleColor: UIColor, secondaryTitleColor: UIColor, disabledTitleColor: UIColor, textButtonColor: UIColor, textButtonHighlightColor: UIColor, instructionColor: UIColor, subheadlineColor: UIColor, placeholderColor: UIColor, viewControllerBackgroundColor: UIColor, navBarImage: UIImage, navBarBadgeColor: UIColor, prologueBackgroundColor: UIColor = WPStyleGuide.wordPressBlue(), prologueTitleColor: UIColor = .white, statusBarStyle: UIStatusBarStyle = .lightContent) {
82+
public init(primaryNormalBackgroundColor: UIColor, primaryNormalBorderColor: UIColor, primaryHighlightBackgroundColor: UIColor, primaryHighlightBorderColor: UIColor, secondaryNormalBackgroundColor: UIColor, secondaryNormalBorderColor: UIColor, secondaryHighlightBackgroundColor: UIColor, secondaryHighlightBorderColor: UIColor, disabledBackgroundColor: UIColor, disabledBorderColor: UIColor, primaryTitleColor: UIColor, secondaryTitleColor: UIColor, disabledTitleColor: UIColor, textButtonColor: UIColor, textButtonHighlightColor: UIColor, instructionColor: UIColor, subheadlineColor: UIColor, placeholderColor: UIColor, viewControllerBackgroundColor: UIColor, textFieldBackgroundColor: UIColor, navBarImage: UIImage, navBarBadgeColor: UIColor, prologueBackgroundColor: UIColor = WPStyleGuide.wordPressBlue(), prologueTitleColor: UIColor = .white, statusBarStyle: UIStatusBarStyle = .lightContent) {
8183
self.primaryNormalBackgroundColor = primaryNormalBackgroundColor
8284
self.primaryNormalBorderColor = primaryNormalBorderColor
8385
self.primaryHighlightBackgroundColor = primaryHighlightBackgroundColor
@@ -97,6 +99,7 @@ public struct WordPressAuthenticatorStyle {
9799
self.subheadlineColor = subheadlineColor
98100
self.placeholderColor = placeholderColor
99101
self.viewControllerBackgroundColor = viewControllerBackgroundColor
102+
self.textFieldBackgroundColor = textFieldBackgroundColor
100103
self.navBarImage = navBarImage
101104
self.navBarBadgeColor = navBarBadgeColor
102105
self.prologueBackgroundColor = prologueBackgroundColor

WordPressAuthenticator/Extensions/WPStyleGuide+Login.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,10 @@ extension WPStyleGuide {
124124
class func appleLoginButton() -> UIControl {
125125
#if XCODE11
126126
if #available(iOS 13.0, *) {
127-
let appleButton = ASAuthorizationAppleIDButton(authorizationButtonType: .continue, authorizationButtonStyle: .black)
127+
let traits = UITraitCollection.current
128+
let buttonStyle: ASAuthorizationAppleIDButton.Style = (traits.userInterfaceStyle == .dark) ? .white : .black
129+
130+
let appleButton = ASAuthorizationAppleIDButton(authorizationButtonType: .continue, authorizationButtonStyle: buttonStyle)
128131
appleButton.translatesAutoresizingMaskIntoConstraints = false
129132
appleButton.heightAnchor.constraint(greaterThanOrEqualToConstant: Constants.buttonMinHeight).isActive = true
130133
return appleButton

WordPressAuthenticator/NUX/WPWalkthroughTextField.m

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,10 @@ - (void)commonInit
9595
};
9696
self.attributedPlaceholder = [[NSAttributedString alloc] initWithString:self.placeholder attributes:attributes];
9797
}
98+
99+
if (@available(iOS 13.0, *)) {
100+
self.leadingViewInsets = UIEdgeInsetsMake(0, 0, 0, LeftImageSpacing);
101+
}
98102
}
99103

100104
- (void)awakeFromNib {

WordPressAuthenticator/Services/SignupService.swift

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ class SignupService {
5151
func createWPComUserWithApple(token: String,
5252
email: String,
5353
fullName: String?,
54-
success: @escaping (_ newAccount: Bool, _ username: String, _ wpcomToken: String) -> Void,
54+
success: @escaping (_ newAccount: Bool, _ existingNonSocialAccount: Bool, _ username: String, _ wpcomToken: String) -> Void,
5555
failure: @escaping (_ error: Error) -> Void) {
5656
let remote = WordPressComServiceRemote(wordPressComRestApi: anonymousAPI)
5757

@@ -68,8 +68,16 @@ class SignupService {
6868
}
6969

7070
let createdAccount = (response?[ResponseKeys.createdAccount] as? Int ?? 0) == 1
71-
success(createdAccount, username, bearer_token)
71+
success(createdAccount, false, username, bearer_token)
7272
}, failure: { error in
73+
if let error = (error as NSError?) {
74+
let existingNonSocialAccount = (error.userInfo[ErrorKeys.errorCode] as? String ?? "") == ErrorKeys.existingNonSocialUser
75+
if existingNonSocialAccount {
76+
success(false, true, "", "")
77+
return
78+
}
79+
}
80+
7381
failure(error ?? SignupError.unknown)
7482
})
7583
}
@@ -96,6 +104,11 @@ private extension SignupService {
96104
static let username = "username"
97105
static let createdAccount = "created_account"
98106
}
107+
108+
struct ErrorKeys {
109+
static let errorCode = "WordPressComRestApiErrorCodeKey"
110+
static let existingNonSocialUser = "user_exists"
111+
}
99112
}
100113

101114

WordPressAuthenticator/Signin/AppleAuthenticator.swift

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import Foundation
22
import AuthenticationServices
33
import WordPressKit
4+
import SVProgressHUD
45

56
#if XCODE11
67

@@ -57,19 +58,27 @@ private extension AppleAuthenticator {
5758
@available(iOS 13.0, *)
5859
func createWordPressComUser(appleCredentials: ASAuthorizationAppleIDCredential) {
5960
guard let identityToken = appleCredentials.identityToken,
60-
let token = String(data: identityToken, encoding: .utf8),
61-
let email = appleCredentials.email else {
61+
let token = String(data: identityToken, encoding: .utf8) else {
6262
DDLogError("Apple Authenticator: invalid Apple credentials.")
6363
return
6464
}
6565

66+
SVProgressHUD.show(withStatus: NSLocalizedString("Continuing with Apple", comment: "Shown while logging in with Apple and the app waits for the site creation process to complete."))
67+
68+
let email = appleCredentials.email ?? ""
6669
let name = fullName(from: appleCredentials.fullName)
6770

6871
updateLoginFields(email: email, fullName: name, token: token)
6972

7073
let service = SignupService()
7174
service.createWPComUserWithApple(token: token, email: email, fullName: name,
72-
success: { [weak self] accountCreated, wpcomUsername, wpcomToken in
75+
success: { [weak self] accountCreated, existingNonSocialAccount, wpcomUsername, wpcomToken in
76+
SVProgressHUD.dismiss()
77+
78+
guard !existingNonSocialAccount else {
79+
self?.logInInstead()
80+
return
81+
}
7382

7483
let wpcom = WordPressComCredentials(authToken: wpcomToken, isJetpackLogin: false, multifactor: false, siteURL: self?.loginFields.siteAddress ?? "")
7584
let credentials = AuthenticatorCredentials(wpcom: wpcom)
@@ -79,12 +88,15 @@ private extension AppleAuthenticator {
7988
self?.authenticationDelegate.createdWordPressComAccount(username: wpcomUsername, authToken: wpcomToken)
8089
self?.signupSuccessful(with: credentials)
8190
return
91+
} else {
92+
self?.authenticationDelegate.createdWordPressComAccount(username: wpcomUsername, authToken: wpcomToken)
93+
self?.signinSuccessful(with: credentials)
94+
return
8295
}
83-
84-
// Existing WP Account
85-
self?.logInInstead()
8696

8797
}, failure: { [weak self] error in
98+
SVProgressHUD.dismiss()
99+
88100
self?.signupFailed(with: error)
89101
})
90102
}
@@ -95,6 +107,11 @@ private extension AppleAuthenticator {
95107
showSignupEpilogue(for: credentials)
96108
}
97109

110+
func signinSuccessful(with credentials: AuthenticatorCredentials) {
111+
// TODO: Tracks events for login
112+
showSigninEpilogue(for: credentials)
113+
}
114+
98115
func showSignupEpilogue(for credentials: AuthenticatorCredentials) {
99116
guard let navigationController = showFromViewController?.navigationController else {
100117
fatalError()
@@ -107,6 +124,14 @@ private extension AppleAuthenticator {
107124
authenticationDelegate.presentSignupEpilogue(in: navigationController, for: credentials, service: service)
108125
}
109126

127+
func showSigninEpilogue(for credentials: AuthenticatorCredentials) {
128+
guard let navigationController = showFromViewController?.navigationController else {
129+
fatalError()
130+
}
131+
132+
authenticationDelegate.presentLoginEpilogue(in: navigationController, for: credentials) {}
133+
}
134+
110135
func signupFailed(with error: Error) {
111136
WPAnalytics.track(.signupSocialFailure)
112137
DDLogError("Apple Authenticator: signup failed. error: \(error)")

WordPressAuthenticator/UI/LoginTextField.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@ import WordPressShared
33

44
open class LoginTextField: WPWalkthroughTextField {
55

6+
open override func awakeFromNib() {
7+
super.awakeFromNib()
8+
9+
backgroundColor = WordPressAuthenticator.shared.style.textFieldBackgroundColor
10+
}
11+
612
override open func draw(_ rect: CGRect) {
713
if showTopLineSeparator {
814
guard let context = UIGraphicsGetCurrentContext() else {

0 commit comments

Comments
 (0)