Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -------------------------------------------------------------------------------------------- affiche des utilisateurs
- <?php
- if($_SERVER["REQUEST_METHOD"]=="POST"){
- include 'config.php';
- showUsers();
- }
- function showUsers(){
- global $connect;
- $query="SELECT * FROM Utilisateurs WHERE connected=1;";
- $result=mysqli_query($connect, $query);
- $number_of_rows=mysqli_num_rows($result);
- $temp_array=[];
- if($number_of_rows > 0){
- while($row=mysqli_fetch_assoc($result)){
- $temp_array[]=$row;
- }
- }
- header('Content-Type: application/json');
- echo json_encode(array("Users"=>$temp_array));
- var_dump($temp_array);
- mysqli_close($connect);
- }
- ---------------------------------------------------------------------------------------------- login (marche pas)
- <?php
- if($_SERVER["REQUEST_METHOD"]=="POST"){
- include 'config.php';
- connect();
- }
- function connect(){
- //Champs
- global $connect;
- $alias=$_POST["alias"];
- $password=$_POST["password"];
- //REQUEST
- $queryA="SELECT * FROM Utilisateurs WHERE alias='$alias' AND password='$password';";
- $queryB="UPDATE Utilisateurs SET connected=1 WHERE alias='$alias' AND password='$password';";
- $result=mysqli_query($connect, $queryA);
- $number_of_rows=mysqli_num_rows($result);
- $temp_array=[];
- if($number_of_rows > 0){
- while($row=mysqli_fetch_assoc($result)){
- $temp_array[]=$row;
- }
- }
- if(!empty($temp_array)){
- //Update connect
- header('Content-Type: application/json');
- print(json_encode(array("Users"=>$temp_array)));
- }
- mysqli_query($connect, $queryB);
- mysqli_close($connect);
- }
- ------------------------------------------------------- afficher des users coté JAVA marche
- private void showConnectedUsers() {
- JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.POST, showUrl, new Response.Listener<JSONObject>() {
- @Override
- public void onResponse(JSONObject response) {
- try {
- JSONArray Users = response.getJSONArray("Users");
- for (int i = 0; i < Users.length(); i++) {
- JSONObject user = Users.getJSONObject(i);
- String alias = user.getString("alias");
- String mail = user.getString("mail");
- String password = user.getString("password");
- String nom = user.getString("nom");
- String prenom = user.getString("prenom");
- result.append(alias+" "+mail+" "+nom+" "+prenom+"\n");
- }
- }
- catch (JSONException e) {
- e.printStackTrace();
- }
- }
- }, new Response.ErrorListener() {
- @Override
- public void onErrorResponse(VolleyError e) {
- }
- });
- requestQueue.add(jsonObjectRequest);
- }
- --------------------------------------------------------------- login coté Java marche pas
- private void connectUser() {
- final JsonObjectRequest request = new JsonObjectRequest(Request.Method.POST, connectUrl, new Response.Listener<JSONObject>() {
- @Override
- public void onResponse(JSONObject response) {
- try {
- JSONArray Users = response.getJSONArray("Users");
- for (int i = 0; i < Users.length(); i++) {
- JSONObject user = Users.getJSONObject(i);
- String alias = user.getString("alias");
- String mail = user.getString("mail");
- String password = user.getString("password");
- String nom = user.getString("nom");
- String prenom = user.getString("prenom");
- User = new UserModel(alias, password, mail, nom, prenom);
- }
- test.append(User.getAlias());
- //userLocalStore.storeUserData(User);
- userLocalStore.setUserLoggedIn(true);
- }
- catch (JSONException e) {
- e.printStackTrace();
- }
- }
- }, new Response.ErrorListener() {
- @Override
- public void onErrorResponse(VolleyError e) {
- Toast.makeText(ConnectActivity.this, e.toString(), Toast.LENGTH_LONG).show();
- }
- }) {
- @Override
- public Map<String, String> getHeaders() throws AuthFailureError {
- Map<String, String> headers = new HashMap<String, String>();
- headers.put("Content-Type", "application/json; charset=utf-8");
- return headers;
- }
- };
- requestQueue.add(request);
- }
Add Comment
Please, Sign In to add comment