lcolli98

Untitled

Nov 12th, 2019
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.60 KB | None | 0 0
  1. //
  2. // LoginViewController.swift
  3. // AeroBuddy
  4. //
  5. // Created by Luke Collister on 28/09/2019.
  6. // Copyright © 2019 Luke Collister. All rights reserved.
  7. //
  8.  
  9.  
  10. import UIKit
  11.  
  12. class LoginViewController: UIViewController {
  13.  
  14. @IBOutlet var email_input: UITextField!
  15. @IBOutlet var password_input: UITextField!
  16.  
  17. @IBAction func login(_ sender: UIButton) {
  18.  
  19. let username = email_input!.text
  20. let password = password_input!.text
  21. let credential = URLCredential(user: username!, password: password!, persistence: .permanent)
  22. let protectionSpace = URLProtectionSpace(host: "fe01.kilosierracharlie.me", port: 80, protocol: "http", realm: "Secured Area", authenticationMethod: NSURLAuthenticationMethodHTTPBasic)
  23. URLCredentialStorage.shared.setDefaultCredential(credential, for: protectionSpace)
  24.  
  25. let config = URLSessionConfiguration.default
  26. let session = URLSession(configuration: config)
  27.  
  28. let url = URL(string: "http://fe01.kilosierracharlie.me/user/")!
  29.  
  30. let task = session.dataTask(with: url) { (data, response, error) in
  31. guard error == nil else {
  32. print(error?.localizedDescription ?? "")
  33. return
  34. }
  35.  
  36. if let httpStatus = response as? HTTPURLResponse {
  37. // check status code returned by the http server
  38. print("status code = \(httpStatus.statusCode)")
  39. // process result
  40. if httpStatus.statusCode == 200 {
  41.  
  42. }
  43. }
  44. }
  45. task.resume()
  46.  
  47. }
  48. }
Add Comment
Please, Sign In to add comment