BioAuthLoginViewController.swift 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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. var isAuthed = false
  20. //判断是否当前绑定的服务器的
  21. if !bioAuthUser.isBlank {
  22. let array = bioAuthUser.split("^^")
  23. if array.count == 2 {
  24. if array[0] == O2AuthSDK.shared.bindUnit()?.id {
  25. isAuthed = true
  26. }
  27. }
  28. }
  29. if !isAuthed {
  30. bioAuthBtn.isEnabled = false
  31. }else {
  32. bioType = O2BioLocalAuth.shared.checkBiometryType()
  33. switch bioType {
  34. case O2BiometryType.FaceID:
  35. typeTitle = "立即验证登录"
  36. bioImageView.image = UIImage(named: "faceid")
  37. bioAuthBtn.setTitle(typeTitle, for: .normal)
  38. bioAuthBtn.isEnabled = true
  39. break
  40. case O2BiometryType.TouchID:
  41. typeTitle = "立即验证登录"
  42. bioImageView.image = UIImage(named: "touchid")
  43. bioAuthBtn.setTitle(typeTitle, for: .normal)
  44. bioAuthBtn.isEnabled = true
  45. break
  46. case O2BiometryType.None:
  47. typeTitle = "登录"
  48. bioImageView.image = UIImage(named: "pic_o2_moren1")
  49. bioAuthBtn.setTitle(typeTitle, for: .normal)
  50. bioAuthBtn.isEnabled = false
  51. break
  52. }
  53. }
  54. }
  55. @IBAction func tapBioAuthLogin(_ sender: OOBaseUIButton) {
  56. if self.bioType != O2BiometryType.None {
  57. O2BioLocalAuth.shared.auth(reason: "使用\(typeTitle)", selfAuthTitle: "用户名登录", block: { (result, errorMsg) in
  58. switch result {
  59. case O2BioEvaluateResult.SUCCESS:
  60. // login
  61. self.loginO2OA()
  62. break
  63. case O2BioEvaluateResult.FALLBACK:
  64. self.back2Login()
  65. break
  66. case O2BioEvaluateResult.LOCKED:
  67. self.showSystemAlert(title: "提示", message: "多次错误,已被锁定,请到手机解锁界面输入密码!", okHandler: { (action) in
  68. //
  69. })
  70. break
  71. case O2BioEvaluateResult.FAILURE:
  72. DDLogError(errorMsg)
  73. self.showError(title: "验证失败!")
  74. break
  75. }
  76. })
  77. }else {
  78. self.showError(title: "手机系统未开启或不支持识别功能")
  79. }
  80. }
  81. @objc private func back2Login() {
  82. DispatchQueue.main.async {
  83. self.performSegue(withIdentifier: "goBack2Login", sender: nil)
  84. }
  85. }
  86. private func loginO2OA() {
  87. self.showLoading(title: "登录中...")
  88. let bioAuthUser = AppConfigSettings.shared.bioAuthUser
  89. var userId = ""
  90. if !bioAuthUser.isBlank {
  91. let array = bioAuthUser.split("^^")
  92. if array.count == 2 {
  93. if array[0] == O2AuthSDK.shared.bindUnit()?.id {
  94. userId = array[1]
  95. }
  96. }
  97. }
  98. if userId.isBlank {
  99. DDLogError("登录失败。。。用户名为空")
  100. self.showError(title: "服务器验证登录失败,请尝试使用其它方式登录")
  101. }else {
  102. O2AuthSDK.shared.faceRecognizeLogin(userId: userId, callback: { (result, msg) in
  103. if result {
  104. self.hideLoading()
  105. DispatchQueue.main.async {
  106. let destVC = O2MainController.genernateVC()
  107. destVC.selectedIndex = 2
  108. UIApplication.shared.keyWindow?.rootViewController = destVC
  109. UIApplication.shared.keyWindow?.makeKeyAndVisible()
  110. }
  111. }else {
  112. DDLogError("登录失败。。。。。。。\(msg ?? "")")
  113. self.showError(title: "服务器验证登录失败,请尝试使用其它方式登录")
  114. }
  115. })
  116. }
  117. }
  118. }