Some google auth fixes
This commit is contained in:
parent
1cbee99f12
commit
5fd6bf65f3
@ -15,6 +15,7 @@ class GoogleSignInController: UIViewController, WKNavigationDelegate {
|
|||||||
@IBOutlet weak var webView: WKWebView!
|
@IBOutlet weak var webView: WKWebView!
|
||||||
|
|
||||||
private var codeVerifier: String = ""
|
private var codeVerifier: String = ""
|
||||||
|
public var completion: (() -> Void)?
|
||||||
|
|
||||||
override func viewDidLoad() {
|
override func viewDidLoad() {
|
||||||
super.viewDidLoad()
|
super.viewDidLoad()
|
||||||
@ -60,7 +61,9 @@ class GoogleSignInController: UIViewController, WKNavigationDelegate {
|
|||||||
Settings.shared.user.googleIdToken = idToken
|
Settings.shared.user.googleIdToken = idToken
|
||||||
Settings.shared.user.googleRefreshToken = refreshToken
|
Settings.shared.user.googleRefreshToken = refreshToken
|
||||||
DispatchQueue.main.async {
|
DispatchQueue.main.async {
|
||||||
self.dismiss(animated: true, completion: nil)
|
self.dismiss(animated: true) {
|
||||||
|
self.completion?()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -43,11 +43,16 @@ class SettingsController: FormViewController {
|
|||||||
func displayLogoutSheet() {
|
func displayLogoutSheet() {
|
||||||
guard let jwtString = Settings.shared.user.googleIdToken, let jwt = JWT(string: jwtString) else { return }
|
guard let jwtString = Settings.shared.user.googleIdToken, let jwt = JWT(string: jwtString) else { return }
|
||||||
|
|
||||||
let sheet = UIAlertController(title: jwt.payload.name, message: "You are currently signed in with email \(jwt.payload.email). It allows us to find more data about vehicles.", preferredStyle: .actionSheet)
|
let sheet = UIAlertController(title: jwt.payload.name, message: "You are currently signed in with email \(jwt.payload.email). It will help to gather more data about vehicles.", preferredStyle: .actionSheet)
|
||||||
|
|
||||||
let cancel = UIAlertAction(title: "Cancel", style: .cancel) { _ in sheet.dismiss(animated: true, completion: nil) }
|
let cancel = UIAlertAction(title: "Cancel", style: .cancel) { _ in sheet.dismiss(animated: true, completion: nil) }
|
||||||
let logout = UIAlertAction(title: "Sign Out", style: .destructive) { _ in
|
let logout = UIAlertAction(title: "Sign Out", style: .destructive) { _ in
|
||||||
Settings.shared.user.googleIdToken = nil
|
Settings.shared.user.googleIdToken = nil
|
||||||
|
Settings.shared.user.googleRefreshToken = nil
|
||||||
|
if let googleRow = self.form.rowBy(tag: "GoogleAccount") as? LabelRow {
|
||||||
|
googleRow.value = "Log In"
|
||||||
|
googleRow.reload()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
sheet.addAction(logout)
|
sheet.addAction(logout)
|
||||||
@ -57,7 +62,17 @@ class SettingsController: FormViewController {
|
|||||||
|
|
||||||
func loginToGoogle() {
|
func loginToGoogle() {
|
||||||
let storyboard = UIStoryboard(name: "Main", bundle: nil)
|
let storyboard = UIStoryboard(name: "Main", bundle: nil)
|
||||||
let vc = storyboard.instantiateViewController(identifier: "GoogleSignInController")
|
if let vc = storyboard.instantiateViewController(identifier: "GoogleSignInController") as? GoogleSignInController {
|
||||||
|
vc.completion = {
|
||||||
|
guard let googleRow = self.form.rowBy(tag: "GoogleAccount") as? LabelRow else { return }
|
||||||
|
if let jwtString = Settings.shared.user.googleIdToken, let jwt = JWT(string: jwtString) {
|
||||||
|
googleRow.value = jwt.payload.email
|
||||||
|
} else {
|
||||||
|
googleRow.value = "Log In"
|
||||||
|
}
|
||||||
|
googleRow.reload()
|
||||||
|
}
|
||||||
self.present(vc, animated: true)
|
self.present(vc, animated: true)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|||||||
4
AutoCat/ThirdParty/Api.swift
vendored
4
AutoCat/ThirdParty/Api.swift
vendored
@ -72,6 +72,10 @@ class Api {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static func checkVehicle(by number: String) -> Observable<Vehicle> {
|
public static func checkVehicle(by number: String) -> Observable<Vehicle> {
|
||||||
|
if let token = Settings.shared.user.googleIdToken, let jwt = JWT(string: token) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
return self.makeRequest(api: "vehicles/check", method: "POST", body: ["number": number]).map { (vehicle: Vehicle) -> Vehicle in
|
return self.makeRequest(api: "vehicles/check", method: "POST", body: ["number": number]).map { (vehicle: Vehicle) -> Vehicle in
|
||||||
vehicle.addedDate = Date().timeIntervalSince1970*1000
|
vehicle.addedDate = Date().timeIntervalSince1970*1000
|
||||||
return vehicle
|
return vehicle
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user