@@ -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
0 commit comments