|
|
@@ -8,8 +8,6 @@
|
|
|
import Foundation
|
|
|
import UIKit
|
|
|
import SnapKit
|
|
|
-import GoogleSignIn
|
|
|
-import AuthenticationServices
|
|
|
|
|
|
|
|
|
private weak var curLoginPanel: LNLoginPanel? = nil
|
|
|
@@ -45,22 +43,6 @@ extension LNLoginPanel: LNAccountManagerNotify {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-extension LNLoginPanel: ASAuthorizationControllerDelegate {
|
|
|
- func authorizationController(controller: ASAuthorizationController, didCompleteWithAuthorization authorization: ASAuthorization) {
|
|
|
- guard let credential = authorization.credential as? ASAuthorizationAppleIDCredential,
|
|
|
- let token = credential.identityToken,
|
|
|
- let tokenStr = String(data: token, encoding: .utf8)
|
|
|
- else {
|
|
|
- return
|
|
|
- }
|
|
|
-
|
|
|
- LNAccountManager.shared.loginByApple(data: tokenStr)
|
|
|
- }
|
|
|
-
|
|
|
- func authorizationController(controller: ASAuthorizationController, didCompleteWithError error: any Error) {
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
extension LNLoginPanel {
|
|
|
private func setupViews() {
|
|
|
container.backgroundColor = .text_5.withAlphaComponent(0.7)
|
|
|
@@ -94,13 +76,26 @@ extension LNLoginPanel {
|
|
|
let email = buildEmail()
|
|
|
stackView.addArrangedSubview(email)
|
|
|
#endif
|
|
|
- let phone = buildPhoneLogin()
|
|
|
+ let phone = buildLoginItem(icon: .icLoginPhone, title: .init(key: "B00019"), textColor: .text_1, color: .primary_3)
|
|
|
+ phone.addAction(UIAction(handler: { [weak self] _ in
|
|
|
+ guard let self else { return }
|
|
|
+ pushToLoginPhone()
|
|
|
+ }), for: .touchUpInside)
|
|
|
stackView.addArrangedSubview(phone)
|
|
|
|
|
|
- let apple = buildAppleLogin()
|
|
|
+ let apple = buildLoginItem(icon: .icApple, title: .init(key: "A00285"), textColor: .text_1, color: .init(hex: "#0B0B0A"))
|
|
|
+ apple.addAction(UIAction(handler: { [weak self] _ in
|
|
|
+ guard self != nil else { return }
|
|
|
+ LNAccountManager.shared.doAppleLogin()
|
|
|
+ }), for: .touchUpInside)
|
|
|
stackView.addArrangedSubview(apple)
|
|
|
|
|
|
- let google = buildGoogleLogin()
|
|
|
+ let google = buildLoginItem(icon: .icGoogle, title: .init(key: "A00115"), textColor: .text_5, color: .fill)
|
|
|
+ google.addAction(UIAction(handler: { [weak self] _ in
|
|
|
+ guard let self else { return }
|
|
|
+ guard let topVC = navigationController?.topViewController else { return }
|
|
|
+ LNAccountManager.shared.doGoogleLogin(topVC)
|
|
|
+ }), for: .touchUpInside)
|
|
|
stackView.addArrangedSubview(google)
|
|
|
|
|
|
let tipsLabel = UILabel()
|
|
|
@@ -123,9 +118,9 @@ extension LNLoginPanel {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private func buildPhoneLogin() -> UIView {
|
|
|
+ private func buildLoginItem(icon: UIImage, title: String, textColor: UIColor, color: UIColor) -> UIButton {
|
|
|
let button = UIButton()
|
|
|
- button.setBackgroundImage(.primary_3, for: .normal)
|
|
|
+ button.setBackgroundImage(UIImage.image(for: color), for: .normal)
|
|
|
button.layer.cornerRadius = 24
|
|
|
button.clipsToBounds = true
|
|
|
button.snp.makeConstraints { make in
|
|
|
@@ -133,107 +128,22 @@ extension LNLoginPanel {
|
|
|
}
|
|
|
|
|
|
let ic = UIImageView()
|
|
|
- ic.image = .icLoginPhone
|
|
|
+ ic.image = icon
|
|
|
button.addSubview(ic)
|
|
|
ic.snp.makeConstraints { make in
|
|
|
make.centerY.equalToSuperview()
|
|
|
make.leading.equalToSuperview().offset(12)
|
|
|
}
|
|
|
|
|
|
- let title = UILabel()
|
|
|
- title.font = .heading_h3
|
|
|
- title.textColor = .text_1
|
|
|
- title.text = .init(key: "B00019")
|
|
|
- button.addSubview(title)
|
|
|
- title.snp.makeConstraints { make in
|
|
|
+ let titleLabel = UILabel()
|
|
|
+ titleLabel.font = .heading_h3
|
|
|
+ titleLabel.textColor = textColor
|
|
|
+ titleLabel.text = title
|
|
|
+ button.addSubview(titleLabel)
|
|
|
+ titleLabel.snp.makeConstraints { make in
|
|
|
make.center.equalToSuperview()
|
|
|
}
|
|
|
|
|
|
- button.addAction(UIAction(handler: { [weak self] _ in
|
|
|
- guard let self else { return }
|
|
|
- pushToLoginPhone()
|
|
|
- }), for: .touchUpInside)
|
|
|
-
|
|
|
- return button
|
|
|
- }
|
|
|
-
|
|
|
- private func buildAppleLogin() -> UIView {
|
|
|
- let button = UIButton()
|
|
|
- button.setBackgroundImage(UIImage.image(for: .init(hex: "#0B0B0A")), for: .normal)
|
|
|
- button.layer.cornerRadius = 24
|
|
|
- button.clipsToBounds = true
|
|
|
- button.snp.makeConstraints { make in
|
|
|
- make.height.equalTo(48)
|
|
|
- }
|
|
|
-
|
|
|
- let ic = UIImageView()
|
|
|
- ic.image = .icApple
|
|
|
- button.addSubview(ic)
|
|
|
- ic.snp.makeConstraints { make in
|
|
|
- make.centerY.equalToSuperview()
|
|
|
- make.leading.equalToSuperview().offset(12)
|
|
|
- }
|
|
|
-
|
|
|
- let title = UILabel()
|
|
|
- title.font = .heading_h3
|
|
|
- title.textColor = .text_1
|
|
|
- title.text = .init(key: "A00285")
|
|
|
- button.addSubview(title)
|
|
|
- title.snp.makeConstraints { make in
|
|
|
- make.center.equalToSuperview()
|
|
|
- }
|
|
|
-
|
|
|
- button.addAction(UIAction(handler: { [weak self] _ in
|
|
|
- guard let self else { return }
|
|
|
- let provider = ASAuthorizationAppleIDProvider()
|
|
|
- let request = provider.createRequest()
|
|
|
- request.requestedScopes = [.fullName, .email]
|
|
|
- let controller = ASAuthorizationController(authorizationRequests: [request])
|
|
|
- controller.delegate = self
|
|
|
-// controller.presentationContextProvider = self
|
|
|
- controller.performRequests()
|
|
|
- }), for: .touchUpInside)
|
|
|
-
|
|
|
- return button
|
|
|
- }
|
|
|
-
|
|
|
- private func buildGoogleLogin() -> UIView {
|
|
|
- let button = UIButton()
|
|
|
- button.setBackgroundImage(.fill, for: .normal)
|
|
|
- button.layer.cornerRadius = 24
|
|
|
- button.clipsToBounds = true
|
|
|
- button.snp.makeConstraints { make in
|
|
|
- make.height.equalTo(48)
|
|
|
- }
|
|
|
-
|
|
|
- let ic = UIImageView()
|
|
|
- ic.image = .icGoogle
|
|
|
- button.addSubview(ic)
|
|
|
- ic.snp.makeConstraints { make in
|
|
|
- make.centerY.equalToSuperview()
|
|
|
- make.leading.equalToSuperview().offset(22)
|
|
|
- }
|
|
|
-
|
|
|
- let title = UILabel()
|
|
|
- title.font = .heading_h3
|
|
|
- title.textColor = .text_5
|
|
|
- title.text = .init(key: "A00115")
|
|
|
- button.addSubview(title)
|
|
|
- title.snp.makeConstraints { make in
|
|
|
- make.center.equalToSuperview()
|
|
|
- }
|
|
|
-
|
|
|
- button.addAction(UIAction(handler: { [weak self] _ in
|
|
|
- guard let self else { return }
|
|
|
- guard let topVC = navigationController?.topViewController else { return }
|
|
|
- GIDSignIn.sharedInstance.signIn(withPresenting: topVC) { [weak self] result, err in
|
|
|
- guard self != nil else { return }
|
|
|
- guard err == nil, let result else { return }
|
|
|
- guard let token = result.user.idToken?.tokenString else { return }
|
|
|
- LNAccountManager.shared.loginByGoogle(data: token)
|
|
|
- }
|
|
|
- }), for: .touchUpInside)
|
|
|
-
|
|
|
return button
|
|
|
}
|
|
|
|