| | |
| | | // |
| | | |
| | | import UIKit |
| | | import AuthenticationServices |
| | | import QMUIKit |
| | | import JQTools |
| | | |
| | | class UpdatePhoneVC: BaseVC { |
| | | |
| | | private var credential:ASAuthorizationAppleIDCredential? |
| | | @IBOutlet weak var tf_phone: QMUITextField! |
| | | @IBOutlet weak var tf_code: QMUITextField! |
| | | @IBOutlet weak var btn_code: UIButton! |
| | | @IBOutlet weak var btn_isRead: UIButton! |
| | | |
| | | init(credential:ASAuthorizationAppleIDCredential? = nil) { |
| | | super.init(nibName: nil, bundle: nil) |
| | | self.credential = credential |
| | | } |
| | | |
| | | @MainActor required init?(coder: NSCoder) { |
| | | fatalError("init(coder:) has not been implemented") |
| | | } |
| | | |
| | | override func viewDidLoad() { |
| | | super.viewDidLoad() |
| | | title = "验证手机号" |
| | | |
| | | } |
| | | |
| | | @IBAction func getCodeAction(_ sender: UIButton) { |
| | | view.endEditing(true) |
| | | guard tf_phone.text!.jq_isPhone else { |
| | | alertError(msg: "请输入正确的手机号");return |
| | | } |
| | | |
| | | Services.sendCode(type: .threePlantform).subscribe(onNext: {data in |
| | | if let _ = data.data{ |
| | | sender.jq_openCountDown(60, defultTitle: "发送验证码") { |
| | | sender.titleLabel?.font = UIFont.systemFont(ofSize: 12) |
| | | sender.setTitleColor(.black.withAlphaComponent(0.3), for: .normal) |
| | | } completeClouse: { |
| | | sender.titleLabel?.font = UIFont.systemFont(ofSize: 14, weight: .medium) |
| | | sender.setTitleColor(UIColor(hexStr: "#96AD81"), for: .normal) |
| | | } |
| | | } |
| | | }).disposed(by: disposeBag) |
| | | } |
| | | |
| | | @IBAction func loginAction(_ sender: UIButton) { |
| | | view.endEditing(true) |
| | | guard tf_phone.text!.jq_isPhone else { |
| | | alertError(msg: "请输入正确的手机号");return |
| | | } |
| | | |
| | | guard tf_code.text!.count == 6 else { |
| | | alertError(msg: "请输入6位验证码");return |
| | | } |
| | | guard let credentialUser = credential?.user else { |
| | | alertError(msg: "Apple登录授权异常");return |
| | | } |
| | | |
| | | let formatName = String(format: "%@%@%@", credential?.fullName?.familyName ?? "",credential?.fullName?.middleName ?? "", credential?.fullName?.middleName ?? "") |
| | | |
| | | Services.confirmByApple(cellPhone: tf_phone.text!, captcha: tf_code.text!, loginType: .apple, wxOrAppleId: credentialUser,name: formatName, mail: credential!.email).subscribe(onNext: {data in |
| | | if var model = data.data{ |
| | | model.loginByAppleToken = String(data: self.credential!.identityToken!, encoding: .utf8) |
| | | model.appleId = self.credential!.user |
| | | sceneDelegate?.loginSuccess() |
| | | NotificationCenter.default.post(name: LoginDismiss_Noti, object: nil, userInfo: nil) |
| | | UserViewModel.saveLoginInfo(model) |
| | | |
| | | Services.getUserInfo().subscribe(onNext: {data in |
| | | if let model = data.data{ |
| | | UserViewModel.saveAvatarInfo(model) |
| | | } |
| | | }).disposed(by: self.disposeBag) |
| | | } |
| | | }).disposed(by: disposeBag) |
| | | } |
| | | |
| | | } |