Advertisement
Guest User

Untitled

a guest
Jul 31st, 2014
201
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.46 KB | None | 0 0
  1. public void LoginUser(){
  2.  
  3. // Tag used to cancel the request
  4. String tag_json_obj = "json_obj_req";
  5.  
  6. String url = "http://example.com/myfile/mobile_api/";
  7.  
  8. //final ProgressDialog pDialog = ProgressDialog.show(getParent(), "Please wait", "Login user");
  9.  
  10.  
  11. JsonObjectRequest jsonObjReq = new JsonObjectRequest(Method.GET,
  12. url, null,
  13. new Response.Listener<JSONObject>() {
  14.  
  15. @Override
  16. public void onResponse(JSONObject response) {
  17. try {
  18. if(response.getString(KEY_SUCCESS)!=null){
  19.  
  20. String res = response.getString(KEY_SUCCESS);
  21.  
  22. if(Integer.parseInt(res) == 1){
  23. JSONObject json_user = response.getJSONObject("user");
  24. Toast.makeText(getApplicationContext(), "User Logged in.. " + json_user.getString("name"), Toast.LENGTH_LONG).show();
  25. }
  26. }
  27. else if(response.getString(KEY_ERROR)!=null){
  28.  
  29. String res = response.getString(KEY_ERROR);
  30.  
  31. if(Integer.parseInt(res) == 1){
  32. Toast.makeText(getApplicationContext(), response.getString("error_msg"), Toast.LENGTH_LONG).show();
  33. }
  34. }
  35.  
  36. } catch (JSONException e) {
  37. // TODO Auto-generated catch block
  38. e.printStackTrace();
  39. //pDialog.hide();
  40. }
  41. Log.d(TAG, response.toString());
  42. //pDialog.hide();
  43. }
  44. }, new Response.ErrorListener() {
  45.  
  46. @Override
  47. public void onErrorResponse(VolleyError error) {
  48. VolleyLog.d(TAG, "Error: " + error.getMessage());
  49. Log.d(TAG, "Error: " + error.getMessage());
  50. //pDialog.hide();
  51. }
  52. }) {
  53.  
  54. @Override
  55. protected Map<String, String> getParams() {
  56. Map<String, String> params = new HashMap<String, String>();
  57. params.put("tag", login_tag);
  58. params.put("email", Email);
  59. params.put("password", Pass);
  60.  
  61. return params;
  62. }
  63.  
  64. };
  65.  
  66. // Adding request to request queue
  67. AppController.getInstance().addToRequestQueue(jsonObjReq, tag_json_obj);
  68. }
  69.  
  70. if ($tag == 'login') {
  71.  
  72. $email = $_POST['email'];
  73. $password = $_POST['password'];
  74.  
  75.  
  76. $user = $db->getUserByEmailAndPassword($email, $password);
  77. if ($user != false) {
  78.  
  79. $response["success"] = 1;
  80. $response["uid"] = $user["id"];
  81. $response["user"]["name"] = $user["name"];
  82. $response["user"]["phone"] = $user["contact_no"];
  83. $response["user"]["email"] = $user["email"];
  84. $response["user"]["reg_date"] = $user["reg_date"];
  85. echo json_encode($response);
  86. } else {
  87.  
  88. $response["error"] = 1;
  89. $response["error_msg"] = "Incorrect email or password!";
  90. echo json_encode($response);
  91. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement