Skip to content

Commit 618e236

Browse files
authored
Merge pull request #19 from codeRIT/peter-adminlogin
Fixes #15, Admin login now works
2 parents de29325 + e060e63 commit 618e236

3 files changed

Lines changed: 50 additions & 30 deletions

File tree

BrickHack-Mobile/AlertMessage.swift

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,14 @@ class MessageHandler {
2323
static func showAlertMessage(withTitle title: String, body: String, type: MessageType ) {
2424

2525
let view = MessageView.viewFromNib(layout: .tabView)
26-
view.configureTheme(.error)
26+
27+
// Map our fake type to their type
28+
switch type {
29+
case .error: view.configureTheme(.error)
30+
case .warning: view.configureTheme(.warning)
31+
case .info: view.configureTheme(.info)
32+
}
33+
2734
view.button?.isHidden = true
2835
view.configureContent(title: title,
2936
body: body,
@@ -103,4 +110,11 @@ class MessageHandler {
103110
body: "Please try again later.",
104111
type: .error)
105112
}
113+
114+
static func showUnknownUserDataError() {
115+
print("ERROR: Could not find questionnaire for user.")
116+
showAlertMessage(withTitle: "User name unknown!",
117+
body: "Setting a placeholder name in the meantime...",
118+
type: .info)
119+
}
106120
}

BrickHack-Mobile/Controllers/LoginViewController.swift

Lines changed: 35 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -136,23 +136,6 @@ class LoginViewController: UIViewController {
136136
print("passed user object")
137137
eventsVC.currentUser = self.currentUser
138138
}
139-
140-
141-
// Check for MainTabBarController (skip through nav controller)
142-
// Note: not used!
143-
/*
144-
if let tabVC = segue.destination.children.first as? MainTabBarController {
145-
146-
// Check if valid user (on error, user will reauth)
147-
guard userID != 0 else {
148-
MessageHandler.showInvalidUserError()
149-
return
150-
}
151-
152-
// Pass data to the tab bar controller, which will handle passing its own children
153-
tabVC.userID = userID
154-
tabVC.oauthGrant = oauthGrant
155-
} */
156139
}
157140
}
158141

@@ -176,13 +159,15 @@ class LoginViewController: UIViewController {
176159
SVProgressHUD.show()
177160
}
178161

162+
// MARK: User data request
179163
URLSession.shared.dataTask(with: signedNameRequest) { (data, response, error) in
180164

181165
// MARK: Error checking
182166
guard error == nil else {
183167
DispatchQueue.main.async {
184168
MessageHandler.showNetworkError(withText: error!.localizedDescription)
185169
SVProgressHUD.dismiss()
170+
self.logout()
186171
}
187172
return
188173
}
@@ -191,6 +176,7 @@ class LoginViewController: UIViewController {
191176
DispatchQueue.main.async {
192177
MessageHandler.showUserDataParsingError()
193178
SVProgressHUD.dismiss()
179+
self.logout()
194180
}
195181
return
196182
}
@@ -200,6 +186,7 @@ class LoginViewController: UIViewController {
200186
DispatchQueue.main.async {
201187
MessageHandler.showNetworkError(withText: "Invalid response code")
202188
SVProgressHUD.dismiss()
189+
self.logout()
203190
}
204191
return
205192
}
@@ -208,30 +195,50 @@ class LoginViewController: UIViewController {
208195
DispatchQueue.main.async {
209196
MessageHandler.showNetworkError(withText: "User account not found")
210197
SVProgressHUD.dismiss()
198+
self.logout()
211199
}
212200
return
213201
}
214202

215-
216203
// MARK: Data conversion
217204

205+
var unknownErrorOccured = false
206+
218207
// Convert server data to our User object
219208
do {
220209
self.currentUser = try JSONDecoder().decode(User.self, from: data)
221-
} catch (let error) {
210+
} catch {
211+
212+
print("Got in error")
213+
214+
// This error might be fixable!
215+
// Admin accounts don't have a questionnaire, and if the user was
216+
// able to login, then this is almost certainly an admin account.
217+
// (Or their questionnaire doesn't exist).
218+
219+
unknownErrorOccured = true
222220
DispatchQueue.main.async {
223-
print("parsing error: \(error)")
224-
MessageHandler.showUserDataParsingError(withText: "Unable to convert JSON")
225-
SVProgressHUD.dismiss()
221+
MessageHandler.showUnknownUserDataError()
226222
}
227-
return
223+
224+
// In this case, we just assign some blank data.
225+
self.currentUser = User(firstName: "Mystery", lastName: "User", major: "Bachelors of codeRIT")
228226
}
229227

230-
// Now that we have the user data, go to the main screen,
231-
// passing the data forward!
232-
DispatchQueue.main.async {
233-
SVProgressHUD.dismiss()
234-
self.performSegue(withIdentifier: "authSuccessSegue", sender: self)
228+
// Now that we have the user data (or fake admin data),
229+
// go to the main screen, and pass the data forward!
230+
231+
// If error occured, give user like three seconds to read it before moving on
232+
if unknownErrorOccured {
233+
DispatchQueue.main.asyncAfter(deadline: .now() + .seconds(3)) {
234+
SVProgressHUD.dismiss()
235+
self.performSegue(withIdentifier: "authSuccessSegue", sender: self)
236+
}
237+
} else {
238+
DispatchQueue.main.async {
239+
SVProgressHUD.dismiss()
240+
self.performSegue(withIdentifier: "authSuccessSegue", sender: self)
241+
}
235242
}
236243

237244
return

BrickHack-Mobile/Models/ScheduleParser.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,6 @@ class ScheduleParser {
241241
case 0:
242242

243243
guard rowIndex > 1 || !currentEvent.title.isEmpty else {
244-
print("broken like me right now")
245244
break
246245
}
247246

0 commit comments

Comments
 (0)