123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147 |
- //
- // GuesturePasswordViewController.swift
- // xingchuangke
- //
- // Created by Virgil on 2019/3/22.
- // Copyright © 2019 Virgil. All rights reserved.
- //
- import UIKit
- class GuesturePasswordViewController: BaseViewController {
- @IBOutlet weak var viewTemp: UIView!
- @IBOutlet weak var btnOtherLogin: UIButton!
- @IBOutlet weak var btnForgetPassword: UIButton!
- @IBOutlet weak var lblRemark: UILabel!
- @IBOutlet weak var lblName: UILabel!
- @IBOutlet weak var imgIcon: UIImageView!
- /// 0:设置密码 1:检查密码
- var type = 0
- @IBOutlet weak var viewGuesture: UIView!
- override func viewDidLoad() {
- super.viewDidLoad()
- if type == 0 {
- DBGuestureLock.clearPassword()
- initNavLeftBackButton()
- self.title = "设置手势密码"
- lblName.text = CommonValue.getUserNickName()
- lblRemark.text = "请输入您的手势"
- btnForgetPassword.isHidden = true
- btnOtherLogin.isHidden = true
- } else {
- self.navigationItem.hidesBackButton = true
- self.title = "手势登录"
- lblName.text = "欢迎回来,\(CommonValue.getUserNickName())"
- lblRemark.text = "请输入您的手势"
- }
- imgIcon.loadImage(imgUrl: CommonValue.getUserLogo(), defaultImage: "common_user")
- imgIcon.setCornerRadius()
- viewGuesture.setSizeHeight(height: ScreenWidth + 40)
- let lock = DBGuestureLock.init(on: self.viewGuesture, onPasswordSet: {[weak self] (lock, password) in
- print("=1=\(password)===")
- self!.setPassword(password: password!)
- }, onGetCorrectPswd: {[weak self] (lock, password) in
- print("=2=\(password)===")
- self!.correctPswd(password: password!)
- }) {[weak self] (_, password) in
- print("=3=\(password)===")
- self!.inCorrectPswd(password: password!)
- }
- lock?.setupLockTheme(withLineColor: CommonUntils.getUIColorFromRGB(rgbValue: 0x37A6FF, alpha: 1.0), lineWidth: 2, stroke: CommonUntils.getUIColorFromRGB(rgbValue: 0x37A6FF, alpha: 1.0), strokeWidth: 2, circleRadius: 15, fill: nil, showCenterPoint: true, centerPointColor: CommonUntils.getUIColorFromRGB(rgbValue: 0x37A6FF, alpha: 1.0), centerPointRadius: 5, fillCenterPoint: false, on: .selected)
- lock?.setupLockTheme(withLineColor: nil, lineWidth: 2, stroke: nil, strokeWidth: 2, circleRadius: 15, fill: nil, showCenterPoint: true, centerPointColor: UIColor.lightGray, centerPointRadius: 10, fillCenterPoint: true, on: .normal)
- viewGuesture.addSubview(lock!)
- viewTemp.frame = viewGuesture.frame
- timer = Timer.scheduledTimer(timeInterval: 1, target: self, selector: #selector(move), userInfo: nil, repeats: true)
- timer.fireDate = Date.distantFuture
- }
- var timer: Timer!
- var strSetPassword = ""
- func setPassword(password: String) {
- if strSetPassword == "" {
- strSetPassword = password
- lblRemark.text = "请再次输入您的手势"
- }
- }
- var errorCount = 0
- func correctPswd(password: String) {
- if type == 0 {
- lblRemark.text = "手势密码设置成功"
- SVProgressHUD.showSuccess(withStatus: "手势密码设置成功")
- CommonValue.setDefaultUserInfoForString(value: "1", key: "common_default_is_ss_password")
- handleBack()
- } else {
- handleBack()
- }
- }
- func inCorrectPswd(password: String) {
- if type == 0 {
- lblRemark.text = "两次手势密码不一致,请重新输入"
- lblRemark.textColor = UIColor.red
- errorCount += 1
- if errorCount == 5 {
- errorCount = 0
- strSetPassword = ""
- lblRemark.text = "请重新输入您的手势"
- lblRemark.textColor = CommonUntils.getUIColorFromRGB(rgbValue: 0x999999, alpha: 1.0)
- DBGuestureLock.clearPassword()
- }
- } else {
- lblRemark.text = "手势密码不正确,请重新输入"
- lblRemark.textColor = UIColor.red
- errorCount += 1
- if errorCount == 5 {
- errorCount = 0
- viewTemp.isHidden = false
- count = 60
- timer.fireDate = Date.distantPast
- }
- }
- }
- var count = 60
- @objc func move() {
- lblRemark.text = "\(count)s后再试"
- lblRemark.textColor = UIColor.red
- count -= 1
- if count == 0 {
- lblRemark.text = "请输入您的手势"
- lblRemark.textColor = CommonUntils.getUIColorFromRGB(rgbValue: 0x999999, alpha: 1.0)
- timer.fireDate = Date.distantFuture
- viewTemp.isHidden = true
- }
- }
- @IBAction func btnOtherLoginClick(_ sender: Any) {
- let login = LoginViewController()
- login.type = 1
- toViewController(viewController: login)
- }
- override func viewWillAppear(_ animated: Bool) {
- super.viewWillAppear(animated)
- }
- override func viewDidAppear(_ animated: Bool) {
- super.viewDidAppear(animated)
- closeRightBack()
- }
- override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: Bundle?) {
- super.init(nibName: "GuesturePasswordViewController", bundle: nil)
- }
- required init?(coder aDecoder: NSCoder) {
- fatalError("init(coder:) has not been implemented")
- }
- }
|