Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add fall back login with username and password option to login #1656

Merged
merged 3 commits into from
Sep 13, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
30 changes: 25 additions & 5 deletions Simplenote/AuthenticationMode.swift
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,12 @@ extension AuthenticationMode {

/// Login with Password
///
static func loginWithPassword(header: String? = nil) -> AuthenticationMode {
static func loginWithPassword(header: String? = nil, includeUsername: Bool = false) -> AuthenticationMode {
var inputElements: AuthenticationInputElements = includeUsername ? [.username, .password] : [.password]

return .init(title: NSLocalizedString("Log In with Password", comment: "LogIn Interface Title"),
header: header,
inputElements: [.password],
inputElements: inputElements,
validationStyle: .legacy,
actions: [
AuthenticationActionDescriptor(name: .primary,
Expand All @@ -114,6 +116,7 @@ extension AuthenticationMode {
AuthenticationActionDescriptor(name: .primary,
selector: #selector(SPAuthViewController.requestLogInCode),
text: NSLocalizedString("Log in with email", comment: "Sends the User an email with an Authentication Code")),
AuthenticationActionDescriptor(name: .secondary, selector: #selector(SPAuthViewController.presentUsernameAndPasswordInterface), text: nil, attributedText: Strings.usernameAndPasswordOption),
AuthenticationActionDescriptor(name: .tertiary,
selector: #selector(SPAuthViewController.performLogInWithWPCOM),
text: NSLocalizedString("Log in with WordPress.com", comment: "Password fallback Action"))
Expand Down Expand Up @@ -150,15 +153,15 @@ extension AuthenticationMode {
AuthenticationActionDescriptor(name: .secondary,
selector: #selector(SPAuthViewController.presentTermsOfService),
text: nil,
attributedText: SignupStrings.termsOfService)
attributedText: Strings.termsOfService)
])
}
}


// MARK: - Mode: .signup
// MARK: - String Constants
//
private enum SignupStrings {
private enum Strings {

/// Returns a formatted Secondary Action String for Signup
///
Expand All @@ -176,4 +179,21 @@ private enum SignupStrings {

return output
}

/// Returns a formatted Secondary Action String for Optional Username and password login
///
static var usernameAndPasswordOption: NSAttributedString {
let output = NSMutableAttributedString(string: String(), attributes: [
.font: UIFont.preferredFont(forTextStyle: .subheadline)
])

let prefix = NSLocalizedString("We'll email you a code to log in, or you can", comment: "Option to login with username and password *PREFIX*: printed in dark color")
let suffix = NSLocalizedString("log in manually.", comment: "Option to login with username and password *SUFFIX*: Concatenated with a space, after the PREFIX, and printed in blue")

output.append(string: prefix, foregroundColor: .simplenoteGray60Color)
output.append(string: " ")
output.append(string: suffix, foregroundColor: .simplenoteBlue60Color)

return output
}
}
10 changes: 7 additions & 3 deletions Simplenote/Classes/SPAuthViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -549,15 +549,19 @@ extension SPAuthViewController {
@IBAction func presentPasswordInterface() {
presentPasswordInterfaceWithHeader(header: AuthenticationStrings.loginWithEmailEmailHeader)
}

@IBAction func presentPasswordInterfaceWithRateLimitingHeader() {
presentPasswordInterfaceWithHeader(header: AuthenticationStrings.loginWithEmailLimitHeader)
}

@IBAction func presentPasswordInterfaceWithHeader(header: String?) {
let viewController = SPAuthViewController(controller: controller, mode: .loginWithPassword(header: header), state: state)
@IBAction func presentPasswordInterfaceWithHeader(header: String?, includeUsername: Bool = false) {
let viewController = SPAuthViewController(controller: controller, mode: .loginWithPassword(header: header, includeUsername: includeUsername), state: state)
navigationController?.pushViewController(viewController, animated: true)
}

@IBAction func presentUsernameAndPasswordInterface() {
presentPasswordInterfaceWithHeader(header: AuthenticationStrings.loginWithEmailLimitHeader, includeUsername: true)
}
}


Expand Down