Guest User

app

a guest
Jan 26th, 2016
29
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.85 KB | None | 0 0
  1. -------------------------------------------------------------------------------------------- affiche des utilisateurs
  2. <?php
  3.  
  4. if($_SERVER["REQUEST_METHOD"]=="POST"){
  5. include 'config.php';
  6. showUsers();
  7. }
  8.  
  9. function showUsers(){
  10. global $connect;
  11.  
  12. $query="SELECT * FROM Utilisateurs WHERE connected=1;";
  13.  
  14. $result=mysqli_query($connect, $query);
  15. $number_of_rows=mysqli_num_rows($result);
  16.  
  17. $temp_array=[];
  18.  
  19. if($number_of_rows > 0){
  20. while($row=mysqli_fetch_assoc($result)){
  21. $temp_array[]=$row;
  22. }
  23. }
  24.  
  25. header('Content-Type: application/json');
  26. echo json_encode(array("Users"=>$temp_array));
  27. var_dump($temp_array);
  28. mysqli_close($connect);
  29. }
  30.  
  31. ---------------------------------------------------------------------------------------------- login (marche pas)
  32. <?php
  33.  
  34. if($_SERVER["REQUEST_METHOD"]=="POST"){
  35. include 'config.php';
  36. connect();
  37. }
  38.  
  39. function connect(){
  40. //Champs
  41. global $connect;
  42. $alias=$_POST["alias"];
  43. $password=$_POST["password"];
  44.  
  45. //REQUEST
  46. $queryA="SELECT * FROM Utilisateurs WHERE alias='$alias' AND password='$password';";
  47. $queryB="UPDATE Utilisateurs SET connected=1 WHERE alias='$alias' AND password='$password';";
  48. $result=mysqli_query($connect, $queryA);
  49. $number_of_rows=mysqli_num_rows($result);
  50.  
  51. $temp_array=[];
  52.  
  53. if($number_of_rows > 0){
  54. while($row=mysqli_fetch_assoc($result)){
  55. $temp_array[]=$row;
  56. }
  57. }
  58. if(!empty($temp_array)){
  59. //Update connect
  60. header('Content-Type: application/json');
  61. print(json_encode(array("Users"=>$temp_array)));
  62. }
  63. mysqli_query($connect, $queryB);
  64. mysqli_close($connect);
  65. }
  66.  
  67. ------------------------------------------------------- afficher des users coté JAVA marche
  68. private void showConnectedUsers() {
  69. JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.POST, showUrl, new Response.Listener<JSONObject>() {
  70. @Override
  71. public void onResponse(JSONObject response) {
  72. try {
  73. JSONArray Users = response.getJSONArray("Users");
  74. for (int i = 0; i < Users.length(); i++) {
  75. JSONObject user = Users.getJSONObject(i);
  76.  
  77. String alias = user.getString("alias");
  78. String mail = user.getString("mail");
  79. String password = user.getString("password");
  80. String nom = user.getString("nom");
  81. String prenom = user.getString("prenom");
  82.  
  83. result.append(alias+" "+mail+" "+nom+" "+prenom+"\n");
  84. }
  85. }
  86. catch (JSONException e) {
  87. e.printStackTrace();
  88. }
  89. }
  90. }, new Response.ErrorListener() {
  91. @Override
  92. public void onErrorResponse(VolleyError e) {
  93.  
  94. }
  95. });
  96. requestQueue.add(jsonObjectRequest);
  97. }
  98.  
  99. --------------------------------------------------------------- login coté Java marche pas
  100. private void connectUser() {
  101. final JsonObjectRequest request = new JsonObjectRequest(Request.Method.POST, connectUrl, new Response.Listener<JSONObject>() {
  102. @Override
  103. public void onResponse(JSONObject response) {
  104. try {
  105.  
  106. JSONArray Users = response.getJSONArray("Users");
  107. for (int i = 0; i < Users.length(); i++) {
  108. JSONObject user = Users.getJSONObject(i);
  109.  
  110. String alias = user.getString("alias");
  111. String mail = user.getString("mail");
  112. String password = user.getString("password");
  113. String nom = user.getString("nom");
  114. String prenom = user.getString("prenom");
  115.  
  116. User = new UserModel(alias, password, mail, nom, prenom);
  117.  
  118. }
  119. test.append(User.getAlias());
  120. //userLocalStore.storeUserData(User);
  121. userLocalStore.setUserLoggedIn(true);
  122. }
  123. catch (JSONException e) {
  124. e.printStackTrace();
  125. }
  126.  
  127. }
  128. }, new Response.ErrorListener() {
  129. @Override
  130. public void onErrorResponse(VolleyError e) {
  131. Toast.makeText(ConnectActivity.this, e.toString(), Toast.LENGTH_LONG).show();
  132. }
  133. }) {
  134. @Override
  135. public Map<String, String> getHeaders() throws AuthFailureError {
  136. Map<String, String> headers = new HashMap<String, String>();
  137. headers.put("Content-Type", "application/json; charset=utf-8");
  138. return headers;
  139. }
  140. };
  141. requestQueue.add(request);
  142. }
Add Comment
Please, Sign In to add comment