Advertisement
tborg

checkLogin

Apr 21st, 2015
203
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.40 KB | None | 0 0
  1.     private void checkLogin(final String email, final String password) {
  2.         // Tag used to cancel the request
  3.         String tag_string_req = "req_login";
  4.  
  5.         pDialog.setMessage("Logging in ...");
  6.         showDialog();
  7.  
  8.         StringRequest strReq = new StringRequest(Method.POST,
  9.                 com.example.thomas.taken.app.AppConfig.URL_REGISTER, new Response.Listener<String>() {
  10.  
  11.             @Override
  12.             public void onResponse(String response) {
  13.                 Log.d(TAG, "Login Response: " + response.toString());
  14.                 hideDialog();
  15.  
  16.                 try {
  17.                     JSONObject jObj = new JSONObject(response);
  18.                     boolean error = jObj.getBoolean("error");
  19.  
  20.                     // Check for error node in json
  21.                     if (!error) {
  22.                       // Launch main activity
  23.                         Intent intent = new Intent(LoginActivity.this,
  24.                                 MainActivity.class);
  25.                         startActivity(intent);
  26.                         finish();
  27.                     } else {
  28.                         // Error in login. Get the error message
  29.                         String errorMsg = jObj.getString("error_msg");
  30.                         Toast.makeText(getApplicationContext(),
  31.                                 errorMsg, Toast.LENGTH_LONG).show();
  32.                     }
  33.                 }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement