diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e43b0f9 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.DS_Store diff --git a/HackIllinois: QR.xcworkspace/xcuserdata/ymostofi.xcuserdatad/UserInterfaceState.xcuserstate b/HackIllinois: QR.xcworkspace/xcuserdata/ymostofi.xcuserdatad/UserInterfaceState.xcuserstate index 9d576d1..816f6f2 100644 Binary files a/HackIllinois: QR.xcworkspace/xcuserdata/ymostofi.xcuserdatad/UserInterfaceState.xcuserstate and b/HackIllinois: QR.xcworkspace/xcuserdata/ymostofi.xcuserdatad/UserInterfaceState.xcuserstate differ diff --git a/HackIllinois: QR/AddViewController.swift b/HackIllinois: QR/AddViewController.swift index a2435bb..9cced8e 100644 --- a/HackIllinois: QR/AddViewController.swift +++ b/HackIllinois: QR/AddViewController.swift @@ -7,37 +7,52 @@ // import UIKit +import Alamofire +import SwiftyJSON class AddViewController: BaseViewController { - + @IBOutlet var nameField: UITextField! + @IBOutlet var durationField: UITextField! override func viewDidLoad() { super.viewDidLoad() - - // Do any additional setup after loading the view. - } - - override func didReceiveMemoryWarning() { - super.didReceiveMemoryWarning() - // Dispose of any resources that can be recreated. + let preferences = UserDefaults.standard + if preferences.object(forKey: "session") != nil + { + self.login_session = preferences.object(forKey: "session") as! String + } } - - - /* - // MARK: - Navigation - - // In a storyboard-based application, you will often want to do a little preparation before navigation - override func prepare(for segue: UIStoryboardSegue, sender: Any?) { - // Get the new view controller using segue.destinationViewController. - // Pass the selected object to the new view controller. - } - */ - + @IBAction func cancelButton(_ sender: Any) { print("cancel") self.dismiss(animated: true, completion: nil) } @IBAction func saveButton(_ sender: Any) { print("save") - self.dismiss(animated: true, completion: nil) + let role = self.check_permissions(key: self.login_session) + print(role) + if role != "ADMIN" { + self.dismiss(animated: true) + return + } + let headers: HTTPHeaders = [ + "Authorization": self.login_session + ] + let parameters: Parameters = [ + "name": nameField.text!, + "duration": durationField.text! + ] + print(parameters) + Alamofire.request("https://api.hackillinois.org/v1/tracking", method: .post, + parameters: parameters, encoding: JSONEncoding.default, + headers: headers).validate().responseJSON { [weak self] response in + print(response) + switch response.result { + case .success: + self?.dismiss(animated: true) + case .failure: +// self?.displayAlert(title: "ERROR!", message: "Could not create new event") + self?.dismiss(animated: true) + } + } } } diff --git a/HackIllinois: QR/Base.lproj/Main.storyboard b/HackIllinois: QR/Base.lproj/Main.storyboard index 0bff3d3..8a186a6 100644 --- a/HackIllinois: QR/Base.lproj/Main.storyboard +++ b/HackIllinois: QR/Base.lproj/Main.storyboard @@ -1,5 +1,5 @@ - + @@ -116,7 +116,7 @@ - + @@ -127,9 +127,33 @@ + + + + + + + + + + + + + + + + + + + + + + + + - + @@ -141,6 +165,10 @@ + + + +