Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- org.json.JSONException: Value <br of type java.lang.String cannot be converted to JSONObject
- require_once 'include/DB_Functions.php';
- $db = new DB_Functions();
- // json response array
- $response = array("error" => FALSE);
- if (isset($_POST['email']) && isset($_POST['password'])) {
- // receiving the post params
- $email = $_POST['email'];
- $password = $_POST['password'];
- // get the user by email and password
- $user = $db->getUserByEmailAndPassword($email, $password);
- if ($user != false) {
- // use is found
- $response["error"] = FALSE;
- $response["uid"] = $user["unique_id"];
- $response["user"]["name"] = $user["name"];
- $response["user"]["cognome"] = $user["cognome"];
- $response["user"]["email"] = $user["email"];
- $response["user"]["email2"] = $user["email2"];
- $response["user"]["numero_appartamento"] = $user["numero_appartamento"];
- $response["user"]["nome_edificio"] = $user["nome_edificio"];
- $response["user"]["zona_metropolitana"] = $user["zona_metropolitana"];
- $response["user"]["created_at"] = $user["created_at"];
- $response["user"]["updated_at"] = $user["updated_at"];
- echo json_encode($response);
- } else {
- // user is not found with the credentials
- $response["error"] = TRUE;
- $response["error_msg"] = "Login credentials are wrong. Please try again!";
- echo json_encode($response);
- }
- } else {
- // required post params is missing
- $response["error"] = TRUE;
- $response["error_msg"] = "Required parameters email or password is missing!";
- echo json_encode($response);
- }
- ?>
- private void checkLogin(final String email, final String password) {
- // Tag used to cancel the request
- String tag_string_req = "req_login";
- pDialog.setMessage("Logging in ...");
- showDialog();
- StringRequest strReq = new StringRequest(Method.POST,
- AppConfig.URL_LOGIN, new Response.Listener<String>() {
- @Override
- public void onResponse(String response) {
- Log.d(TAG, "Login Response: " + response.toString());
- hideDialog();
- try {
- JSONObject jObj = new JSONObject(response);
- boolean error = jObj.getBoolean("error");
- // Check for error node in json
- if (!error) {
- // user successfully logged in
- // Create login session
- session.setLogin(true);
- // Now store the user in SQLite
- String uid = jObj.getString("uid");
- JSONObject user = jObj.getJSONObject("user");
- String name = user.getString("name");
- String cognome = user.getString("cognome");
- String email = user.getString("email");
- String email2 = user.getString("email2");
- String numero_appartamento = user.getString("numero_appartamento");
- String nome_edificio = user.getString("nome_edificio");
- String zona_metropolitana = user.getString("zona_metropolitana");
- String created_at = user
- .getString("created_at");
- // Inserting row in users table
- db.addUser(name,cognome, email,email2,numero_appartamento,nome_edificio,zona_metropolitana,uid, created_at);
- // Launch main activity
- Intent intent = new Intent(LoginActivity.this,
- // MainActivity.class);
- ScrollableTabsActivity.class);
- startActivity(intent);
- finish();
- } else {
- // Error in login. Get the error message
- String errorMsg = jObj.getString("error_msg");
- Toast.makeText(getApplicationContext(),
- errorMsg, Toast.LENGTH_LONG).show();
- }
- } catch (JSONException e) {
- // JSON error
- e.printStackTrace();
- Toast.makeText(getApplicationContext(), "Json error: " + e.getMessage(), Toast.LENGTH_LONG).show();
- }
- }
- }, new Response.ErrorListener() {
- @Override
- public void onErrorResponse(VolleyError error) {
- Log.e(TAG, "Login Error: " + error.getMessage());
- Toast.makeText(getApplicationContext(),
- error.getMessage(), Toast.LENGTH_LONG).show();
- hideDialog();
- }
- }) {
- @Override
- protected Map<String, String> getParams() {
- // Posting parameters to login url
- Map<String, String> params = new HashMap<String, String>();
- params.put("email", email);
- params.put("password", password);
- System.out.println(params);
- return params;
- }
- };
- // Adding request to request queue
- AppController.getInstance().addToRequestQueue(strReq, tag_string_req);
- }
- JSONObject jObj = new JSONObject(response);
- AppConfig.URL_LOGIN, new Response.Listener<String>()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement