Advertisement
NgThanhPhuc

Untitled

Sep 7th, 2017
184
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.14 KB | None | 0 0
  1.         Alamofire.request(Api.AuthToken, method: .post, parameters:params, encoding: JSONEncoding.default, headers: nil).responseJSON { response in
  2.             if let value: Any = response.result.value {
  3.                 //Handle the results as JSON
  4.                 let post = JSON(value)
  5.                 if let token = post["token"].string {
  6.                     //At this point the user should have authenticated, store the session id and use it as you wish
  7.                    
  8.                     let userInfo = ["email": withUsername, "password": password]
  9.                     UserDefaults.standard.set(userInfo, forKey: "userInformation")
  10.                     UserDefaults.standard.set(token, forKey: "token")
  11.                    
  12.                     print(token)
  13.                     self.getProfile(token, completion: { (status) in
  14.                         if(status){
  15.                             completion(true)
  16.                         }else{
  17.                             completion(false)
  18.                         }
  19.                     })
  20.                 } else {
  21.                     completion(false)
  22.                 }
  23.             }
  24.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement