-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCheckAuthViewController.swift
More file actions
92 lines (70 loc) · 3.14 KB
/
Copy pathCheckAuthViewController.swift
File metadata and controls
92 lines (70 loc) · 3.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
//
// CheckAuthViewController.swift
// Absinthe-iOS
//
// Created by Alyssa Torres on 10/24/16.
// Copyright © 2016 AppDelegates. All rights reserved.
//
import UIKit
import PromiseKit
enum AuthError: Error {
case noEmailError
case noPasswordError
}
class CheckAuthViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
checkUserStatus()
.then{ response -> Void in
self.performSegue(withIdentifier: "fromCheckAuthToMainTabs", sender: nil)
}
.catch{ err -> Void in
self.performSegue(withIdentifier: "fromCheckAuthToLR", sender: nil)
}
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
override var preferredStatusBarStyle : UIStatusBarStyle {
return .lightContent
}
func checkUserStatus() -> Promise<Bool> {
return Promise<Bool> { resolve, reject in
if let email = Settings.sharedInstance.userEmail {
if let pwd = Settings.sharedInstance.userPassword {
Asahi.sharedInstance.login(email, password: pwd)
.then{ response -> Void in
Asahi.sharedInstance.checkAuthStatus()
.then{ response -> Void in
log.debug("Successfully checked auth")
if let first = response["firstName"].string {
Settings.sharedInstance.userFirstName = first
}
if let last = response["lastName"].string {
Settings.sharedInstance.userLastName = last
}
if let email = response["auth"]["email"].string {
Settings.sharedInstance.userEmail = email
}
if let id = response["id"].string {
Settings.sharedInstance.userId = id
}
resolve(true)
}
.catch{ err -> Void in
reject(err)
}
}
.catch{ err -> Void in
reject(err)
}
} else {
reject(AuthError.noPasswordError)
}
} else {
reject(AuthError.noEmailError)
}
}
}
}