From 594b2e4a72e0e28ceafd2c04461f5e59ce9e8deb Mon Sep 17 00:00:00 2001 From: Yasha Mostofi Date: Sat, 18 Feb 2017 11:15:36 -0600 Subject: [PATCH] Multi-ROLE user support --- HackIllinois: QR/Info.plist | 2 +- HackIllinois: QR/ViewController.swift | 15 +++++---------- 2 files changed, 6 insertions(+), 11 deletions(-) diff --git a/HackIllinois: QR/Info.plist b/HackIllinois: QR/Info.plist index e6aa547..d4ef68d 100644 --- a/HackIllinois: QR/Info.plist +++ b/HackIllinois: QR/Info.plist @@ -17,7 +17,7 @@ CFBundleShortVersionString 1.0 CFBundleVersion - 1 + 3 LSRequiresIPhoneOS NSCameraUsageDescription diff --git a/HackIllinois: QR/ViewController.swift b/HackIllinois: QR/ViewController.swift index a1949e7..6ae8359 100644 --- a/HackIllinois: QR/ViewController.swift +++ b/HackIllinois: QR/ViewController.swift @@ -20,17 +20,12 @@ class BaseViewController: UIViewController { func check_permissions(key: String) -> String { let jwt: JWT = try! decode(jwt: key) let json = JSON(jwt.body) - let role = json["roles"][0]["role"].rawString() - if (role == "STAFF" || role == "VOLUNTEER") { - return "SCAN" - } - else if (role == "ADMIN") - { - return "ADMIN" - } - else { - return "NONE" + let roles = json["roles"].arrayValue.map { (role) -> String in + return role.dictionaryValue["role"]!.stringValue } + if roles.contains("ADMIN") { return "ADMIN" } + else if roles.contains("STAFF") || roles.contains("VOLUNTEER") { return "SCAN" } + else { return "NONE" } } func get_email(key: String) -> String {