SAccoutSecViewController.swift 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. //
  2. // SAccoutSecViewController.swift
  3. // O2Platform
  4. //
  5. // Created by 刘振兴 on 2016/10/17.
  6. // Copyright © 2016年 zoneland. All rights reserved.
  7. //
  8. import UIKit
  9. import Eureka
  10. import CocoaLumberjack
  11. // 系统生物识别登录 updated by fancylou on 2019-3-11
  12. class SAccoutSecViewController: FormViewController {
  13. var bioType = O2BiometryType.None
  14. var typeTitle = "生物识别登录"
  15. override func viewDidLoad() {
  16. super.viewDidLoad()
  17. let bioAuthUser = AppConfigSettings.shared.bioAuthUser
  18. var isAuthed = false
  19. //判断是否当前绑定的服务器的
  20. if !bioAuthUser.isBlank {
  21. let array = bioAuthUser.split("^^")
  22. if array.count == 2 {
  23. if array[0] == O2AuthSDK.shared.bindUnit()?.id {
  24. isAuthed = true
  25. }
  26. }
  27. }
  28. DDLogDebug("bio user: \(bioAuthUser)")
  29. bioType = O2BioLocalAuth.shared.checkBiometryType()
  30. switch bioType {
  31. case O2BiometryType.FaceID:
  32. typeTitle = "人脸识别登录"
  33. break
  34. case O2BiometryType.TouchID:
  35. typeTitle = "指纹识别登录"
  36. break
  37. case O2BiometryType.None:
  38. typeTitle = "生物识别登录"
  39. break
  40. }
  41. SwitchRow.defaultCellUpdate = {
  42. cell,row in
  43. cell.textLabel?.font = setting_value_textFont
  44. cell.textLabel?.textColor = setting_value_textColor
  45. cell.detailTextLabel?.font = setting_value_textFont
  46. cell.detailTextLabel?.textColor = setting_value_textColor
  47. cell.accessoryType = .disclosureIndicator
  48. }
  49. //设置配置列
  50. form +++ Section(footer: "开启\(typeTitle)后,在登录的时候无需输入用户名密码或者短信验证码,一键验证登录,方便快捷!")
  51. <<< SwitchRow("set_none") {
  52. $0.title = typeTitle
  53. $0.value = isAuthed
  54. $0.cell?.switchControl?.addTarget(self, action: #selector(self.clickSwitch), for: UIControl.Event.touchUpInside)
  55. }
  56. // Do any additional setup after loading the view.
  57. }
  58. override func didReceiveMemoryWarning() {
  59. super.didReceiveMemoryWarning()
  60. // Dispose of any resources that can be recreated.
  61. }
  62. @objc private func clickSwitch() {
  63. let row = self.form.rowBy(tag: "set_none") as? SwitchRow
  64. if self.bioType != O2BiometryType.None {
  65. O2BioLocalAuth.shared.auth(reason: "开启\(typeTitle)", selfAuthTitle: "再想想", block: { (result, errorMsg) in
  66. switch result {
  67. case O2BioEvaluateResult.SUCCESS:
  68. if row?.value == true { //开启
  69. //这里需要将unitId和 userId 组合 否则切换登录服务器后 绑定的userId不能正常登录
  70. let unitId = O2AuthSDK.shared.bindUnit()?.id ?? ""
  71. let userId = O2AuthSDK.shared.myInfo()?.distinguishedName ?? ""
  72. AppConfigSettings.shared.bioAuthUser = "\(unitId)^^\(userId)"
  73. }else { //关闭
  74. AppConfigSettings.shared.bioAuthUser = ""
  75. }
  76. break
  77. case O2BioEvaluateResult.FALLBACK:
  78. //还原value
  79. if row?.value == true {
  80. row?.value = false
  81. }else {
  82. row?.value = true
  83. }
  84. row?.updateCell()
  85. //self.showError(title: "已取消!")
  86. break
  87. case O2BioEvaluateResult.LOCKED:
  88. //还原value
  89. if row?.value == true {
  90. row?.value = false
  91. }else {
  92. row?.value = true
  93. }
  94. row?.updateCell()
  95. self.showSystemAlert(title: "提示", message: "多次错误,已被锁定,请到手机解锁界面输入密码!", okHandler: { (action) in
  96. //
  97. })
  98. break
  99. case O2BioEvaluateResult.FAILURE:
  100. //还原value
  101. if row?.value == true {
  102. row?.value = false
  103. }else {
  104. row?.value = true
  105. }
  106. row?.updateCell()
  107. DDLogError(errorMsg)
  108. self.showError(title: "验证失败!")
  109. break
  110. }
  111. })
  112. }else {
  113. self.showError(title: "手机系统未开启或不支持识别功能")
  114. }
  115. }
  116. /*
  117. // MARK: - Navigation
  118. // In a storyboard-based application, you will often want to do a little preparation before navigation
  119. override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
  120. // Get the new view controller using segue.destinationViewController.
  121. // Pass the selected object to the new view controller.
  122. }
  123. */
  124. }