Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @IBAction func accediButton(_ sender: UIButton!) {
- guard let usname = userText.text,
- let pasw = passText.text else {return}
- DownloadManager.shared.downloadUtenteJSON(url: "http://pippo.it/ws/wspippo.ashx", nomU: usname, pawU: pasw)
- let user = DataManager.shared.emaute
- let pass = DataManager.shared.pawute
- if user.isEmpty == true || pass.isEmpty == true {
- let myAlert = UIAlertController(title: "Attenzione",
- message: "Digitare le credenziali!",
- preferredStyle: .alert)
- myAlert.addAction(UIAlertAction(title: "Ok", style: .cancel, handler: nil))
- present(myAlert, animated: true, completion: nil)
- return
- }
- }
- func downloadUtenteJSON(url : String, nomU : String, pawU : String ) {
- request(url, method: .get).responseJSON { response in
- print("sono nel request")
- if let er = response.result.error {
- print("ERRORE:")
- print(er.localizedDescription)
- }
- guard let ilJson = response.result.value else {
- print("JSON Nil")
- return
- }
- guard let json = JSON(ilJson).array else { return }
- let totale = json.count
- var selezioneN:Bool = false
- var selezioneP:Bool = false
- for i in 0..<totale {
- if let uteEma = json[i]["EmailUtente"].string {
- if nomU == uteEma && selezioneN != true {
- selezioneN = true
- print("ok")
- }
- }
- if let utePaw = json[i]["PasswordUtente"].string {
- if pawU == utePaw && selezioneP != true {
- selezioneP = true
- print("ok2")
- }
- }
- if selezioneN == true && selezioneP == true {
- print("ok3")
- if let uteCod = json[i]["CodUtente"].int {
- DataManager.shared.codute = uteCod
- }
- if let uteNom = json[i]["NomeUtente"].string {
- DataManager.shared.nomute = uteNom
- }
- if let uteCog = json[i]["CognomeUtente"].string {
- DataManager.shared.cogute = uteCog
- }
- if let uteEma = json[i]["EmailUtente"].string {
- DataManager.shared.emaute = uteEma
- }
- if let utePaw = json[i]["PasswordUtente"].string {
- DataManager.shared.pawute = utePaw
- }
- selezioneN = false
- selezioneP = false
- break
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement