Advertisement
Guest User

Untitled

a guest
Aug 10th, 2016
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.57 KB | None | 0 0
  1. private void registerUser(final String name, final String password, final String Repassword) {
  2. // Tag used to cancel the request
  3. String tag_string_req = "req_register";
  4.  
  5. pDialog.setMessage("Registering ...");
  6. showDialog();
  7.  
  8. StringRequest strReq = new StringRequest(Request.Method.POST,
  9. AppConfig.URL_REGISTER, new Response.Listener<String>() {
  10.  
  11. @Override
  12. public void onResponse(String response) {
  13. Log.d(TAG, "Register Response: " + response.toString());
  14. hideDialog();
  15.  
  16. try {
  17.  
  18. JSONObject jObj = new JSONObject(response);
  19.  
  20. //JSONArray jare = new JSONArray(response);
  21.  
  22. //Log.d(TAG,"iki datane "+jare);
  23. // boolean error = jsonArray.getBoolean(1);
  24. // if (!error) {
  25. // User successfully stored in MySQL
  26. // Now store the user in sqlite
  27. JSONObject Data = jObj.getJSONObject("data");
  28.  
  29.  
  30. String username = Data.getString("username");
  31. String password = Data.getString("password");
  32. String token = Data.getString("token");
  33. String join_date = Data.getString("join_date");
  34.  
  35. Toast.makeText(getApplicationContext(), "User successfully registered. Try login now!", Toast.LENGTH_LONG).show();
  36. //int status = jObj.getInt("status");
  37. //Log.d(TAG,"iki jObj "+username);
  38.  
  39. /*if(status == 1){
  40. Toast.makeText(getApplicationContext(), "User successfully registered. Try login now!", Toast.LENGTH_LONG).show();
  41. }
  42. else{
  43. Toast.makeText(getApplicationContext(), "User not registered. Try Register Again!", Toast.LENGTH_LONG).show();
  44. }*/
  45.  
  46. // db.addUser(username, password, token, join_date);
  47. //} else {
  48. // Error occurred in registration. Get the error
  49. // message
  50. //String errorMsg = jObj.getString("error_msg");
  51. //Toast.makeText(getApplicationContext(), errorMsg, Toast.LENGTH_LONG).show();
  52. // }
  53. } catch (JSONException e) {
  54. //e.printStackTrace();
  55. Toast.makeText(getApplicationContext(), "Registration Error", Toast.LENGTH_LONG).show();
  56. //Log.d(TAG,"Eroor JSON"+e.getMessage());
  57. }
  58.  
  59. }
  60. }, new Response.ErrorListener() {
  61.  
  62. @Override
  63. public void onErrorResponse(VolleyError error) {
  64. Log.e(TAG, "Registration Error: " + error.getMessage());
  65. Toast.makeText(getApplicationContext(), error.getMessage(), Toast.LENGTH_LONG).show();
  66. hideDialog();
  67. }
  68. }) {
  69.  
  70. @Override
  71. protected Map<String, String> getParams() {
  72. // Posting params to register url
  73. Map<String, String> params = new HashMap<String, String>();
  74. params.put("user_name", name);
  75. params.put("pass_name", password);
  76. params.put("re_pass_name", Repassword);
  77.  
  78. return params;
  79. }
  80.  
  81. };
  82.  
  83. // Adding request to request queue
  84. AppController.getInstance().addToRequestQueue(strReq, tag_string_req);
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement