For Login Validation
email = edit_useremail.getText().toString();
pass = edit_password.getText().toString();
if (email.equals("")) {
edit_useremail.setError("Please enter Email!");
edit_useremail.requestFocus();
} else if (!android.util.Patterns.EMAIL_ADDRESS.matcher(edit_useremail.getText().toString()).matches()) {
edit_useremail.setError("Please enter valid Email");
edit_useremail.requestFocus();
return;
} else if (pass.equals("")) {
txtForgetPass.setError("Please enter Password!");
txtForgetPass.requestFocus();
}
/* else if (!checkBoxRememberMe.isChecked()) { checkBoxRememberMe.setError("Please select Box!");} */
else {
final ProgressDialog pd = new ProgressDialog(LoginActivity.this);
pd.setMessage("Loading...");
pd.show();
JSONObject jsonObject = new JSONObject();
try {
jsonObject.put("email", email);
jsonObject.put("password", pass);
} catch (JSONException e) {
e.printStackTrace();
}
JsonObjectRequest jsonObjReq = new JsonObjectRequest(Request.Method.POST,
USERLOGIN, jsonObject, new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
try {
String status = response.getString("status");
String message = response.getString("message");
if (status.equals("true")) {
manager.setPreferences(LoginActivity.this, "statuslogin", "1");
String statuslogin = manager.getPreferences(LoginActivity.this, "status");
Intent intent = new Intent(getApplicationContext(), MainActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
finish();
} else {
Toast.makeText(getApplicationContext(), message, Toast.LENGTH_LONG).show();
}
Toast.makeText(LoginActivity.this, message, Toast.LENGTH_LONG).show();
JSONObject data = response.getJSONObject("data");
SharedPreferences.Editor editor = preferences.edit();
editor.putString("auth_token", data.getString("auth_token"));
editor.putString("username", data.getString("username"));
editor.commit();
} catch (JSONException e) {
e.printStackTrace();
}
pd.dismiss();
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Toast.makeText(getApplicationContext(),
error.getMessage(), Toast.LENGTH_LONG).show();
pd.dismiss();
}
})
{
@Override
public Map<String, String> getHeaders() throws AuthFailureError {
Map<String, String> params = new HashMap<String, String>();
params.put("Csrf-Token", "default11");
return params;
}
};
RequestQueue requestQueue = Volley.newRequestQueue(this);
requestQueue.add(jsonObjReq);
}
No comments:
Post a Comment