Advertisement
Guest User

Untitled

a guest
Feb 6th, 2017
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.34 KB | None | 0 0
  1. func sendLoginRequest(userName:String,password:String){
  2. let parameters = ["username":userName,
  3. "password":password,
  4. "client_id": clientID,
  5. "client_secret": clientSecret,
  6. "grant_type":"password"]
  7. HUD.show(.progress)
  8. let api = RCValues.sharedInstance.string(forKey: .apiOuvidor)
  9. Alamofire.request(api+"auth-social/token/", method: .post, parameters: parameters).responseJSON { (response) in
  10. HUD.hide()
  11. if response.result.error == nil{
  12. debugPrint(response.result.value!)
  13. let responseJSON = response.result.value as! [String:AnyObject]
  14. if let token = responseJSON["access_token"] as? String{
  15. self.saveTokenOnLoginSucceed(token)
  16. }else{
  17. let alert = UIAlertController(title: nil, message: "Login ou senha inválidos.", preferredStyle: .alert)
  18. let action = UIAlertAction(title: "OK", style: .cancel, handler: nil)
  19. alert.addAction(action)
  20. self.present(alert, animated: true, completion: nil)
  21. }
  22. }else{
  23. self.showErrorAlertView()
  24. debugPrint(response.result.error as Any)
  25. }
  26. }
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement