Advertisement
Guest User

Untitled

a guest
Jul 10th, 2017
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.91 KB | None | 0 0
  1. import UIKit
  2. import Alamofire
  3. import AudioToolbox
  4.  
  5.  
  6. class LoginVC: UIViewController {
  7.  
  8. //The login script url make sure to write the ip instead of localhost
  9. //you can get the ip using ifconfig command in terminal
  10. let URL_USER_LOGIN = "http://39.109.246.10/naruvionline/api/login.php"
  11.  
  12. //the defaultvalues to store user data
  13. let defaultValues = UserDefaults.standard
  14.  
  15. @IBOutlet weak var hnum: UITextField!
  16.  
  17. @IBOutlet weak var password: UITextField!
  18.  
  19. @IBOutlet weak var lblinfo: UILabel!
  20.  
  21. @IBAction func login(_ sender: UIButton) {
  22.  
  23. let parameters: Parameters=[
  24. "hnum":Int(hnum.text!)!,
  25. "password":password.text!
  26. ]
  27.  
  28. Alamofire.request(URL_USER_LOGIN, method: .post, parameters: parameters).responseJSON
  29. {
  30. response in
  31. //printing response
  32. print(response)
  33.  
  34. //getting the json value from the server
  35. if let result = response.result.value {
  36. let jsonData = result as! NSDictionary
  37.  
  38. if(!(jsonData.value(forKey: "nodata") as! Bool)){
  39. let user = jsonData.value(forKey: "patient") as! NSDictionary
  40. let hosnum = user.value(forKey: "hnum") as! Int
  41. let name = user.value(forKey: "patientname") as! String
  42.  
  43.  
  44. self.defaultValues.set(hosnum, forKey: "hnum")
  45. self.defaultValues.set(name, forKey: "patientusername")
  46.  
  47.  
  48. let homevc = self.storyboard?.instantiateViewController(withIdentifier: "HomeVC") as! HomeVC
  49. self.navigationController?.pushViewController(homevc, animated: true)
  50. self.dismiss(animated: false, completion: nil)
  51. }
  52.  
  53. else
  54. {
  55. AudioServicesPlayAlertSound(SystemSoundID(kSystemSoundID_Vibrate))
  56. self.lblinfo.text = "Invalid username or password"
  57.  
  58. }
  59.  
  60. }
  61.  
  62. }
  63.  
  64.  
  65.  
  66.  
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement