Advertisement
Guest User

Untitled

a guest
Nov 11th, 2017
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.08 KB | None | 0 0
  1. package com.kismec.kismecapp1;
  2.  
  3. import android.app.Activity;
  4. import android.app.ProgressDialog;
  5. import android.content.Context;
  6. import android.content.Intent;
  7. import android.content.SharedPreferences;
  8. import android.net.Uri;
  9. import android.os.AsyncTask;
  10. import android.support.annotation.NonNull;
  11. import android.util.Log;
  12. import android.view.LayoutInflater;
  13. import android.view.View;
  14. import android.view.ViewGroup;
  15. import android.widget.ArrayAdapter;
  16. import android.widget.Button;
  17. import android.widget.TextView;
  18. import android.widget.Toast;
  19.  
  20. import org.json.JSONException;
  21. import org.json.JSONObject;
  22.  
  23. import java.util.ArrayList;
  24.  
  25. /**
  26. * Created by selva on 11/11/2017.
  27. */
  28.  
  29. public class rowlayoutadapter extends ArrayAdapter<users>
  30. {
  31. private ProgressDialog pDialog;
  32. JSONParser jsonParser = new JSONParser();
  33. private static final String url_login = "http://172.16.140.100/ukm/resetuser.php";
  34. private final Context context;
  35. private final ArrayList<users> users_list;
  36.  
  37. public rowlayoutadapter(@NonNull Context context, ArrayList<users> users_list)
  38. {
  39. super(context, R.layout.rowlayout,users_list);
  40. this.context=context;
  41. this.users_list=users_list;
  42. }
  43. public View getView(int position, View convertview, ViewGroup parent)
  44. {
  45. LayoutInflater inflater = (LayoutInflater) context
  46. .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
  47. View rowView = inflater.inflate(R.layout.rowlayout, parent, false);
  48. final TextView tfullname = (TextView) rowView.findViewById(R.id.tfullname);
  49. final TextView tusername = (TextView) rowView.findViewById(R.id.tusername);
  50. users obj=users_list.get(position);
  51. tfullname.setText(obj.fullname);
  52. tusername.setText(obj.username);
  53. Button btnreset=(Button)rowView.findViewById(R.id.btnreset);
  54. btnreset.setOnClickListener(new View.OnClickListener() {
  55. public void onClick(View v) {
  56. new resetuser().execute(tusername.getText().toString(),null,null);
  57. }
  58. });
  59. return rowView;
  60. }
  61. class resetuser extends AsyncTask<String, String, String>
  62. {
  63. protected void onPreExecute()
  64. {
  65. super.onPreExecute();
  66. pDialog = new ProgressDialog(context);
  67. pDialog.setMessage("Reseting user password. Please wait...");
  68. pDialog.setIndeterminate(false);
  69. pDialog.setCancelable(true);
  70. pDialog.show();
  71. }
  72. protected String doInBackground(String... params)
  73. {
  74. int success;
  75. try
  76. {
  77. Uri.Builder builder = new Uri.Builder()
  78. .appendQueryParameter("username", params[0]);
  79. String query = builder.build().getEncodedQuery();
  80. JSONObject json = jsonParser.makeHttpRequest(url_login, query);
  81. if(json !=null)
  82. {
  83. Log.d("resettinguser", json.toString());
  84. success = json.getInt("result");
  85. if (success == 1)
  86. {
  87. ((Activity) context).runOnUiThread(new Runnable()
  88. {
  89. public void run()
  90. {
  91. Toast.makeText(context, "Reset is success", Toast.LENGTH_LONG).show();
  92. }
  93. });
  94. }
  95. else
  96. {
  97. ((Activity) context).runOnUiThread(new Runnable()
  98. {
  99. public void run()
  100. {
  101. Toast.makeText(context, "Reset failed", Toast.LENGTH_LONG).show();
  102. }
  103. });
  104. }
  105. }
  106. else
  107. {
  108. ((Activity) context).runOnUiThread(new Runnable()
  109. {
  110. public void run()
  111. {
  112. Toast.makeText(context,"Unable to contact server",Toast.LENGTH_LONG).show();
  113.  
  114. }
  115. });
  116. return null;
  117. }
  118. }
  119. catch (JSONException e)
  120. {
  121. e.printStackTrace();
  122. }
  123. return null;
  124. }
  125. protected void onPostExecute(String file_url)
  126. {
  127. pDialog.dismiss();
  128. }
  129. }
  130. }
  131.  
  132.  
  133.  
  134. resetuser.php
  135.  
  136. <?php
  137. include "newdb.php";
  138. $dbcon=connect_db();
  139. ?>
  140. <?php
  141. $username=$_POST["username"];
  142. $flag=0;
  143. $statement="update users set password='123456' where username='$username'";
  144. if (mysqli_query($dbcon, $statement))
  145. {
  146. $myObj=new \stdClass();
  147. $myObj->result = "1";
  148. $myJSON = json_encode($myObj);
  149. echo $myJSON;
  150. exit();
  151. }
  152. else
  153. {
  154. $myObj=new \stdClass();
  155. $myObj->result = "2";
  156. $myJSON = json_encode($myObj);
  157. echo $myJSON;
  158. exit();
  159. }
  160. close_db();
  161. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement