Skip to content

Commit

Permalink
WORKS
Browse files Browse the repository at this point in the history
  • Loading branch information
redsn0w422 committed Feb 17, 2017
1 parent d0496a2 commit 0124559
Show file tree
Hide file tree
Showing 30 changed files with 2,731 additions and 274 deletions.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,11 @@
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "HackIllinois: QR/ScanViewController.swift"
timestampString = "508795814.607108"
timestampString = "509007188.377517"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "37"
endingLineNumber = "37"
startingLineNumber = "61"
endingLineNumber = "61"
landmarkName = "viewDidLoad()"
landmarkType = "7">
</BreakpointContent>
Expand Down
42 changes: 33 additions & 9 deletions HackIllinois: QR/ScanViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,48 @@ import SwiftQRCode
import Alamofire
import Foundation


class ScanViewController: UIViewController {
let scanner = QRCode()
var login_session:String = ""

override func viewDidLoad() {
super.viewDidLoad()
print("other view loaded")

let preferences = UserDefaults.standard
if preferences.object(forKey: "session") != nil {
self.login_session = preferences.object(forKey: "session") as! String
}
scanner.prepareScan(view) { (stringValue) -> () in
print(stringValue)
self.scanner.stopScan()
let alert = UIAlertController(title: "data", message: stringValue, preferredStyle: .alert)
let okayAction = UIAlertAction(title: "okay", style: .default) { [weak self] (_) in
self?.scanner.startScan()
}
alert.addAction(okayAction)
DispatchQueue.main.async { [weak self] in
self?.present(alert, animated: true) {
print(self.login_session)

let headers: HTTPHeaders = [
"Authorization": self.login_session
]
// Alamofire.request("https://api.hackillinois.org/v1/tracking/"+stringValue, headers: headers).responseJSON { response in
// print(response)
// }
Alamofire.request("https://api.hackillinois.org/v1/tracking/"+stringValue,
headers: headers).validate().responseJSON { response in
var message:String = ""
var title:String = ""
switch response.result {
case .success:
message = "Attendee can participate"
title = "Success!"
case .failure:
message = "Attendee has already participated"
title = "ERROR!"
}
let alert = UIAlertController(title: title, message: message, preferredStyle: .alert)
let okayAction = UIAlertAction(title: "Okay", style: .default) { [weak self] (_) in
self?.scanner.startScan()
}
alert.addAction(okayAction)
DispatchQueue.main.async { [weak self] in
self?.present(alert, animated: true) {
}
}
}
}
Expand Down
45 changes: 37 additions & 8 deletions HackIllinois: QR/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import AVFoundation
import SwiftQRCode
import Alamofire
import Foundation
import SwiftyJSON

class ViewController: UIViewController {
@IBOutlet var email_input: UITextField!
Expand Down Expand Up @@ -61,9 +62,6 @@ class ViewController: UIViewController {
if preferences.object(forKey: "session") != nil
{
login_session = preferences.object(forKey: "session") as! String
check_session(key: login_session)
// scanner.startScan()
performSegue(withIdentifier: "ShowScanner", sender: self)
}
else {
let parameters: Parameters = [
Expand All @@ -80,15 +78,26 @@ class ViewController: UIViewController {
self?.login_session = authKey
let preferences = UserDefaults.standard
preferences.set(authKey, forKey: "session")
// print(authKey)
// self.scanner.startScan()
self?.performSegue(withIdentifier: "ShowScanner", sender: self)
}
}
}
}
}
}
check_session(key: login_session)
let role = check_permissions(key: login_session)
if (role == "SCAN" || role == "ALL") {
performSegue(withIdentifier: "ShowScanner", sender: self)
}
else {
let alert = UIAlertController(title: "Error", message: "Permissions error", preferredStyle: .alert)
let okayAction = UIAlertAction(title: "Okay", style: .default)
alert.addAction(okayAction)
DispatchQueue.main.async { [weak self] in
self?.present(alert, animated: true) {
}
}
}
}

func check_session(key: String) {
Expand All @@ -112,6 +121,28 @@ class ViewController: UIViewController {
}
}

func check_permissions(key: String) -> String {
if let data = Data(base64Encoded: key.components(separatedBy: ".")[1]) {
let json = JSON(data)
// if voluteer, staff, or admin, they can scan
// if admin, they can also create events
let role = json["roles"].arrayValue[0]["role"].stringValue
if (role == "STAFF" || role == "VOLUNTEER") {
return "SCAN"
}
else if (role == "ADMIN")
{
return "ALL"
}
else {
return "NONE"
}
}
else {
return "NONE"
}
}


override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
Expand All @@ -121,7 +152,5 @@ class ViewController: UIViewController {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}


}

2 changes: 1 addition & 1 deletion Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ target 'HackIllinois: QR' do

pod 'SwiftQRCode'
pod 'Alamofire'

pod 'SwiftyJSON'

# Pods for HackIllinois: QR
target 'HackIllinois: QRTests' do
Expand Down
5 changes: 4 additions & 1 deletion Podfile.lock
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
PODS:
- Alamofire (4.3.0)
- SwiftQRCode (3.0.2)
- SwiftyJSON (3.1.4)

DEPENDENCIES:
- Alamofire
- SwiftQRCode
- SwiftyJSON

SPEC CHECKSUMS:
Alamofire: 856a113053a7bc9cbe5d6367a555d773fc5cfef7
SwiftQRCode: 280589699d84195c2c573011aa52f2c015c31c34
SwiftyJSON: c2842d878f95482ffceec5709abc3d05680c0220

PODFILE CHECKSUM: 3137f185b914865aceba965eb0ea5375283c41e9
PODFILE CHECKSUM: 87c148bddd69768669c938e766f45d5299b6e25a

COCOAPODS: 1.2.0
5 changes: 4 additions & 1 deletion Pods/Manifest.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 0124559

Please sign in to comment.