[+] Implement family checking after login
This commit is contained in:
@@ -48,7 +48,7 @@ class AccountViewController: UIViewController
|
|||||||
func logout()
|
func logout()
|
||||||
{
|
{
|
||||||
// Remove login info
|
// Remove login info
|
||||||
["id", "user", "pass"].forEach { localStorage.removeObject(forKey: $0) }
|
["id", "user", "pass", "family"].forEach { localStorage.removeObject(forKey: $0) }
|
||||||
|
|
||||||
// Switch UI
|
// Switch UI
|
||||||
vLogin.isHidden = false
|
vLogin.isHidden = false
|
||||||
@@ -100,6 +100,19 @@ class LoginVC: UIViewController
|
|||||||
localStorage["pass"] = pass.sha256
|
localStorage["pass"] = pass.sha256
|
||||||
localStorage["id"] = $0
|
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
|
// Send feedback
|
||||||
if login { self.msg("Login success!", "Now you can use account features, yay!") }
|
if login { self.msg("Login success!", "Now you can use account features, yay!") }
|
||||||
else { self.msg("Registration success!", "Now you have an account, 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
|
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
|
// Send request
|
||||||
let a = alert(title, "Please Wait")
|
let a = alert(title, "Please Wait")
|
||||||
send(api, params) { it in a.dismiss { success(it) } }
|
send(api, params) { it in a.dismiss { success(it) } }
|
||||||
err:
|
err:
|
||||||
{
|
{
|
||||||
|
// Call callback error function
|
||||||
|
if let err = err { err($0); return }
|
||||||
|
|
||||||
// Display error message
|
// Display error message
|
||||||
print("===== Error: \($0) =====")
|
print("===== Error: \($0) =====")
|
||||||
let message = errors[$0.trimmingCharacters(in: .whitespaces)]
|
let message = errors[$0.trimmingCharacters(in: .whitespaces)]
|
||||||
|
|||||||
Reference in New Issue
Block a user