Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public void LoginUser(){
- // Tag used to cancel the request
- String tag_json_obj = "json_obj_req";
- String url = "http://example.com/myfile/mobile_api/";
- //final ProgressDialog pDialog = ProgressDialog.show(getParent(), "Please wait", "Login user");
- JsonObjectRequest jsonObjReq = new JsonObjectRequest(Method.GET,
- url, null,
- new Response.Listener<JSONObject>() {
- @Override
- public void onResponse(JSONObject response) {
- try {
- if(response.getString(KEY_SUCCESS)!=null){
- String res = response.getString(KEY_SUCCESS);
- if(Integer.parseInt(res) == 1){
- JSONObject json_user = response.getJSONObject("user");
- Toast.makeText(getApplicationContext(), "User Logged in.. " + json_user.getString("name"), Toast.LENGTH_LONG).show();
- }
- }
- else if(response.getString(KEY_ERROR)!=null){
- String res = response.getString(KEY_ERROR);
- if(Integer.parseInt(res) == 1){
- Toast.makeText(getApplicationContext(), response.getString("error_msg"), Toast.LENGTH_LONG).show();
- }
- }
- } catch (JSONException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- //pDialog.hide();
- }
- Log.d(TAG, response.toString());
- //pDialog.hide();
- }
- }, new Response.ErrorListener() {
- @Override
- public void onErrorResponse(VolleyError error) {
- VolleyLog.d(TAG, "Error: " + error.getMessage());
- Log.d(TAG, "Error: " + error.getMessage());
- //pDialog.hide();
- }
- }) {
- @Override
- protected Map<String, String> getParams() {
- Map<String, String> params = new HashMap<String, String>();
- params.put("tag", login_tag);
- params.put("email", Email);
- params.put("password", Pass);
- return params;
- }
- };
- // Adding request to request queue
- AppController.getInstance().addToRequestQueue(jsonObjReq, tag_json_obj);
- }
- if ($tag == 'login') {
- $email = $_POST['email'];
- $password = $_POST['password'];
- $user = $db->getUserByEmailAndPassword($email, $password);
- if ($user != false) {
- $response["success"] = 1;
- $response["uid"] = $user["id"];
- $response["user"]["name"] = $user["name"];
- $response["user"]["phone"] = $user["contact_no"];
- $response["user"]["email"] = $user["email"];
- $response["user"]["reg_date"] = $user["reg_date"];
- echo json_encode($response);
- } else {
- $response["error"] = 1;
- $response["error_msg"] = "Incorrect email or password!";
- echo json_encode($response);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement