Skip to content

Commit

Permalink
iOS works
Browse files Browse the repository at this point in the history
  • Loading branch information
redsn0w422 committed Feb 14, 2017
1 parent dfe4f9e commit 5014e7f
Show file tree
Hide file tree
Showing 14 changed files with 211 additions and 44 deletions.
4 changes: 4 additions & 0 deletions HackIllinois: QR.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
/* Begin PBXBuildFile section */
2C2EFF3751D864194E8AAF57 /* Pods_HackIllinois__QRTests.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 66B938DD4A3F3CC85BE83D48 /* Pods_HackIllinois__QRTests.framework */; };
3DA2A117F80259320E343F6A /* Pods_HackIllinois__QR.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 305529D902BF1604EEA51AF9 /* Pods_HackIllinois__QR.framework */; };
84C7D6CF1E5394110018AA46 /* ScanViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84C7D6CE1E5394110018AA46 /* ScanViewController.swift */; };
84EFA7471E51407B00424F8F /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84EFA7461E51407B00424F8F /* AppDelegate.swift */; };
84EFA7491E51407B00424F8F /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84EFA7481E51407B00424F8F /* ViewController.swift */; };
84EFA74C1E51407B00424F8F /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 84EFA74A1E51407B00424F8F /* Main.storyboard */; };
Expand Down Expand Up @@ -44,6 +45,7 @@
417B10D974E0A5876B5A6C99 /* Pods-HackIllinois: QRTests.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-HackIllinois: QRTests.release.xcconfig"; path = "Pods/Target Support Files/Pods-HackIllinois: QRTests/Pods-HackIllinois: QRTests.release.xcconfig"; sourceTree = "<group>"; };
66B938DD4A3F3CC85BE83D48 /* Pods_HackIllinois__QRTests.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_HackIllinois__QRTests.framework; sourceTree = BUILT_PRODUCTS_DIR; };
6B154F548C1D70B49E437A8B /* Pods-HackIllinois: QR.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-HackIllinois: QR.release.xcconfig"; path = "Pods/Target Support Files/Pods-HackIllinois: QR/Pods-HackIllinois: QR.release.xcconfig"; sourceTree = "<group>"; };
84C7D6CE1E5394110018AA46 /* ScanViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ScanViewController.swift; sourceTree = "<group>"; };
84EFA7431E51407B00424F8F /* HackIllinois: QR.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "HackIllinois: QR.app"; sourceTree = BUILT_PRODUCTS_DIR; };
84EFA7461E51407B00424F8F /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
84EFA7481E51407B00424F8F /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -130,6 +132,7 @@
84EFA7461E51407B00424F8F /* AppDelegate.swift */,
84EFA7481E51407B00424F8F /* ViewController.swift */,
84EFA74A1E51407B00424F8F /* Main.storyboard */,
84C7D6CE1E5394110018AA46 /* ScanViewController.swift */,
84EFA74D1E51407B00424F8F /* Assets.xcassets */,
84EFA74F1E51407B00424F8F /* LaunchScreen.storyboard */,
84EFA7521E51407B00424F8F /* Info.plist */,
Expand Down Expand Up @@ -451,6 +454,7 @@
files = (
84EFA7491E51407B00424F8F /* ViewController.swift in Sources */,
84EFA7471E51407B00424F8F /* AppDelegate.swift in Sources */,
84C7D6CF1E5394110018AA46 /* ScanViewController.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -94,5 +94,21 @@
</Locations>
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
shouldBeEnabled = "No"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "HackIllinois: QR/ScanViewController.swift"
timestampString = "508795814.607108"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "37"
endingLineNumber = "37"
landmarkName = "viewDidLoad()"
landmarkType = "7">
</BreakpointContent>
</BreakpointProxy>
</Breakpoints>
</Bucket>
4 changes: 4 additions & 0 deletions HackIllinois: QR/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
//

import UIKit
import AVFoundation
import SwiftQRCode
import Alamofire
import Foundation

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
Expand Down
25 changes: 25 additions & 0 deletions HackIllinois: QR/Assets.xcassets/AppIcon.appiconset/Contents.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
{
"images" : [
{
"idiom" : "iphone",
"size" : "20x20",
"scale" : "2x"
},
{
"idiom" : "iphone",
"size" : "20x20",
"scale" : "3x"
},
{
"idiom" : "iphone",
"size" : "29x29",
Expand Down Expand Up @@ -30,6 +40,16 @@
"size" : "60x60",
"scale" : "3x"
},
{
"idiom" : "ipad",
"size" : "20x20",
"scale" : "1x"
},
{
"idiom" : "ipad",
"size" : "20x20",
"scale" : "2x"
},
{
"idiom" : "ipad",
"size" : "29x29",
Expand Down Expand Up @@ -59,6 +79,11 @@
"idiom" : "ipad",
"size" : "76x76",
"scale" : "2x"
},
{
"idiom" : "ipad",
"size" : "83.5x83.5",
"scale" : "2x"
}
],
"info" : {
Expand Down
6 changes: 6 additions & 0 deletions HackIllinois: QR/Assets.xcassets/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"info" : {
"version" : 1,
"author" : "xcode"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"images" : [
{
"idiom" : "universal",
"filename" : "landing-logo-2.png",
"scale" : "1x"
},
{
"idiom" : "universal",
"filename" : "landing-logo.png",
"scale" : "2x"
},
{
"idiom" : "universal",
"filename" : "landing-logo-1.png",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
47 changes: 46 additions & 1 deletion HackIllinois: QR/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="11757"/>
<capability name="Aspect ratio constraints" minToolsVersion="5.1"/>
<capability name="Constraints to layout margins" minToolsVersion="6.0"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
Expand Down Expand Up @@ -44,13 +45,22 @@
<action selector="DoLogin:" destination="BYZ-38-t0r" eventType="touchUpInside" id="ucA-5L-msB"/>
</connections>
</button>
<imageView userInteractionEnabled="NO" contentMode="scaleToFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" image="hackillinois" translatesAutoresizingMaskIntoConstraints="NO" id="x5x-Ek-ZC4">
<rect key="frame" x="168" y="20" width="40" height="40"/>
<constraints>
<constraint firstAttribute="width" secondItem="x5x-Ek-ZC4" secondAttribute="height" multiplier="1:1" id="S92-Q0-ugm"/>
<constraint firstAttribute="height" constant="40" id="WD4-5N-hJS"/>
</constraints>
</imageView>
</subviews>
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<color key="backgroundColor" red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<constraints>
<constraint firstItem="OhU-0G-emJ" firstAttribute="leading" secondItem="8bC-Xf-vdC" secondAttribute="leadingMargin" constant="14" id="AKp-OB-tE5"/>
<constraint firstItem="OhU-0G-emJ" firstAttribute="trailing" secondItem="Yol-Ws-fKc" secondAttribute="trailing" id="Din-mW-xe4"/>
<constraint firstItem="FWv-Br-zeN" firstAttribute="centerX" secondItem="Yol-Ws-fKc" secondAttribute="centerX" id="MUq-Hw-rOr"/>
<constraint firstItem="x5x-Ek-ZC4" firstAttribute="top" secondItem="8bC-Xf-vdC" secondAttribute="topMargin" constant="20" id="MzT-eh-G5q"/>
<constraint firstItem="Yol-Ws-fKc" firstAttribute="top" secondItem="OhU-0G-emJ" secondAttribute="bottom" constant="10" id="RyJ-c8-CiK"/>
<constraint firstItem="x5x-Ek-ZC4" firstAttribute="centerX" secondItem="8bC-Xf-vdC" secondAttribute="centerX" id="j2q-mM-SgI"/>
<constraint firstItem="OhU-0G-emJ" firstAttribute="leading" secondItem="Yol-Ws-fKc" secondAttribute="leading" id="nRF-sb-GSi"/>
<constraint firstItem="FWv-Br-zeN" firstAttribute="top" secondItem="Yol-Ws-fKc" secondAttribute="bottom" constant="24" id="sOa-Rz-yeJ"/>
<constraint firstItem="OhU-0G-emJ" firstAttribute="centerX" secondItem="8bC-Xf-vdC" secondAttribute="centerX" id="smb-s1-qaM"/>
Expand All @@ -61,11 +71,46 @@
<outlet property="email_input" destination="OhU-0G-emJ" id="dTM-Ny-Aq4"/>
<outlet property="login_button" destination="FWv-Br-zeN" id="Dlg-8g-llq"/>
<outlet property="password_input" destination="Yol-Ws-fKc" id="Opa-cR-l3K"/>
<segue destination="QsI-mm-d63" kind="show" identifier="ShowScanner" id="l2e-BM-Zud"/>
</connections>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="dkx-z0-nzr" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="24.800000000000001" y="36.431784107946029"/>
</scene>
<!--Scan View Controller-->
<scene sceneID="srV-G8-hbK">
<objects>
<viewController id="QsI-mm-d63" customClass="ScanViewController" customModule="HackIllinois__QR" customModuleProvider="target" sceneMemberID="viewController">
<layoutGuides>
<viewControllerLayoutGuide type="top" id="QLM-zq-xI1"/>
<viewControllerLayoutGuide type="bottom" id="R6N-vG-jFR"/>
</layoutGuides>
<view key="view" contentMode="scaleToFill" id="dqU-7c-ajY">
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<imageView userInteractionEnabled="NO" contentMode="scaleToFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" image="hackillinois" translatesAutoresizingMaskIntoConstraints="NO" id="KLH-Jf-Q3Z">
<rect key="frame" x="163" y="40" width="50" height="50"/>
<constraints>
<constraint firstAttribute="height" constant="50" id="PKu-Ws-NiH"/>
<constraint firstAttribute="width" secondItem="KLH-Jf-Q3Z" secondAttribute="height" multiplier="1:1" id="fkY-8w-V7U"/>
</constraints>
</imageView>
</subviews>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<constraints>
<constraint firstItem="KLH-Jf-Q3Z" firstAttribute="top" secondItem="QLM-zq-xI1" secondAttribute="bottom" constant="20" id="EUT-6C-thB"/>
<constraint firstItem="KLH-Jf-Q3Z" firstAttribute="centerX" secondItem="dqU-7c-ajY" secondAttribute="centerX" id="hex-bw-kOc"/>
</constraints>
</view>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="CJd-Uf-4dR" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="848.79999999999995" y="35.532233883058474"/>
</scene>
</scenes>
<resources>
<image name="hackillinois" width="250" height="252"/>
</resources>
</document>
39 changes: 39 additions & 0 deletions HackIllinois: QR/ScanViewController.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
//
// ScanViewController.swift
// HackIllinois: QR
//
// Created by Yasha Mostofi on 2/14/17.
// Copyright © 2017 Yasha Mostofi. All rights reserved.
//

import UIKit
import AVFoundation
import SwiftQRCode
import Alamofire
import Foundation


class ScanViewController: UIViewController {
let scanner = QRCode()

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

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) {
}
}
}
scanner.scanFrame = view.bounds
scanner.startScan()
}
}
91 changes: 48 additions & 43 deletions HackIllinois: QR/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,88 +23,93 @@ class ViewController: UIViewController {
let checksession_url = "https://api.hackillinois.org/v1/auth/reset"
var login_session:String = ""

let scanner = QRCode()

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


/*
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) {
}
}
}
scanner.scanFrame = view.bounds
*/

// email_input.text = "[email protected]"
// password_input.text = "test"

/*
// Uncomment to save auth key between app opens
let preferences = UserDefaults.standard
if preferences.object(forKey: "session") != nil
{
login_session = preferences.object(forKey: "session") as! String
check_session(key: login_session)
scanner.startScan()
}
*/
}

func logIn(email: String, password: String) {
let parameters: Parameters = [
"email": email,
"password": password
]

// Both calls are equivalent
Alamofire.request("https://api.hackillinois.org/v1/auth", method: .post,
parameters: parameters,
encoding: JSONEncoding.default).responseJSON { response in
// print(response.request) // original URL request
// print(response.response) // HTTP URL response
// print(response.data) // server data
// print(response.result) // result of response serialization

if let json = response.result.value {
if let jsonDict = json as? [String: Any] {
if let dataVal = jsonDict["data"] as? [String: Any] {
if let authKey = dataVal["auth"] as? String {
self.login_session = authKey
let preferences = UserDefaults.standard
preferences.set(authKey, forKey: "session")
print(authKey)
self.scanner.startScan()
}
}
}
}
}
let preferences = UserDefaults.standard
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 = [
"email": email,
"password": password
]
Alamofire.request("https://api.hackillinois.org/v1/auth", method: .post,
parameters: parameters,
encoding: JSONEncoding.default).responseJSON { [weak self] response in
if let json = response.result.value {
if let jsonDict = json as? [String: Any] {
if let dataVal = jsonDict["data"] as? [String: Any] {
if let authKey = dataVal["auth"] as? String {
self?.login_session = authKey
let preferences = UserDefaults.standard
preferences.set(authKey, forKey: "session")
// print(authKey)
// self.scanner.startScan()
self?.performSegue(withIdentifier: "ShowScanner", sender: self)
}
}
}
}
}
}
}

func check_session(key: String) {
let parameters: Parameters = [
"Authorization": key
]

// Both calls are equivalent
Alamofire.request("https://api.hackillinois.org/v1/auth/refresh", method: .get,
parameters: parameters,
encoding: JSONEncoding.default).responseJSON { response in
// print(response.request) // original URL request
// print(response.response) // HTTP URL response
// print(response.data) // server data
// print(response.result) // result of response serialization

if let json = response.result.value {
if let jsonDict = json as? [String: Any] {
if let dataVal = jsonDict["data"] as? [String: Any] {
if let authKey = dataVal["auth"] as? String {
self.login_session = authKey
let preferences = UserDefaults.standard
preferences.set(authKey, forKey: "session")
print(authKey)
}
}
}
}
}

}


Expand Down
Binary file added HackIllinois: QR/landing-logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 5014e7f

Please sign in to comment.