Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- // LoginViewController.swift
- // AeroBuddy
- //
- // Created by Luke Collister on 28/09/2019.
- // Copyright © 2019 Luke Collister. All rights reserved.
- //
- import UIKit
- class LoginViewController: UIViewController {
- @IBOutlet var email_input: UITextField!
- @IBOutlet var password_input: UITextField!
- @IBAction func login(_ sender: UIButton) {
- let username = email_input!.text
- let password = password_input!.text
- let credential = URLCredential(user: username!, password: password!, persistence: .permanent)
- let protectionSpace = URLProtectionSpace(host: "fe01.kilosierracharlie.me", port: 80, protocol: "http", realm: "Secured Area", authenticationMethod: NSURLAuthenticationMethodHTTPBasic)
- URLCredentialStorage.shared.setDefaultCredential(credential, for: protectionSpace)
- let config = URLSessionConfiguration.default
- let session = URLSession(configuration: config)
- let url = URL(string: "http://fe01.kilosierracharlie.me/user/")!
- let task = session.dataTask(with: url) { (data, response, error) in
- guard error == nil else {
- print(error?.localizedDescription ?? "")
- return
- }
- if let httpStatus = response as? HTTPURLResponse {
- // check status code returned by the http server
- print("status code = \(httpStatus.statusCode)")
- // process result
- if httpStatus.statusCode == 200 {
- }
- }
- }
- task.resume()
- }
- }
Add Comment
Please, Sign In to add comment