@Override protected Void doInBackground(String... uid) { String hostUrl = "http://192.241.211.104/~proposal/api/index.php/user?a=a"; List<NameValuePair> params = new ArrayList<NameValuePair>(); params.add(new BasicNameValuePair("id", uid[0])); JSONParser jsonParser = new JSONParser(getApplicationContext()); JSONObject json = jsonParser.httpRequestRest(hostUrl, "GET", params); if (json == null) { Log.e("JSONObject Get User Information have problem", ""); success = false; httpReponseCode = jsonParser.getHttpResponseCode(); return null; } success = true; httpReponseCode = jsonParser.getHttpResponseCode(); try { phoneNumber = json.getString("uPhone"); phoneNumber = phoneNumber.replace("886", "0"); original_email = json.getString("uEmail"); original_nickname = json.getString("uNickName"); original_genderCode = Integer.parseInt(json.getString("uGender")); } catch (JSONException e) { e.printStackTrace(); } return null; }
@Override protected Void doInBackground(String... pass) { String newer_email = "", newer_nickName = "", newer_gender = ""; String hostUrl = "http://192.241.211.104/~proposal/api/index.php/user/update"; String hostUrlPw = "http://192.241.211.104/~proposal/api/index.php/user/change_pw"; if (mode == MODE_UPDATE) { newer_email = edt_email.getText().toString(); newer_nickName = edt_nickName.getText().toString(); newer_gender = String.valueOf(gender); List<NameValuePair> params = new ArrayList<NameValuePair>(); params.add(new BasicNameValuePair("id", uID)); params.add(new BasicNameValuePair("password", pass[0])); params.add(new BasicNameValuePair("nickname", newer_nickName)); params.add(new BasicNameValuePair("mail", newer_email)); params.add(new BasicNameValuePair("gender", newer_gender)); JSONParser jsonParser = new JSONParser(getApplicationContext()); JSONObject json = jsonParser.httpRequestRest(hostUrl, "POST", params); if (json == null) { Log.e("Error when Updating user information.", ""); httpResponseCode = jsonParser.getHttpResponseCode(); success = false; return null; } httpResponseCode = jsonParser.getHttpResponseCode(); success = true; userFunctions = new UserFunctions(getApplicationContext()); userFunctions.logoutUser(getApplicationContext()); // 清除本機資料 // 寫入SQLite DatabaseHandler db = new DatabaseHandler(getApplicationContext()); try { db.addUser( json.getString("uNickName"), json.getString("uEmail"), uID, json.getString("uPhone")); } catch (JSONException e) { e.printStackTrace(); } } else if (mode == MODE_NEWPASSWORD) { String newPassword = ""; newPassword = edt_newPassword.getText().toString(); List<NameValuePair> params = new ArrayList<NameValuePair>(); params.add(new BasicNameValuePair("id", uID)); params.add(new BasicNameValuePair("password", pass[0])); params.add(new BasicNameValuePair("new_password", newPassword)); JSONParser jsonParser = new JSONParser(getApplicationContext()); JSONObject json = jsonParser.httpRequestRest(hostUrlPw, "POST", params); if (json == null) { Log.e("Error when Updating user password", ""); httpResponseCode = jsonParser.getHttpResponseCode(); success = false; return null; } httpResponseCode = jsonParser.getHttpResponseCode(); success = true; } return null; }