Commit acbbe341 authored by Jose Blaya's avatar Jose Blaya
Browse files

- PIAX Login View Controller

- Refactor and removed unnecessary code
parent 10042310
......@@ -21,6 +21,7 @@ internal enum StoryboardSegue {
}
internal enum Welcome: String, SegueType {
case confirmPurchaseVPNPlanSegue = "ConfirmPurchaseVPNPlanSegue"
case loginAccountSegue = "LoginAccountSegue"
case purchaseVPNPlanSegue = "PurchaseVPNPlanSegue"
case redeemGiftCardSegue = "RedeemGiftCardSegue"
case signupQRCameraScannerSegue = "SignupQRCameraScannerSegue"
......
......@@ -193,5 +193,4 @@ public class ConfirmVPNPlanViewController: AutolayoutViewController, BrandableNa
for: [])
}
}
......@@ -56,9 +56,11 @@ public class GetStartedViewController: AutolayoutViewController, ConfigurationAc
switch segue.identifier {
case StoryboardSegue.Welcome.redeemGiftCardSegue.rawValue:
vc.preset.pages = .redeem
vc.preset.pages = .redeem
case StoryboardSegue.Welcome.purchaseVPNPlanSegue.rawValue:
vc.preset.pages = .purchase
vc.preset.pages = .purchase
case StoryboardSegue.Welcome.loginAccountSegue.rawValue:
vc.preset.pages = .login
default:
break
}
......
......@@ -20,24 +20,8 @@ class LoginViewController: AutolayoutViewController, WelcomeChild {
@IBOutlet private weak var textPassword: BorderedTextField!
@IBOutlet private weak var buttonLogin: ActivityButton!
@IBOutlet private weak var buttonLogin: PIAButton!
@IBOutlet private weak var viewFooter: UIView!
@IBOutlet private weak var viewPurchase: UIView!
@IBOutlet private weak var labelPurchase1: UILabel!
@IBOutlet private weak var labelPurchase2: UILabel!
@IBOutlet private weak var viewRedeem: UIView!
@IBOutlet private weak var labelRedeem1: UILabel!
@IBOutlet private weak var labelRedeem2: UILabel!
@IBOutlet private weak var buttonRestorePurchase: UIButton!
var preset: Preset?
var omitsSiblingLink = false
......@@ -46,6 +30,8 @@ class LoginViewController: AutolayoutViewController, WelcomeChild {
private var signupEmail: String?
private var isLogging = false
override func viewDidLoad() {
super.viewDidLoad()
......@@ -53,24 +39,14 @@ class LoginViewController: AutolayoutViewController, WelcomeChild {
fatalError("Preset not propagated")
}
viewFooter.isHidden = omitsSiblingLink
labelTitle.text = L10n.Welcome.Login.title
textUsername.placeholder = L10n.Welcome.Login.Username.placeholder
textPassword.placeholder = L10n.Welcome.Login.Password.placeholder
buttonLogin.title = L10n.Welcome.Login.submit
labelPurchase1.text = L10n.Welcome.Login.Purchase.footer
labelPurchase2.text = L10n.Welcome.Login.Purchase.button
labelRedeem1.text = L10n.Welcome.Login.Redeem.footer
labelRedeem2.text = L10n.Welcome.Login.Redeem.button
buttonRestorePurchase.setTitle(L10n.Welcome.Login.Restore.button, for: .normal)
buttonRestorePurchase.titleLabel?.textAlignment = .center
buttonRestorePurchase.titleLabel?.numberOfLines = 0
buttonLogin.accessibilityIdentifier = "uitests.login.submit"
viewPurchase.accessibilityLabel = "\(labelPurchase1.text!) \(labelPurchase2.text!)"
textUsername.text = preset.loginUsername
textPassword.text = preset.loginPassword
styleLoginButton()
}
override func viewWillAppear(_ animated: Bool) {
......@@ -86,25 +62,31 @@ class LoginViewController: AutolayoutViewController, WelcomeChild {
// MARK: Actions
@IBAction private func logIn(_ sender: Any?) {
guard !buttonLogin.isRunningActivity else {
guard !isLogging else {
return
}
let errorTitle = L10n.Welcome.Login.Error.title
let errorMessage = L10n.Welcome.Login.Error.validation
guard let username = textUsername.text?.trimmed(), !username.isEmpty else {
let alert = Macros.alert(errorTitle, errorMessage)
alert.addCancelAction(L10n.Ui.Global.ok)
present(alert, animated: true, completion: nil)
Macros.displayImageNote(withImage: Asset.iconWarning.image,
message: errorMessage)
self.status = .error(element: textUsername)
return
}
self.status = .restore(element: textUsername)
guard let password = textPassword.text?.trimmed(), !password.isEmpty else {
let alert = Macros.alert(errorTitle, errorMessage)
alert.addCancelAction(L10n.Ui.Global.ok)
present(alert, animated: true, completion: nil)
Macros.displayImageNote(withImage: Asset.iconWarning.image,
message: errorMessage)
self.status = .error(element: textPassword)
return
}
self.status = .restore(element: textPassword)
self.status = .initial
view.endEditing(false)
let credentials = Credentials(username: username, password: password)
......@@ -142,9 +124,8 @@ class LoginViewController: AutolayoutViewController, WelcomeChild {
log.error("Failed to log in")
}
let alert = Macros.alert(L10n.Welcome.Login.Error.title, errorMessage ?? "")
alert.addCancelAction(L10n.Ui.Global.close)
self.present(alert, animated: true, completion: nil)
Macros.displayImageNote(withImage: Asset.iconWarning.image,
message: errorMessage ?? L10n.Welcome.Login.Error.title)
return
}
......@@ -153,20 +134,6 @@ class LoginViewController: AutolayoutViewController, WelcomeChild {
self.completionDelegate?.welcomeDidLogin(withUser: user, topViewController: self)
}
}
@IBAction private func signUp(_ sender: Any?) {
guard let pageController = parent as? WelcomePageViewController else {
fatalError("Not running in WelcomePageViewController")
}
pageController.show(page: .purchase)
}
@IBAction private func redeem(_ sender: Any?) {
guard let pageController = parent as? WelcomePageViewController else {
fatalError("Not running in WelcomePageViewController")
}
pageController.show(page: .redeem)
}
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if let vc = segue.destination as? RestoreSignupViewController {
......@@ -191,28 +158,27 @@ class LoginViewController: AutolayoutViewController, WelcomeChild {
private func enableInteractions(_ enable: Bool) {
parent?.view.isUserInteractionEnabled = enable
if enable {
buttonLogin.stopActivity()
} else {
buttonLogin.startActivity()
}
isLogging = !enable
}
// MARK: Restylable
override func viewShouldRestyle() {
super.viewShouldRestyle()
Theme.current.applyLightBackground(view)
Theme.current.applyTitle(labelTitle, appearance: .dark)
Theme.current.applyInput(textUsername)
Theme.current.applyInput(textPassword)
Theme.current.applyActionButton(buttonLogin)
Theme.current.applyBody1(labelPurchase1, appearance: .dark)
Theme.current.applyTextButton(labelPurchase2)
Theme.current.applyBody1(labelRedeem1, appearance: .dark)
Theme.current.applyTextButton(labelRedeem2)
Theme.current.applyTextButton(buttonRestorePurchase)
}
private func styleLoginButton() {
buttonLogin.setRounded()
buttonLogin.style(style: TextStyle.Buttons.piaGreenButton)
buttonLogin.setTitle(L10n.Welcome.Login.submit.uppercased(),
for: [])
buttonLogin.accessibilityIdentifier = "uitests.login.submit"
}
}
extension LoginViewController: UITextFieldDelegate {
......
......@@ -39,14 +39,6 @@ class RedeemViewController: AutolayoutViewController, WelcomeChild {
@IBOutlet private weak var buttonRedeem: PIAButton!
@IBOutlet private weak var viewFooter: UIView!
@IBOutlet private weak var viewLogin: UIView!
@IBOutlet private weak var labelLogin1: UILabel!
@IBOutlet private weak var labelLogin2: UILabel!
@IBOutlet private weak var cameraButton: PIAButton!
var preset: Preset?
......@@ -73,8 +65,6 @@ class RedeemViewController: AutolayoutViewController, WelcomeChild {
fatalError("Preset not propagated")
}
viewFooter.isHidden = omitsSiblingLink
labelTitle.text = L10n.Welcome.Redeem.title
labelSubtitle.text = L10n.Welcome.Redeem.subtitle(RedeemViewController.codeLength)
textEmail.placeholder = L10n.Welcome.Redeem.Email.placeholder
......@@ -88,10 +78,6 @@ class RedeemViewController: AutolayoutViewController, WelcomeChild {
)
buttonRedeem.setTitle(L10n.Welcome.Redeem.title,
for: [])
labelLogin1.text = L10n.Welcome.Purchase.Login.footer
labelLogin2.text = L10n.Welcome.Purchase.Login.button
viewLogin.accessibilityLabel = "\(labelLogin1.text!) \(labelLogin2.text!)"
textEmail.text = preset.redeemEmail
if let code = preset.redeemCode {
redeemCode = GiftCardUtil.strippedRedeemCode(code) // will set textCode automatically
......@@ -168,13 +154,6 @@ class RedeemViewController: AutolayoutViewController, WelcomeChild {
perform(segue: StoryboardSegue.Welcome.signupViaRedeemSegue)
}
@IBAction private func logIn(_ sender: Any?) {
guard let pageController = parent as? WelcomePageViewController else {
fatalError("Not running in WelcomePageViewController")
}
pageController.show(page: .login)
}
@IBAction private func showCameraToScanQRCodes(_ sender: Any?) {
if AVCaptureDevice.authorizationStatus(for: AVMediaType.video) == .denied {
......@@ -270,8 +249,6 @@ class RedeemViewController: AutolayoutViewController, WelcomeChild {
Theme.current.applyInput(textEmail)
Theme.current.applyInput(textCode)
Theme.current.applyLinkAttributes(textAgreement)
Theme.current.applyBody1(labelLogin1, appearance: .dark)
Theme.current.applyTextButton(labelLogin2)
}
}
......
......@@ -49,7 +49,7 @@ class WelcomePageViewController: UIPageViewController {
fatalError("Source element must be a WelcomeChild")
}
child.preset = preset
child.omitsSiblingLink = isSinglePage
child.omitsSiblingLink = !isSinglePage
child.completionDelegate = completionDelegate
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment