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

Auth alert tweaks #1286

Merged
merged 7 commits into from
Mar 15, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion Wikipedia/Code/UIColor+WMFStyle.swift
Expand Up @@ -48,7 +48,8 @@ public extension UIColor {
public static let wmf_referencePopoverBackground: UIColor = .white
public static let wmf_referencePopoverLink: UIColor = .wmf_color(withHex: 0x3366cc, alpha: 1.0)
public static let wmf_referencePopoverText: UIColor = .black
public static let wmf_red: UIColor = .wmf_color(withHex: 0xd11611, alpha: 1.0)
public static let wmf_red: UIColor = .wmf_color(withHex: 0xdd3333, alpha: 1.0)
public static let wmf_yellow: UIColor = .wmf_color(withHex: 0xffcc33, alpha: 1.0)
public static let wmf_orange: UIColor = .wmf_color(withHex: 0xff5b00, alpha: 1.0)
public static let wmf_authTitle: UIColor = .wmf_color(withHex: 0x72777d, alpha: 1.0)

Expand Down
6 changes: 4 additions & 2 deletions Wikipedia/Code/WMFAccountCreationViewController.swift
Expand Up @@ -51,6 +51,8 @@ class WMFAccountCreationViewController: WMFScrollViewController, WMFCaptchaViewC
super.viewDidLoad()

[titleLabel, usernameTitleLabel, passwordTitleLabel, passwordRepeatTitleLabel, emailTitleLabel].forEach{$0.textColor = .wmf_authTitle}
usernameAlertLabel.textColor = .wmf_red
passwordRepeatAlertLabel.textColor = .wmf_yellow

navigationItem.leftBarButtonItem = UIBarButtonItem(image: UIImage(named:"close"), style: .plain, target:self, action:#selector(closeButtonPushed(_:)))

Expand Down Expand Up @@ -237,7 +239,7 @@ class WMFAccountCreationViewController: WMFScrollViewController, WMFCaptchaViewC
}

guard passwordFieldsMatch() else {
self.passwordRepeatField.textColor = .orange
self.passwordRepeatField.textColor = .wmf_yellow
self.passwordRepeatAlertLabel.isHidden = false
self.scrollView.scrollSubView(toTop: self.passwordTitleLabel, offset: 6, animated: true)
WMFAlertManager.sharedInstance.showErrorAlertWithMessage(localizedStringForKeyFallingBackOnEnglish("account-creation-passwords-mismatched"), sticky: false, dismissPreviousAlerts: true, tapCallBack: nil)
Expand Down Expand Up @@ -271,7 +273,7 @@ class WMFAccountCreationViewController: WMFScrollViewController, WMFCaptchaViewC
case .usernameUnavailable:
self.usernameAlertLabel.text = error.localizedDescription
self.usernameAlertLabel.isHidden = false
self.usernameField.textColor = .red
self.usernameField.textColor = .wmf_red
self.funnel?.logError(error.localizedDescription)
WMFAlertManager.sharedInstance.dismissAlert()
return
Expand Down
22 changes: 15 additions & 7 deletions Wikipedia/Code/WMFAccountLogin.swift
Expand Up @@ -5,6 +5,7 @@ public enum WMFAccountLoginError: LocalizedError {
case temporaryPasswordNeedsChange(String?)
case needsOathTokenFor2FA(String?)
case wrongPassword
case wrongToken
public var errorDescription: String? {
switch self {
case .cannotExtractLoginStatus:
Expand All @@ -17,6 +18,8 @@ public enum WMFAccountLoginError: LocalizedError {
return message
case .wrongPassword:
return localizedStringForKeyFallingBackOnEnglish("field-alert-password-invalid")
case .wrongToken:
return localizedStringForKeyFallingBackOnEnglish("field-alert-token-invalid")
default:
return "Unable to login: Reason unknown"
}
Expand Down Expand Up @@ -85,6 +88,18 @@ public class WMFAccountLogin {
let message = clientlogin["message"] as? String ?? nil
guard status == "PASS" else {

if let messageCode = clientlogin["messagecode"] as? String {
switch(messageCode) {
case "wrongpassword":
failure(WMFAccountLoginError.wrongPassword)
return
case "oathauth-login-failed":
failure(WMFAccountLoginError.wrongToken)
return
default: break
}
}

if
status == "UI",
let requests = clientlogin["requests"] as? [AnyObject]
Expand All @@ -106,13 +121,6 @@ public class WMFAccountLogin {
}
}

if let messageCode = clientlogin["messagecode"] as? String {
if messageCode == "wrongpassword" {
failure(WMFAccountLoginError.wrongPassword)
return
}
}

failure(WMFAccountLoginError.statusNotPass(message))
return
}
Expand Down
3 changes: 2 additions & 1 deletion Wikipedia/Code/WMFLoginViewController.swift
Expand Up @@ -31,6 +31,7 @@ class WMFLoginViewController: WMFScrollViewController, UITextFieldDelegate, WMFC
super.viewDidLoad()

[titleLabel, usernameTitleLabel, passwordTitleLabel].forEach{$0.textColor = .wmf_authTitle}
passwordAlertLabel.textColor = .wmf_red

navigationItem.leftBarButtonItem = UIBarButtonItem(image: UIImage(named:"close"), style: .plain, target:self, action:#selector(closeButtonPushed(_:)))

Expand Down Expand Up @@ -163,7 +164,7 @@ class WMFLoginViewController: WMFScrollViewController, UITextFieldDelegate, WMFC
case .wrongPassword:
self.passwordAlertLabel.text = error.localizedDescription
self.passwordAlertLabel.isHidden = false
self.passwordField.textColor = .red
self.passwordField.textColor = .wmf_red
self.funnel?.logError(error.localizedDescription)
WMFAlertManager.sharedInstance.dismissAlert()
return
Expand Down
22 changes: 16 additions & 6 deletions Wikipedia/Code/WMFTwoFactorPasswordViewController.storyboard
Expand Up @@ -25,10 +25,10 @@
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
<subviews>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="dci-dv-K46" userLabel="Scroll container">
<rect key="frame" x="0.0" y="0.0" width="375" height="307"/>
<rect key="frame" x="0.0" y="0.0" width="375" height="326"/>
<subviews>
<stackView opaque="NO" contentMode="scaleToFill" axis="vertical" spacing="3" translatesAutoresizingMaskIntoConstraints="NO" id="voB-TH-ZiL">
<rect key="frame" x="43" y="30" width="288" height="247"/>
<rect key="frame" x="43" y="30" width="288" height="266"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Log in to your account" textAlignment="natural" lineBreakMode="wordWrap" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="ICf-tY-uts">
<rect key="frame" x="0.0" y="0.0" width="288" height="22"/>
Expand Down Expand Up @@ -145,15 +145,24 @@
<outlet property="delegate" destination="AT3-3L-21R" id="QuS-LX-QrB"/>
</connections>
</textField>
<label hidden="YES" opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Invalid password" textAlignment="natural" lineBreakMode="wordWrap" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="jky-Ie-cci">
<rect key="frame" x="0.0" y="150" width="288" height="16"/>
<constraints>
<constraint firstAttribute="height" relation="greaterThanOrEqual" priority="999" constant="16" id="Ac3-V4-SYA"/>
</constraints>
<fontDescription key="fontDescription" style="UICTFontTextStyleCaption1"/>
<color key="textColor" red="1" green="0.0" blue="0.0" alpha="1" colorSpace="calibratedRGB"/>
<nil key="highlightedColor"/>
</label>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="03P-FO-sp2" userLabel="Spacer">
<rect key="frame" x="0.0" y="150" width="288" height="10"/>
<rect key="frame" x="0.0" y="169" width="288" height="10"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<constraints>
<constraint firstAttribute="height" constant="10" id="heq-z8-P62"/>
</constraints>
</view>
<label opaque="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Sign in using backup code" textAlignment="natural" lineBreakMode="wordWrap" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="h8f-mM-rQm" customClass="WMFAuthLinkLabel" customModule="Wikipedia" customModuleProvider="target">
<rect key="frame" x="0.0" y="163" width="288" height="18"/>
<rect key="frame" x="0.0" y="182" width="288" height="18"/>
<constraints>
<constraint firstAttribute="height" relation="greaterThanOrEqual" constant="18" id="hUl-gk-GUZ"/>
</constraints>
Expand All @@ -162,14 +171,14 @@
<nil key="highlightedColor"/>
</label>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="Bt5-Ng-X4b" userLabel="Spacer">
<rect key="frame" x="0.0" y="184" width="288" height="20"/>
<rect key="frame" x="0.0" y="203" width="288" height="20"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<constraints>
<constraint firstAttribute="height" constant="20" id="mCw-Fo-Tkf"/>
</constraints>
</view>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="wordWrap" translatesAutoresizingMaskIntoConstraints="NO" id="dYo-4M-CC7" customClass="WMFAuthButton" customModule="Wikipedia" customModuleProvider="target">
<rect key="frame" x="0.0" y="207" width="288" height="40"/>
<rect key="frame" x="0.0" y="226" width="288" height="40"/>
<constraints>
<constraint firstAttribute="height" relation="greaterThanOrEqual" constant="40" id="vIq-Xi-Btm"/>
</constraints>
Expand Down Expand Up @@ -221,6 +230,7 @@
<outlet property="scrollView" destination="cqK-hC-WEB" id="60H-J2-hGs"/>
<outlet property="subTitleLabel" destination="nHE-b4-nTa" id="AmV-mJ-3Ky"/>
<outlet property="titleLabel" destination="ICf-tY-uts" id="Z0U-Ja-csH"/>
<outlet property="tokenAlertLabel" destination="jky-Ie-cci" id="RYM-4k-bpv"/>
<outlet property="tokenLabel" destination="4Cq-c7-RXq" id="PjS-VK-ykU"/>
<outletCollection property="oathTokenFields" destination="xHD-aF-ff9" collectionClass="NSMutableArray" id="Nnq-Pl-EDn"/>
<outletCollection property="oathTokenFields" destination="5fd-Va-aW7" collectionClass="NSMutableArray" id="eEM-hE-Lr4"/>
Expand Down
11 changes: 11 additions & 0 deletions Wikipedia/Code/WMFTwoFactorPasswordViewController.swift
Expand Up @@ -16,6 +16,7 @@ class WMFTwoFactorPasswordViewController: WMFScrollViewController, UITextFieldDe
@IBOutlet fileprivate var titleLabel: UILabel!
@IBOutlet fileprivate var subTitleLabel: UILabel!
@IBOutlet fileprivate var tokenLabel: UILabel!
@IBOutlet fileprivate var tokenAlertLabel: UILabel!
@IBOutlet fileprivate var oathTokenFields: [UITextField]!
@IBOutlet fileprivate var oathTokenFieldsStackView: UIStackView!
@IBOutlet fileprivate var displayModeToggle: UILabel!
Expand Down Expand Up @@ -189,6 +190,8 @@ class WMFTwoFactorPasswordViewController: WMFScrollViewController, UITextFieldDe
}

func textFieldDidBeginEditing(_ textField: UITextField) {
tokenAlertLabel.isHidden = true

// In the storyboard we've set the text fields' to "Clear when editing begins", but
// the "Editing changed" handler "textFieldDidChange" isn't called when this clearing
// happens, so update progressive buttons' enabled state here too.
Expand All @@ -207,6 +210,7 @@ class WMFTwoFactorPasswordViewController: WMFScrollViewController, UITextFieldDe
super.viewDidLoad()

[titleLabel, tokenLabel].forEach{$0.textColor = .wmf_authTitle}
tokenAlertLabel.textColor = .wmf_red

oathTokenFields.sort { $0.tag < $1.tag }
oathTokenFields.forEach {$0.wmf_addThinBottomBorder()}
Expand Down Expand Up @@ -247,6 +251,7 @@ class WMFTwoFactorPasswordViewController: WMFScrollViewController, UITextFieldDe

fileprivate func save() {
wmf_hideKeyboard()
tokenAlertLabel.isHidden = true
enableProgressiveButton(false)

guard
Expand Down Expand Up @@ -277,6 +282,12 @@ class WMFTwoFactorPasswordViewController: WMFScrollViewController, UITextFieldDe
WMFAlertManager.sharedInstance.dismissAlert()
self.showChangeTempPasswordViewController()
return
case .wrongToken:
self.tokenAlertLabel.text = error.localizedDescription
self.tokenAlertLabel.isHidden = false
self.funnel?.logError(error.localizedDescription)
WMFAlertManager.sharedInstance.dismissAlert()
return
default: break
}
}
Expand Down
2 changes: 1 addition & 1 deletion Wikipedia/Localizations/en.lproj/Localizable.strings
Expand Up @@ -101,12 +101,12 @@
"field-email-placeholder" = "example@example.org";
"field-token-title" = "Verification code";
"field-backup-token-title" = "Backup code";
"field-token-invalid" = "Invalid code. Please try again.";
"field-token-placeholder" = "enter token";
"field-captcha-title" = "Enter the text you see above";
"field-captcha-placeholder" = "CAPTCHA text";
"field-alert-username-unavailable" = "Username not available";
"field-alert-password-invalid" = "Invalid password";
"field-alert-token-invalid" = "Invalid code";
"field-alert-captcha-invalid" = "Invalid CAPTCHA";
"field-alert-password-confirm-mismatch" = "Passwords do not match";

Expand Down
2 changes: 1 addition & 1 deletion Wikipedia/Localizations/qqq.lproj/Localizable.strings
Expand Up @@ -107,12 +107,12 @@
"field-email-placeholder" = "Placeholder text shown inside email address field until user taps on it";
"field-token-title" = "Title for token field\n{{Identical|Token}}";
"field-backup-token-title" = "Title for backup token field";
"field-token-invalid" = "Alert shown if token is not correct";
"field-token-placeholder" = "Placeholder text shown inside token field until user taps on it";
"field-captcha-title" = "Title for captcha field";
"field-captcha-placeholder" = "Placeholder text shown inside captcha field until user taps on it";
"field-alert-username-unavailable" = "Alert shown if new username is not available";
"field-alert-password-invalid" = "Alert shown if password is not correct";
"field-alert-token-invalid" = "Alert shown if token is not correct";
"field-alert-captcha-invalid" = "Alert shown if CAPTCHA is not correct";
"field-alert-password-confirm-mismatch" = "Alert shown if password confirmation did not match password";
"forgot-password-title" = "Title for reset password interface\n{{Identical|Reset password}}";
Expand Down