SAccoutSecViewController.swift 5.1 KB

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