SHARE
TWEET

Untitled

a guest Sep 5th, 2019 151 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. struct UserInfo: Codable {
  2.     var fullname: String
  3.     var email: String
  4.     var username: String
  5.     var cardNumber: Int
  6. }
  7.  
  8. //pripravime json oject s dotazem na server
  9. let username = "" //sem se musi propsat promena z policka v appce - user
  10. let password = "" //sem se musi propsat promena z policka v appce - pass
  11.  
  12. password = nejakametodasifrovanihesel(password); //rovnou zmenit heslo na hash
  13. let json: [String: Any] = ["user": username, "pass" : password]
  14.  
  15. let jsonData = try? JSONSerialization.data(withJSONObject: json)
  16.  
  17. // create post request
  18. let url = URL(string: "http://www.deegym.com/deeid/api/loginRequest.php")! // tady je adresa ktera vykona request
  19. var request = URLRequest(url: url)
  20. request.httpMethod = "POST"
  21.  
  22. // insert json data to the request
  23. request.httpBody = jsonData
  24.  
  25. let task = URLSession.shared.dataTask(with: request) { data, response, error in
  26.     guard let data = data, error == nil else {
  27.         print(error?.localizedDescription ?? "No data") // Chyba nic se nám nevrátilo = chybný login
  28.         return
  29.     }
  30.     let responseJSON = try? JSONSerialization.jsonObject(with: data, options: [])
  31.     if let responseJSON = responseJSON as? [String: Any] {
  32.         let decoder = JSONDecoder()
  33.     let userInfo = try decoder.decode(UserInfo.self, from: json)
  34.  
  35.     //tady uz budes setovat veci do aplikace a v tehlech promenych mas ulozeny info o uzoivatelich
  36.     userInfo.fullname       //Celé jméno z db
  37.     userInfo.cardNumber     //číslo čipu z DB (deeid)
  38.     userInfo.email          //Klientův email
  39.  
  40.     }
  41. }
  42.  
  43. task.resume()
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top