| | |
| | | import JQTools |
| | | import RxRelay |
| | | import QMUIKit |
| | | import AuthenticationServices |
| | | |
| | | |
| | | class LoginViewModel{ |
| | |
| | | } |
| | | } |
| | | |
| | | let LoginDismiss_Noti = Notification.Name.init("LoginDismiss_Noti") |
| | | |
| | | class LoginVC: BaseVC { |
| | | |
| | | @IBOutlet weak var btn_loginByPwd: UIButton! |
| | |
| | | @IBOutlet weak var btn_login: UIButton! |
| | | @IBOutlet weak var btn_sendCode: UIButton! |
| | | @IBOutlet weak var btn_isRead: UIButton! |
| | | |
| | | |
| | | private var viewModel = LoginViewModel() |
| | | |
| | |
| | | self.view.layoutIfNeeded() |
| | | } |
| | | }).disposed(by: disposeBag) |
| | | |
| | | NotificationCenter.default.rx.notification(LoginDismiss_Noti).take(until: self.rx.deallocated).subscribe(onNext: { _ in |
| | | self.backAction() |
| | | }).disposed(by: disposeBag) |
| | | } |
| | | |
| | | override func setUI() { |
| | | |
| | | navigationItem.leftBarButtonItem = UIBarButtonItem.jq_creat(image: nav_back_img, target: self, alignment:.left, action: #selector(backAction)).item |
| | | |
| | | btn_eye.isSelected = true |
| | | view.addSubview(unlineImageView) |
| | | unlineImageView.snp.makeConstraints { make in |
| | |
| | | |
| | | btn_register.setAttributedTitle(btn_attribute, for: .normal) |
| | | } |
| | | |
| | | @objc fileprivate func backAction() { |
| | | self.dismiss(animated: true) |
| | | } |
| | | |
| | | |
| | | @IBAction func loginTypeAction(_ sender: UIButton) { |
| | |
| | | } |
| | | |
| | | @IBAction func loginByWechatAction(_ sender: UIButton) { |
| | | guard btn_isRead.isSelected else { |
| | | alertError(msg: "请阅读并同意《用户注册协议》和《用户隐私协议》");return |
| | | } |
| | | //todo |
| | | } |
| | | |
| | | @IBAction func loginByAppleAction(_ sender: UIButton) { |
| | | //todo |
| | | guard btn_isRead.isSelected else { |
| | | alertError(msg: "请阅读并同意《用户注册协议》和《用户隐私协议》");return |
| | | } |
| | | |
| | | let provider = ASAuthorizationAppleIDProvider() //主要作用是用创建相应的请求,查询用户授权状态 |
| | | let request = provider.createRequest() //授权请求,可以设置具体的请求信息 |
| | | request.requestedScopes = [.fullName,.email] |
| | | let vc = ASAuthorizationController(authorizationRequests: [request]) //发送请求控制器,可以设置相应的协议 |
| | | vc.delegate = self |
| | | vc.presentationContextProvider = self |
| | | vc.performRequests() |
| | | } |
| | | |
| | | @IBAction func forgotPwdAction(_ sender: UIButton) { |
| | |
| | | btn_login.jq_gradientNibColor(colorArr: [UIColor(hexStr: "#8EA47A").cgColor,UIColor(hexStr: "#AFCA98").cgColor], cornerRadius: 20) |
| | | } |
| | | } |
| | | |
| | | extension LoginVC:ASAuthorizationControllerPresentationContextProviding{ |
| | | func presentationAnchor(for controller: ASAuthorizationController) -> ASPresentationAnchor { |
| | | return self.view.window! |
| | | } |
| | | } |
| | | extension LoginVC:ASAuthorizationControllerDelegate{ |
| | | func authorizationController(controller: ASAuthorizationController, didCompleteWithAuthorization authorization: ASAuthorization) { |
| | | if let credential = authorization.credential as? ASAuthorizationAppleIDCredential{ |
| | | |
| | | Services.loginByApple(appleId: credential.user).subscribe(onNext: {data in |
| | | if var m = data.data,m.bindStatus == 2{ |
| | | sceneDelegate?.loginSuccess() |
| | | m.loginByAppleToken = String(data: credential.identityToken!, encoding: .utf8) |
| | | m.appleId = credential.user |
| | | |
| | | self.dismiss(animated: true) |
| | | |
| | | UserViewModel.saveLoginInfo(m) |
| | | |
| | | Services.getUserInfo().subscribe(onNext: {data in |
| | | if let model = data.data{ |
| | | UserViewModel.saveAvatarInfo(model) |
| | | } |
| | | }).disposed(by: self.disposeBag) |
| | | }else{ |
| | | let vc = UpdatePhoneVC(credential: credential) |
| | | self.jq_push(vc: vc) |
| | | } |
| | | }).disposed(by: disposeBag) |
| | | |
| | | |
| | | |
| | | // print(credential.user) |
| | | // print(credential.state) |
| | | // print(credential.email) |
| | | // print(credential.fullName?.familyName) |
| | | // print(credential.fullName?.givenName) |
| | | // print(credential.fullName?.middleName) |
| | | // print(String(data: credential.identityToken!, encoding: .utf8)) |
| | | |
| | | |
| | | } |
| | | } |
| | | |
| | | func authorizationController(controller: ASAuthorizationController, didCompleteWithError error: Error) { |
| | | switch (error as! ASAuthorizationError).code { |
| | | case .canceled:print("用户取消") |
| | | case .failed:print("请求失败") |
| | | case .invalidResponse:print("无效响应") |
| | | case .notHandled:print("未处理") |
| | | case .unknown:print("未知错误") |
| | | case .notInteractive:print("未交互") |
| | | case .matchedExcludedCredential:print("排除的凭证匹配") |
| | | @unknown default:break |
| | | } |
| | | } |
| | | } |
| | | |
| | | |