younger_times
2023-05-06 a8c2422e12becdfc3da0907ff5b589f7f86d0dd5
BrokerDriver/Login/VC/ForgotPwdVC.swift
@@ -6,23 +6,78 @@
//
import UIKit
import QMUIKit
class ForgotPwdVC: BaseViewController {
    @IBOutlet weak var tf_email: QMUITextField!
    @IBOutlet weak var tf_code: QMUITextField!
    @IBOutlet weak var tf_pwd: QMUITextField!
    @IBOutlet weak var tf_apwd: QMUITextField!
    override func viewDidLoad() {
        super.viewDidLoad()
    }
    private func check(getCode:Bool = false)->Bool{
        guard !tf_email.isEmpty else {
            alert(msg: "Please input email");return false
        }
    /*
    // MARK: - Navigation
        guard tf_email.text!.jq_isEmail else {
            alert(msg: "Invaild email");return false
        }
    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        // Get the new view controller using segue.destination.
        // Pass the selected object to the new view controller.
        if getCode{return true}
        guard !tf_code.isEmpty else {
            alert(msg: "Please input code");return false
        }
        guard !tf_pwd.isEmpty else {
            alert(msg: "Please input password");return false
        }
        guard !tf_apwd.isEmpty else {
            alert(msg: "Please input password again");return false
        }
        guard tf_apwd.text != tf_pwd.text else {
            alert(msg: "Entered passwords differ");return false
        }
        return true
    }
    */
    @IBAction func getCodeAction(_ sender: UIButton) {
        if check(getCode:true){
            Services.sendCode(email: tf_email.text!).subscribe(onNext: { data in
                if data.code == 200{
                    sender.openCountDown()
                }else{
                    alert(msg: data.msg)
                }
            }) { error in
                alert(msg: error.localizedDescription)
            }.disposed(by: disposeBag)
        }
    }
    @IBAction func submitAction(_ sender: UIButton) {
        if check(){
            Services.forget(code: tf_code.text!, password: tf_pwd.text!, username: tf_email.text!).subscribe(onNext: {data in
                if data.code == 200{
                    alert(msg: "Update successed!")
                    DispatchQueue.main.asyncAfter(deadline: .now()+1) {
                        self.navigationController?.popViewController()
                    }
                }else{
                    alert(msg: data.msg)
                }
            }) { error in
                alert(msg: error.localizedDescription)
            }.disposed(by: disposeBag)
        }
    }
}