BioAuthLoginViewController.swift 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. //
  2. // BioAuthLoginViewController.swift
  3. // O2Platform
  4. //
  5. // Created by FancyLou on 2019/3/11.
  6. // Copyright © 2019 zoneland. All rights reserved.
  7. //
  8. import UIKit
  9. import O2OA_Auth_SDK
  10. import CocoaLumberjack
  11. class BioAuthLoginViewController: UIViewController {
  12. @IBOutlet weak var bioImageView: UIImageView!
  13. @IBOutlet weak var bioAuthBtn: OOBaseUIButton!
  14. var bioType = O2BiometryType.None
  15. var typeTitle = "立即验证登录"
  16. override func viewDidLoad() {
  17. super.viewDidLoad()
  18. let bioAuthUser = AppConfigSettings.shared.bioAuthUser
  19. if bioAuthUser.isEmpty {
  20. bioAuthBtn.isEnabled = false
  21. }else {
  22. bioType = O2BioLocalAuth.shared.checkBiometryType()
  23. switch bioType {
  24. case O2BiometryType.FaceID:
  25. typeTitle = "立即验证登录"
  26. bioImageView.image = UIImage(named: "faceid")
  27. bioAuthBtn.setTitle(typeTitle, for: .normal)
  28. bioAuthBtn.isEnabled = true
  29. break
  30. case O2BiometryType.TouchID:
  31. typeTitle = "立即验证登录"
  32. bioImageView.image = UIImage(named: "touchid")
  33. bioAuthBtn.setTitle(typeTitle, for: .normal)
  34. bioAuthBtn.isEnabled = true
  35. break
  36. case O2BiometryType.None:
  37. typeTitle = "登录"
  38. bioImageView.image = UIImage(named: "pic_o2_moren1")
  39. bioAuthBtn.setTitle(typeTitle, for: .normal)
  40. bioAuthBtn.isEnabled = false
  41. break
  42. }
  43. }
  44. }
  45. @IBAction func tapBioAuthLogin(_ sender: OOBaseUIButton) {
  46. if self.bioType != O2BiometryType.None {
  47. O2BioLocalAuth.shared.auth(reason: "使用\(typeTitle)", selfAuthTitle: "用户名登录", block: { (result, errorMsg) in
  48. switch result {
  49. case O2BioEvaluateResult.SUCCESS:
  50. // login
  51. self.loginO2OA()
  52. break
  53. case O2BioEvaluateResult.FALLBACK:
  54. self.back2Login()
  55. break
  56. case O2BioEvaluateResult.LOCKED:
  57. self.showSystemAlert(title: "提示", message: "多次错误,已被锁定,请到手机解锁界面输入密码!", okHandler: { (action) in
  58. //
  59. })
  60. break
  61. case O2BioEvaluateResult.FAILURE:
  62. DDLogError(errorMsg)
  63. self.showError(title: "验证失败!")
  64. break
  65. }
  66. })
  67. }else {
  68. self.showError(title: "手机系统未开启或不支持识别功能")
  69. }
  70. }
  71. @objc private func back2Login() {
  72. DispatchQueue.main.async {
  73. self.performSegue(withIdentifier: "goBack2Login", sender: nil)
  74. }
  75. }
  76. private func loginO2OA() {
  77. self.showMessage(title: "登录中...")
  78. O2AuthSDK.shared.faceRecognizeLogin(userId: AppConfigSettings.shared.bioAuthUser, callback: { (result, msg) in
  79. if result {
  80. self.dismissProgressHUD()
  81. DispatchQueue.main.async {
  82. let destVC = O2MainController.genernateVC()
  83. destVC.selectedIndex = 2
  84. UIApplication.shared.keyWindow?.rootViewController = destVC
  85. UIApplication.shared.keyWindow?.makeKeyAndVisible()
  86. }
  87. }else {
  88. DDLogError("登录失败。。。。。。。\(msg ?? "")")
  89. self.showError(title: "登录服务器失败,请尝试使用其它方式登录")
  90. }
  91. })
  92. }
  93. }