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

Commit 425669c

Browse files
Merge pull request #649 from wordpress-mobile/feature/woo-store-cred-sign-in
[Login- "Enter Your Store Address" flow] - Add `Sign in with site credentials` option.
2 parents 76ef761 + cf1d145 commit 425669c

File tree

13 files changed

+378
-137
lines changed

13 files changed

+378
-137
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 = '2.0.1'
5+
s.version = '2.1.0-beta.2'
66

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

WordPressAuthenticator.xcodeproj/project.pbxproj

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -160,8 +160,6 @@
160160
D8610CEC2570A60C00A5DF27 /* NavigationToRootTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = D8610CEB2570A60C00A5DF27 /* NavigationToRootTests.swift */; };
161161
D8611A63257622ED00A5DF27 /* NavigateBack.swift in Sources */ = {isa = PBXBuildFile; fileRef = D8611A62257622ED00A5DF27 /* NavigateBack.swift */; };
162162
D8611A672576236800A5DF27 /* NavigateBackTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = D8611A662576236800A5DF27 /* NavigateBackTests.swift */; };
163-
D87F120B2586DA26005675C5 /* SpacerTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = D87F12092586DA26005675C5 /* SpacerTableViewCell.swift */; };
164-
D87F120C2586DA26005675C5 /* SpacerTableViewCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = D87F120A2586DA26005675C5 /* SpacerTableViewCell.xib */; };
165163
D881A30D256B5A7900FE5605 /* NavigationCommand.swift in Sources */ = {isa = PBXBuildFile; fileRef = D881A30C256B5A7900FE5605 /* NavigationCommand.swift */; };
166164
D881A311256B5B4700FE5605 /* NavigateToEnterSite.swift in Sources */ = {isa = PBXBuildFile; fileRef = D881A310256B5B4700FE5605 /* NavigateToEnterSite.swift */; };
167165
D881A315256B5B5800FE5605 /* NavigateToEnterAccount.swift in Sources */ = {isa = PBXBuildFile; fileRef = D881A314256B5B5800FE5605 /* NavigateToEnterAccount.swift */; };
@@ -373,8 +371,6 @@
373371
D8610CEB2570A60C00A5DF27 /* NavigationToRootTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NavigationToRootTests.swift; sourceTree = "<group>"; };
374372
D8611A62257622ED00A5DF27 /* NavigateBack.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NavigateBack.swift; sourceTree = "<group>"; };
375373
D8611A662576236800A5DF27 /* NavigateBackTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NavigateBackTests.swift; sourceTree = "<group>"; };
376-
D87F12092586DA26005675C5 /* SpacerTableViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SpacerTableViewCell.swift; sourceTree = "<group>"; };
377-
D87F120A2586DA26005675C5 /* SpacerTableViewCell.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = SpacerTableViewCell.xib; sourceTree = "<group>"; };
378374
D881A30C256B5A7900FE5605 /* NavigationCommand.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NavigationCommand.swift; sourceTree = "<group>"; };
379375
D881A310256B5B4700FE5605 /* NavigateToEnterSite.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NavigateToEnterSite.swift; sourceTree = "<group>"; };
380376
D881A314256B5B5800FE5605 /* NavigateToEnterAccount.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NavigateToEnterAccount.swift; sourceTree = "<group>"; };
@@ -877,8 +873,6 @@
877873
CE6BCD3724A3CB5E001BCDC5 /* TextLinkButtonTableViewCell.xib */,
878874
98F40AEF24F5E13200A72911 /* TextWithLinkTableViewCell.swift */,
879875
98F40AEE24F5E13200A72911 /* TextWithLinkTableViewCell.xib */,
880-
D87F12092586DA26005675C5 /* SpacerTableViewCell.swift */,
881-
D87F120A2586DA26005675C5 /* SpacerTableViewCell.xib */,
882876
);
883877
path = "Reusable Views";
884878
sourceTree = "<group>";
@@ -1066,7 +1060,6 @@
10661060
CE1BBF8D24D48580001D2E3E /* GravatarEmailTableViewCell.xib in Resources */,
10671061
B560913F208A563800399AE4 /* Login.storyboard in Resources */,
10681062
CE6BCD3924A3CB5E001BCDC5 /* TextLinkButtonTableViewCell.xib in Resources */,
1069-
D87F120C2586DA26005675C5 /* SpacerTableViewCell.xib in Resources */,
10701063
CE6BCD2F24A3A235001BCDC5 /* TextLabelTableViewCell.xib in Resources */,
10711064
98CF18F9248725620047B66C /* GoogleSignupConfirmation.storyboard in Resources */,
10721065
B5609137208A563800399AE4 /* EmailMagicLink.storyboard in Resources */,
@@ -1224,7 +1217,6 @@
12241217
CE2D03E024E5DD4500D18942 /* UnifiedSignupViewController.swift in Sources */,
12251218
98CF18F7248725370047B66C /* GoogleSignupConfirmationViewController.swift in Sources */,
12261219
1A21EE9822832BC300C940C6 /* WordPressComOAuthClientFacade+Swift.swift in Sources */,
1227-
D87F120B2586DA26005675C5 /* SpacerTableViewCell.swift in Sources */,
12281220
CEC77C6624854F2E00FB9050 /* SiteAddressViewController.swift in Sources */,
12291221
CEDE0D952420121D00CB3345 /* UIStoryboard+Helpers.swift in Sources */,
12301222
B5ED7920207E993E00A8FD8C /* WPAuthenticatorLogging.m in Sources */,

WordPressAuthenticator/Analytics/AuthenticatorAnalyticsTracker.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,10 @@ public class AuthenticatorAnalyticsTracker {
233233
/// When the user clicks on “Create account” on the signup confirmation screen
234234
///
235235
case createAccount = "create_account"
236+
237+
/// When the user taps of "Sign in with site credentials" button in `GetStartedViewController`
238+
///
239+
case signInWithSiteCredentials = "sign_in_with_site_credentials"
236240
}
237241

238242
/// Shared Instance.

WordPressAuthenticator/Authenticator/WordPressAuthenticatorConfiguration.swift

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,15 @@ public struct WordPressAuthenticatorConfiguration {
9595
/// Default value is disabled
9696
let continueWithSiteAddressFirst: Bool
9797

98+
/// If enabled shows a "Sign in with site credentials" button in `GetStartedViewController` when landing in the screen after entering site address
99+
/// Used to enable sign-in to self-hosted sites using WordPress.org credentials.
100+
/// Disabled by default
101+
let enableSiteCredentialsLoginForSelfHostedSites: Bool
102+
103+
/// If enabled, we will ask for WPCOM login after signing in using .org site credentials.
104+
/// Disabled by default
105+
let isWPComLoginRequiredForSiteCredentialsLogin: Bool
106+
98107
/// Designated Initializer
99108
///
100109
public init (wpcomClientId: String,
@@ -115,7 +124,9 @@ public struct WordPressAuthenticatorConfiguration {
115124
enableUnifiedAuth: Bool = false,
116125
enableUnifiedCarousel: Bool = false,
117126
displayHintButtons: Bool = true,
118-
continueWithSiteAddressFirst: Bool = false) {
127+
continueWithSiteAddressFirst: Bool = false,
128+
enableSiteCredentialsLoginForSelfHostedSites: Bool = false,
129+
isWPComLoginRequiredForSiteCredentialsLogin: Bool = false) {
119130

120131
self.wpcomClientId = wpcomClientId
121132
self.wpcomSecret = wpcomSecret
@@ -136,5 +147,7 @@ public struct WordPressAuthenticatorConfiguration {
136147
self.displayHintButtons = displayHintButtons
137148
self.enableSignupWithGoogle = enableSignupWithGoogle
138149
self.continueWithSiteAddressFirst = continueWithSiteAddressFirst
150+
self.enableSiteCredentialsLoginForSelfHostedSites = enableSiteCredentialsLoginForSelfHostedSites
151+
self.isWPComLoginRequiredForSiteCredentialsLogin = isWPComLoginRequiredForSiteCredentialsLogin
139152
}
140153
}

WordPressAuthenticator/Authenticator/WordPressAuthenticatorDisplayStrings.swift

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ public struct WordPressAuthenticatorDisplayStrings {
2929
public let createAccountButtonTitle: String
3030
public let continueWithWPButtonTitle: String
3131
public let enterYourSiteAddressButtonTitle: String
32+
public let signInWithSiteCredentialsButtonTitle: String
3233

3334
/// Large titles displayed in unified auth flows.
3435
///
@@ -78,6 +79,7 @@ public struct WordPressAuthenticatorDisplayStrings {
7879
createAccountButtonTitle: String = defaultStrings.createAccountButtonTitle,
7980
continueWithWPButtonTitle: String = defaultStrings.continueWithWPButtonTitle,
8081
enterYourSiteAddressButtonTitle: String = defaultStrings.enterYourSiteAddressButtonTitle,
82+
signInWithSiteCredentialsButtonTitle: String = defaultStrings.signInWithSiteCredentialsButtonTitle,
8183
findSiteButtonTitle: String = defaultStrings.findSiteButtonTitle,
8284
resetPasswordButtonTitle: String = defaultStrings.resetPasswordButtonTitle,
8385
getLoginLinkButtonTitle: String = defaultStrings.getLoginLinkButtonTitle,
@@ -115,6 +117,7 @@ public struct WordPressAuthenticatorDisplayStrings {
115117
self.createAccountButtonTitle = createAccountButtonTitle
116118
self.continueWithWPButtonTitle = continueWithWPButtonTitle
117119
self.enterYourSiteAddressButtonTitle = enterYourSiteAddressButtonTitle
120+
self.signInWithSiteCredentialsButtonTitle = signInWithSiteCredentialsButtonTitle
118121
self.findSiteButtonTitle = findSiteButtonTitle
119122
self.resetPasswordButtonTitle = resetPasswordButtonTitle
120123
self.getLoginLinkButtonTitle = getLoginLinkButtonTitle
@@ -176,6 +179,8 @@ public extension WordPressAuthenticatorDisplayStrings {
176179
comment: "Button title. Takes the user to the login by email flow."),
177180
enterYourSiteAddressButtonTitle: NSLocalizedString("Enter your existing site address",
178181
comment: "Button title. Takes the user to the login by site address flow."),
182+
signInWithSiteCredentialsButtonTitle: NSLocalizedString("Sign in with site credentials",
183+
comment: "Button title. Takes the user the Enter site credentials screen."),
179184
findSiteButtonTitle: NSLocalizedString("Find your site address",
180185
comment: "The hint button's title text to help users find their site address."),
181186
resetPasswordButtonTitle: NSLocalizedString("Reset your password",
@@ -186,8 +191,8 @@ public extension WordPressAuthenticatorDisplayStrings {
186191
comment: "The button's title text to send a 2FA code via SMS text message."),
187192
loginTermsOfService: NSLocalizedString("By continuing, you agree to our _Terms of Service_.", comment: "Legal disclaimer for logging in. The underscores _..._ denote underline."),
188193
signupTermsOfService: NSLocalizedString("If you continue with Apple or Google and don't already have a WordPress.com account, you are creating an account and you agree to our _Terms of Service_.", comment: "Legal disclaimer for signing up. The underscores _..._ denote underline."),
189-
whatIsWPComLinkTitle: NSLocalizedString("_What is WordPress.com?_",
190-
comment: "Navigates to page with details about What is WordPress.com. The underscores _..._ denote underline."),
194+
whatIsWPComLinkTitle: NSLocalizedString("What is WordPress.com?",
195+
comment: "Navigates to page with details about What is WordPress.com."),
191196
getStartedTitle: NSLocalizedString("Get Started",
192197
comment: "View title for initial auth views."),
193198
logInTitle: NSLocalizedString("Log In",

WordPressAuthenticator/Credentials/WordPressOrgCredentials.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,12 @@ public struct WordPressOrgCredentials: Equatable {
3030
self.xmlrpc = xmlrpc
3131
self.options = options
3232
}
33+
34+
/// Returns site URL by stripping "/xmlrpc.php" from `xmlrpc` String property
35+
///
36+
public var siteURL: String {
37+
xmlrpc.removingSuffix("/xmlrpc.php")
38+
}
3339
}
3440

3541
// MARK: - Equatable Conformance

WordPressAuthenticator/Extensions/WPStyleGuide+Login.swift

Lines changed: 55 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -115,17 +115,13 @@ extension WPStyleGuide {
115115

116116
return NSAttributedString(attachment: googleAttachment)
117117
} else {
118-
// Create an attributed string that contains the Google icon + button text.
119118
let nuxButtonTitleFont = WPStyleGuide.mediumWeightFont(forStyle: .title3)
120-
googleAttachment.bounds = CGRect(x: 0, y: (nuxButtonTitleFont.capHeight - Constants.googleIconButtonSize) / 2,
121-
width: Constants.googleIconButtonSize, height: Constants.googleIconButtonSize)
122-
123-
let buttonString = NSMutableAttributedString(attachment: googleAttachment)
124-
// Add leading non-breaking spaces to separate the button text from the Google logo.
125-
let googleTitle = "\u{00a0}\u{00a0}" + NSLocalizedString("Continue with Google", comment: "Button title. Tapping begins log in using Google.")
126-
buttonString.append(NSAttributedString(string: googleTitle))
127-
128-
return buttonString
119+
let googleTitle = NSLocalizedString("Continue with Google",
120+
comment: "Button title. Tapping begins log in using Google.")
121+
return attributedStringwithLogo(googleIcon,
122+
imageSize: .init(width: Constants.googleIconButtonSize, height: Constants.googleIconButtonSize),
123+
title: googleTitle,
124+
titleFont: nuxButtonTitleFont)
129125
}
130126
}
131127

@@ -152,6 +148,21 @@ extension WPStyleGuide {
152148
return NSAttributedString(attributedString: attributedString)
153149
}
154150

151+
/// Creates an attributed string that includes the `linkFieldImage`
152+
///
153+
/// - Returns: A properly styled NSAttributedString to be displayed on a NUXButton.
154+
///
155+
class func formattedSignInWithSiteCredentialsString() -> NSAttributedString {
156+
let title = NSLocalizedString(WordPressAuthenticator.shared.displayStrings.signInWithSiteCredentialsButtonTitle,
157+
comment: "Button title. Tapping opens the site credentials screen.")
158+
let globe = UIImage.gridicon(.globe)
159+
let image = globe.imageWithTintColor(WordPressAuthenticator.shared.style.placeholderColor) ?? globe
160+
return attributedStringwithLogo(image,
161+
imageSize: image.size,
162+
title: title,
163+
titleFont: WPStyleGuide.mediumWeightFont(forStyle: .title3))
164+
}
165+
155166
/// Creates a button for Self-hosted Login
156167
///
157168
/// - Returns: A properly styled UIButton
@@ -216,26 +227,6 @@ extension WPStyleGuide {
216227
return textButton(normal: attrStrNormal, highlighted: attrStrHighlight, font: font, alignment: .center)
217228
}
218229

219-
/// Creates a button to open a webpage with details about What is WordPress.com?
220-
///
221-
/// - Returns: A properly styled UIButton
222-
///
223-
class func whatIsWPComButton() -> UIButton {
224-
let unifiedStyle = WordPressAuthenticator.shared.unifiedStyle
225-
let originalStyle = WordPressAuthenticator.shared.style
226-
let baseString = WordPressAuthenticator.shared.displayStrings.whatIsWPComLinkTitle
227-
let textColor = unifiedStyle?.textSubtleColor ?? originalStyle.subheadlineColor
228-
let linkColor = unifiedStyle?.textButtonColor ?? originalStyle.textButtonColor
229-
230-
let attrStrNormal = baseString.underlined(color: textColor, underlineColor: linkColor)
231-
let attrStrHighlight = baseString.underlined(color: textColor, underlineColor: linkColor)
232-
let font = WPStyleGuide.mediumWeightFont(forStyle: .footnote)
233-
234-
let button = textButton(normal: attrStrNormal, highlighted: attrStrHighlight, font: font, alignment: .center, forUnified: true)
235-
button.titleLabel?.textAlignment = .center
236-
return button
237-
}
238-
239230
/// Creates a button to open our T&C.
240231
/// Specifically, the Sign Up verbiage on the Get Started view.
241232
/// - Returns: A properly styled UIButton
@@ -324,3 +315,37 @@ extension WPStyleGuide {
324315
return labelString
325316
}
326317
}
318+
319+
// MARK: Attributed String Helpers
320+
//
321+
private extension WPStyleGuide {
322+
323+
/// Creates an attributed string with a logo and title.
324+
/// The logo is prepended to the title.
325+
///
326+
/// - Parameters:
327+
/// - logoImage: UIImage representing the logo
328+
/// - imageSize: Size of the UIImage
329+
/// - title: title String to be appended to the logoImage
330+
/// - titleFont: UIFont for the title String
331+
///
332+
/// - Returns: A properly styled NSAttributedString to be displayed on a NUXButton.
333+
///
334+
class func attributedStringwithLogo(_ logoImage: UIImage,
335+
imageSize: CGSize,
336+
title: String,
337+
titleFont: UIFont) -> NSAttributedString {
338+
let attachment = NSTextAttachment()
339+
attachment.image = logoImage
340+
341+
attachment.bounds = CGRect(x: 0, y: (titleFont.capHeight - imageSize.height) / 2,
342+
width: imageSize.width, height: imageSize.height)
343+
344+
let buttonString = NSMutableAttributedString(attachment: attachment)
345+
// Add leading non-breaking spaces to separate the button text from the logo.
346+
let title = "\u{00a0}\u{00a0}" + title
347+
buttonString.append(NSAttributedString(string: title))
348+
349+
return buttonString
350+
}
351+
}

WordPressAuthenticator/NUX/NUXButtonViewController.swift

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,20 @@ open class NUXButtonViewController: UIViewController {
160160
bottomButtonConfig = NUXButtonConfig(title: title, isPrimary: isPrimary, configureBodyFontForTitle: configureBodyFontForTitle, accessibilityIdentifier: accessibilityIdentifier, callback: callback)
161161
}
162162

163+
// Sets up bottom button using `NSAttributedString` as title
164+
//
165+
func setupBottomButton(attributedTitle: NSAttributedString,
166+
isPrimary: Bool = false,
167+
configureBodyFontForTitle: Bool = false,
168+
accessibilityIdentifier: String? = nil,
169+
onTap callback: @escaping CallBackType) {
170+
bottomButtonConfig = NUXButtonConfig(attributedTitle: attributedTitle,
171+
isPrimary: isPrimary,
172+
configureBodyFontForTitle: configureBodyFontForTitle,
173+
accessibilityIdentifier: accessibilityIdentifier,
174+
callback: callback)
175+
}
176+
163177
func setupButtomButtonFor(socialService: SocialServiceName, onTap callback: @escaping CallBackType) {
164178
bottomButtonConfig = buttonConfigFor(socialService: socialService, onTap: callback)
165179
}

0 commit comments

Comments
 (0)