Advertisement
Guest User

Untitled

a guest
Mar 21st, 2016
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.34 KB | None | 0 0
  1. public void registerUser(final String username, final String email, final String password) {
  2. pDialog.setMessage("Signing Up...");
  3. pDialog.show();
  4.  
  5. request = new StringRequest(Method.POST, SL_URL, new Response.Listener<String>() {
  6. @Override
  7. public void onResponse(String s) {
  8. pDialog.dismiss();
  9. String[] split = s.split("Config.php");
  10. String after = split[1];
  11. try {
  12. JSONObject jsonObject = new JSONObject(after);
  13. boolean error = jsonObject.getBoolean("error");
  14. if (error) {
  15. String errorMsg = jsonObject.getString("error_msg");
  16. Toast.makeText(getApplicationContext(),
  17. errorMsg, Toast.LENGTH_LONG).show();
  18.  
  19. } else {
  20. session.setLogin(true, username, email);
  21. }
  22. } catch (JSONException e) {
  23. e.printStackTrace();
  24. }
  25. }
  26. }) {
  27. @Override
  28. protected Map<String, String> getParams() throws AuthFailureError {
  29. HashMap<String, String> hashMap = new HashMap<>();
  30. hashMap.put("tag", "login");
  31. hashMap.put("username", name);
  32. hashMap.put("password", password);
  33. return hashMap;
  34. }
  35. };
  36. queue.add(request);
  37. }
  38.  
  39. let username = usernameTxt.text
  40. let password = passwordTxt.text
  41. let urlPath: String = "***"
  42. let url: NSURL = NSURL(string: urlPath)!
  43. let request1: NSMutableURLRequest = NSMutableURLRequest(URL: url)
  44.  
  45. request1.HTTPMethod = "POST"
  46. let stringPost="tag=login&username=" + username! + "&password=" + password! // Key and Value
  47. NSLog(stringPost)
  48. let data = stringPost.dataUsingEncoding(NSUTF8StringEncoding)
  49.  
  50. request1.timeoutInterval = 60
  51. request1.HTTPBody=data
  52. request1.HTTPShouldHandleCookies=false
  53.  
  54. let queue:NSOperationQueue = NSOperationQueue()
  55.  
  56. NSURLConnection.sendAsynchronousRequest(request1, queue: queue, completionHandler:{ (response: NSURLResponse?, data: NSData?, error: NSError?) -> Void in
  57. do {
  58. var jsonResult: NSDictionary = try NSJSONSerialization.JSONObjectWithData(data!, options: NSJSONReadingOptions.MutableContainers) as! NSDictionary
  59. } catch _ {}
  60.  
  61. })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement