Skip to content

Commit e060e63

Browse files
committed
Fix #15, Admin Login now works
Too complicated to pull admin data for now, so it just assigns an unkown default name.
1 parent 771c280 commit e060e63

3 files changed

Lines changed: 46 additions & 31 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: 31 additions & 29 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,6 +159,7 @@ 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
@@ -216,27 +200,45 @@ class LoginViewController: UIViewController {
216200
return
217201
}
218202

219-
220203
// MARK: Data conversion
221204

205+
var unknownErrorOccured = false
206+
222207
// Convert server data to our User object
223208
do {
224209
self.currentUser = try JSONDecoder().decode(User.self, from: data)
225-
} 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
226220
DispatchQueue.main.async {
227-
print("parsing error: \(error)")
228-
MessageHandler.showUserDataParsingError(withText: "Unable to convert JSON")
229-
SVProgressHUD.dismiss()
230-
self.logout()
221+
MessageHandler.showUnknownUserDataError()
231222
}
232-
return
223+
224+
// In this case, we just assign some blank data.
225+
self.currentUser = User(firstName: "Mystery", lastName: "User", major: "Bachelors of codeRIT")
233226
}
234227

235-
// Now that we have the user data, go to the main screen,
236-
// passing the data forward!
237-
DispatchQueue.main.async {
238-
SVProgressHUD.dismiss()
239-
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+
}
240242
}
241243

242244
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)