[+] Implement family checking after login
This commit is contained in:
@@ -48,7 +48,7 @@ class AccountViewController: UIViewController
|
||||
func logout()
|
||||
{
|
||||
// Remove login info
|
||||
["id", "user", "pass"].forEach { localStorage.removeObject(forKey: $0) }
|
||||
["id", "user", "pass", "family"].forEach { localStorage.removeObject(forKey: $0) }
|
||||
|
||||
// Switch UI
|
||||
vLogin.isHidden = false
|
||||
@@ -100,6 +100,19 @@ class LoginVC: UIViewController
|
||||
localStorage["pass"] = pass.sha256
|
||||
localStorage["id"] = $0
|
||||
|
||||
send(APIs.familyGet)
|
||||
{
|
||||
localStorage["family"] = $0
|
||||
self.loginSuccess(login)
|
||||
}
|
||||
err: { it in self.loginSuccess(login) }
|
||||
}
|
||||
}
|
||||
|
||||
private func loginSuccess(_ login: Bool)
|
||||
{
|
||||
ui
|
||||
{
|
||||
// Send feedback
|
||||
if login { self.msg("Login success!", "Now you can use account features, yay!") }
|
||||
else { self.msg("Registration success!", "Now you have an account, yay!") }
|
||||
|
||||
@@ -148,13 +148,16 @@ extension UIViewController
|
||||
/**
|
||||
Send a http request even more conveniently
|
||||
*/
|
||||
func sendReq<T: Decodable>(_ api: API<T>, title: String, errors: [String: String] = [:], params: [String: String]? = [:], _ success: @escaping (T) -> Void, err: @escaping (String) -> Void = {it in})
|
||||
func sendReq<T: Decodable>(_ api: API<T>, title: String, errors: [String: String] = [:], params: [String: String]? = [:], _ success: @escaping (T) -> Void, err: ((String) -> Void)? = nil)
|
||||
{
|
||||
// Send request
|
||||
let a = alert(title, "Please Wait")
|
||||
send(api, params) { it in a.dismiss { success(it) } }
|
||||
err:
|
||||
{
|
||||
// Call callback error function
|
||||
if let err = err { err($0); return }
|
||||
|
||||
// Display error message
|
||||
print("===== Error: \($0) =====")
|
||||
let message = errors[$0.trimmingCharacters(in: .whitespaces)]
|
||||
|
||||
Reference in New Issue
Block a user