Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import UIKit
- import Alamofire
- import AudioToolbox
- class LoginVC: UIViewController {
- //The login script url make sure to write the ip instead of localhost
- //you can get the ip using ifconfig command in terminal
- let URL_USER_LOGIN = "http://39.109.246.10/naruvionline/api/login.php"
- //the defaultvalues to store user data
- let defaultValues = UserDefaults.standard
- @IBOutlet weak var hnum: UITextField!
- @IBOutlet weak var password: UITextField!
- @IBOutlet weak var lblinfo: UILabel!
- @IBAction func login(_ sender: UIButton) {
- let parameters: Parameters=[
- "hnum":Int(hnum.text!)!,
- "password":password.text!
- ]
- Alamofire.request(URL_USER_LOGIN, method: .post, parameters: parameters).responseJSON
- {
- response in
- //printing response
- print(response)
- //getting the json value from the server
- if let result = response.result.value {
- let jsonData = result as! NSDictionary
- if(!(jsonData.value(forKey: "nodata") as! Bool)){
- let user = jsonData.value(forKey: "patient") as! NSDictionary
- let hosnum = user.value(forKey: "hnum") as! Int
- let name = user.value(forKey: "patientname") as! String
- self.defaultValues.set(hosnum, forKey: "hnum")
- self.defaultValues.set(name, forKey: "patientusername")
- let homevc = self.storyboard?.instantiateViewController(withIdentifier: "HomeVC") as! HomeVC
- self.navigationController?.pushViewController(homevc, animated: true)
- self.dismiss(animated: false, completion: nil)
- }
- else
- {
- AudioServicesPlayAlertSound(SystemSoundID(kSystemSoundID_Vibrate))
- self.lblinfo.text = "Invalid username or password"
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement