Skip to content

Commit

Permalink
Added back up link to login with password
Browse files Browse the repository at this point in the history
  • Loading branch information
charliescheer committed Sep 11, 2024
1 parent 83cfbfb commit 5b6d89e
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 5 deletions.
7 changes: 7 additions & 0 deletions Simplenote/AuthViewController+Swift.swift
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,8 @@ extension AuthViewController {

if let title = descriptor.text {
actionView.title = title
} else if let attributedTitle = descriptor.attributedText {
actionView.attributedTitle = attributedTitle
}

actionView.action = descriptor.selector
Expand Down Expand Up @@ -226,6 +228,11 @@ extension AuthViewController {
func pushCodeLoginView() {
pushNewAuthViewController(with: .loginWithCode, state: state)
}

@objc
func pushUsernameAndPasswordView() {
pushNewAuthViewController(with: .loginWithUsernameAndPassword, state: state)
}
}


Expand Down
2 changes: 1 addition & 1 deletion Simplenote/AuthViewController.xib
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@
<font key="font" metaFont="systemMedium" size="13"/>
</buttonCell>
<constraints>
<constraint firstAttribute="height" constant="20" id="HrL-ss-QSd"/>
<constraint firstAttribute="height" relation="greaterThanOrEqual" constant="20" id="HrL-ss-QSd"/>
</constraints>
</button>
<customView appearanceType="darkAqua" translatesAutoresizingMaskIntoConstraints="NO" id="WI9-SH-Yrp" userLabel="Actions Separator View">
Expand Down
34 changes: 30 additions & 4 deletions Simplenote/AuthenticationMode.swift
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,11 @@ extension AuthenticationMode {
static var loginWithPassword: AuthenticationMode {
buildLoginWithPasswordMode(header: LoginStrings.loginWithEmailEmailHeader)
}


static var loginWithUsernameAndPassword: AuthenticationMode {
buildLoginWithPasswordMode(header: LoginStrings.loginWithEmailEmailHeader, includeUsername: true)
}

/// Auth Mode: Login with Username + Password + Rate Limiting Header
///
static var loginWithPasswordRateLimited: AuthenticationMode {
Expand All @@ -134,10 +138,11 @@ extension AuthenticationMode {

/// Builds the loginWithPassword Mode with the specified Header
///
private static func buildLoginWithPasswordMode(header: String) -> AuthenticationMode {
AuthenticationMode(title: NSLocalizedString("Log In with Password", comment: "LogIn Interface Title"),
private static func buildLoginWithPasswordMode(header: String, includeUsername: Bool = false) -> AuthenticationMode {
let inputElements: AuthenticationInputElements = includeUsername ? [.username, .password] : [.password]
return AuthenticationMode(title: NSLocalizedString("Log In with Password", comment: "LogIn Interface Title"),
header: header,
inputElements: [.password],
inputElements: inputElements,
actions: [
AuthenticationActionDescriptor(name: .primary,
selector: #selector(AuthViewController.pressedLogInWithPassword),
Expand All @@ -160,6 +165,10 @@ extension AuthenticationMode {
AuthenticationActionDescriptor(name: .primary,
selector: #selector(AuthViewController.pressedLoginWithMagicLink),
text: MagicLinkStrings.primaryAction),
AuthenticationActionDescriptor(name: .secondary,
selector: #selector(AuthViewController.pushUsernameAndPasswordView),
text: nil,
attributedText: LoginStrings.usernameAndPasswordOption),
AuthenticationActionDescriptor(name: .tertiary,
selector: #selector(AuthViewController.wordpressSSOAction),
text: LoginStrings.wordpressAction)
Expand Down Expand Up @@ -214,6 +223,23 @@ private enum LoginStrings {
static let loginWithEmailEmailHeader = NSLocalizedString("Enter the password for the account {{EMAIL}}", comment: "Header for Login With Password. Please preserve the {{EMAIL}} substring")
static let loginWithEmailLimitHeader = NSLocalizedString("Log in with email failed, please enter the password for {{EMAIL}}", comment: "Header for Enter Password UI, when the user performed too many requests")

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

let prefix = NSLocalizedString("We'll email you a code to log in, \nor 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: NSColor(studioColor: ColorStudio.gray60))
output.append(string: " ")
output.append(string: suffix, foregroundColor: NSColor(studioColor: ColorStudio.spBlue60))

return output
}

}

private enum MagicLinkStrings {
Expand Down

0 comments on commit 5b6d89e

Please sign in to comment.