From 5b6d89e8a771304e6a81540176751569199b2b13 Mon Sep 17 00:00:00 2001 From: Charlie Scheer Date: Tue, 10 Sep 2024 20:14:55 -1000 Subject: [PATCH] Added back up link to login with password --- Simplenote/AuthViewController+Swift.swift | 7 +++++ Simplenote/AuthViewController.xib | 2 +- Simplenote/AuthenticationMode.swift | 34 ++++++++++++++++++++--- 3 files changed, 38 insertions(+), 5 deletions(-) diff --git a/Simplenote/AuthViewController+Swift.swift b/Simplenote/AuthViewController+Swift.swift index 14410db44..598af38db 100644 --- a/Simplenote/AuthViewController+Swift.swift +++ b/Simplenote/AuthViewController+Swift.swift @@ -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 @@ -226,6 +228,11 @@ extension AuthViewController { func pushCodeLoginView() { pushNewAuthViewController(with: .loginWithCode, state: state) } + + @objc + func pushUsernameAndPasswordView() { + pushNewAuthViewController(with: .loginWithUsernameAndPassword, state: state) + } } diff --git a/Simplenote/AuthViewController.xib b/Simplenote/AuthViewController.xib index 99cfdb123..0ca3b4302 100644 --- a/Simplenote/AuthViewController.xib +++ b/Simplenote/AuthViewController.xib @@ -142,7 +142,7 @@ - + diff --git a/Simplenote/AuthenticationMode.swift b/Simplenote/AuthenticationMode.swift index 988cd9c0f..f871b2933 100644 --- a/Simplenote/AuthenticationMode.swift +++ b/Simplenote/AuthenticationMode.swift @@ -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 { @@ -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), @@ -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) @@ -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 {