|
@@ -9,7 +9,7 @@ import UIKit
|
|
|
import RxSwift
|
|
|
import RxCocoa
|
|
|
import SwiftyUserDefaults
|
|
|
-import AuthenticationServices
|
|
|
+
|
|
|
|
|
|
final class LoginViewController: BaseViewController {
|
|
|
|
|
@@ -18,6 +18,7 @@ final class LoginViewController: BaseViewController {
|
|
|
|
|
|
// MARK: UI属性
|
|
|
|
|
|
+ @IBOutlet weak var wx_btn_layout_L: NSLayoutConstraint!
|
|
|
// 账号
|
|
|
@IBOutlet weak var username_textField: QMUITextField!
|
|
|
//密码
|
|
@@ -63,6 +64,11 @@ final class LoginViewController: BaseViewController {
|
|
|
}
|
|
|
},onError: { Error in
|
|
|
}).disposed(by: disposeBag)
|
|
|
+ //是否审核
|
|
|
+ LocalManager.loginService.dictRequest(dictType: "coach_version").subscribe(onSuccess: { cityItems in
|
|
|
+
|
|
|
+ },onError: { Error in
|
|
|
+ }).disposed(by: disposeBag)
|
|
|
}
|
|
|
// MARK: 私有方法
|
|
|
func setupUI(){
|
|
@@ -76,6 +82,12 @@ final class LoginViewController: BaseViewController {
|
|
|
self.username_textField.placeholderColor = .db_place
|
|
|
self.userpassword_textField.placeholderColor = .db_place
|
|
|
self.userlocation_textField.placeholderColor = .db_place
|
|
|
+// DispatchQueue.main.asyncAfter(deadline: .now() + 0.2) {
|
|
|
+// }
|
|
|
+ if LocalManager.userInfo.ios_login_open == 0 {
|
|
|
+ self.wx_btn_layout_L.constant = 21.f
|
|
|
+ self.apple_button.isHidden = true
|
|
|
+ }
|
|
|
}
|
|
|
func biandView(){
|
|
|
//判断账号的输入是否可用
|
|
@@ -137,7 +149,7 @@ final class LoginViewController: BaseViewController {
|
|
|
}).disposed(by: disposeBag)
|
|
|
//apple id
|
|
|
apple_button.rx.tap.subscribe ({ [unowned self] (_) in
|
|
|
- self.performSignIn()
|
|
|
+ self.showDialog(type: 2)
|
|
|
}).disposed(by: disposeBag)
|
|
|
//登录
|
|
|
login_button.rx.tap
|
|
@@ -214,6 +226,37 @@ final class LoginViewController: BaseViewController {
|
|
|
})
|
|
|
.disposed(by: self.disposeBag)
|
|
|
}).disposed(by: disposeBag)
|
|
|
+ //绑定apple
|
|
|
+ NYAppleApiManager.shared.blockSubject.subscribe(onNext: {[unowned self] array in
|
|
|
+ NYTips.show()
|
|
|
+ self.loginService.authorizationIosRequest(userId: array[0], identityToken: array[1], city: NYAppleApiManager.shared.city).subscribe(onSuccess: {[unowned self] model in
|
|
|
+ NYTips.hide()
|
|
|
+ //判断是否有 openid
|
|
|
+ let data = model.data as AuthorizationDataInfoModel
|
|
|
+ if data.coach != nil {
|
|
|
+ //已经绑定直接登录
|
|
|
+ LocalManager.userInfo.userAccount = data.coach?.idcard
|
|
|
+ LocalManager.userInfo.password = data.coach?.password
|
|
|
+ LocalManager.userInfo.city = self.city
|
|
|
+ LocalManager.userInfo.cityPower = self.cityPower
|
|
|
+ LocalManager.userInfo = data.coach!
|
|
|
+ LocalManager.userInfo.isLogin = true //设置已经登录
|
|
|
+ NYAccountManager.shared.addUserinfo(user: data.coach!)//添加用户信息
|
|
|
+ self.dismiss(animated: true)
|
|
|
+ }else{
|
|
|
+ let bindingViewController = BindingViewController(nibName: "BindingViewController")
|
|
|
+ bindingViewController.bindType = 1
|
|
|
+ bindingViewController.openid = data.openid
|
|
|
+ self.addChild(bindingViewController)
|
|
|
+ self.view.addSubview(bindingViewController.view)
|
|
|
+ }
|
|
|
+ }, onError: { error in
|
|
|
+ NYTips.hide()
|
|
|
+ //NYTips.showErr(txt: (error as! RequestError).errorDescription)
|
|
|
+ print("%@",error)
|
|
|
+ })
|
|
|
+ .disposed(by: self.disposeBag)
|
|
|
+ }).disposed(by: disposeBag)
|
|
|
//添加手势
|
|
|
let tapBackground = UITapGestureRecognizer()
|
|
|
tapBackground.rx.event
|
|
@@ -257,6 +300,11 @@ final class LoginViewController: BaseViewController {
|
|
|
dialogViewController.hide()
|
|
|
return
|
|
|
}
|
|
|
+ if(self.type==2){//apple登录
|
|
|
+ NYAppleApiManager.shared.performSignIn(city:city)
|
|
|
+ dialogViewController.hide()
|
|
|
+ return
|
|
|
+ }
|
|
|
self.userlocation_textField.text = item?.dictLabel
|
|
|
dialogViewController.hide()
|
|
|
}
|
|
@@ -265,53 +313,3 @@ final class LoginViewController: BaseViewController {
|
|
|
}
|
|
|
|
|
|
}
|
|
|
-
|
|
|
-extension LoginViewController: ASAuthorizationControllerDelegate, ASAuthorizationControllerPresentationContextProviding {
|
|
|
- func performSignIn() {
|
|
|
- if #available(iOS 13.0, *) {
|
|
|
- let appleIDProvider = ASAuthorizationAppleIDProvider()
|
|
|
- let request = appleIDProvider.createRequest()
|
|
|
- request.requestedScopes = [.fullName, .email]
|
|
|
-
|
|
|
- let authorizationController = ASAuthorizationController(authorizationRequests: [request])
|
|
|
- authorizationController.delegate = self
|
|
|
- authorizationController.presentationContextProvider = self
|
|
|
- authorizationController.performRequests()
|
|
|
- } else {
|
|
|
- // Fallback on earlier versions
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- // ASAuthorizationControllerDelegate methods
|
|
|
- @available(iOS 13.0, *)
|
|
|
- func authorizationController(controller: ASAuthorizationController, didCompleteWithAuthorization authorization: ASAuthorization) {
|
|
|
- if let appleIDCredential = authorization.credential as? ASAuthorizationAppleIDCredential {
|
|
|
- // Get the user's unique Apple ID and user information
|
|
|
- let userIdentifier = appleIDCredential.user
|
|
|
- let fullName = appleIDCredential.fullName
|
|
|
- let email = appleIDCredential.email
|
|
|
-
|
|
|
- // Handle the user data as needed
|
|
|
- print("User ID: \(userIdentifier)")
|
|
|
- if let fullName = fullName {
|
|
|
- print("Full Name: \(fullName.givenName ?? "") \(fullName.familyName ?? "")")
|
|
|
- }
|
|
|
- if let email = email {
|
|
|
- print("Email: \(email)")
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- @available(iOS 13.0, *)
|
|
|
- func authorizationController(controller: ASAuthorizationController, didCompleteWithError error: Error) {
|
|
|
- // Handle sign-in errors
|
|
|
- print("Sign In with Apple failed: \(error.localizedDescription)")
|
|
|
- }
|
|
|
-
|
|
|
- // ASAuthorizationControllerPresentationContextProviding method
|
|
|
- @available(iOS 13.0, *)
|
|
|
- func presentationAnchor(for controller: ASAuthorizationController) -> ASPresentationAnchor {
|
|
|
- return view.window!
|
|
|
- }
|
|
|
-}
|