connection
This commit is contained in:
parent
05e694b9a9
commit
f4596236de
4 changed files with 18 additions and 18 deletions
8
api.php
8
api.php
|
@ -223,8 +223,7 @@
|
||||||
$password = $_POST['password'];
|
$password = $_POST['password'];
|
||||||
|
|
||||||
$succes = connecter_utilisateur(htmlspecialchars($username),$password);
|
$succes = connecter_utilisateur(htmlspecialchars($username),$password);
|
||||||
|
if($succes){
|
||||||
if($succes == 1){
|
|
||||||
echo( json_encode(["status"=> "1","msg"=> "Utilisateur connecté !" ]) );
|
echo( json_encode(["status"=> "1","msg"=> "Utilisateur connecté !" ]) );
|
||||||
}else{
|
}else{
|
||||||
echo( json_encode(["status"=> "0","msg"=> "Utilisateur inconnu ou informations d'identification erronées." ]) );
|
echo( json_encode(["status"=> "0","msg"=> "Utilisateur inconnu ou informations d'identification erronées." ]) );
|
||||||
|
@ -254,9 +253,8 @@
|
||||||
$password_hash = password_hash($password, PASSWORD_DEFAULT);
|
$password_hash = password_hash($password, PASSWORD_DEFAULT);
|
||||||
|
|
||||||
$succes = inscription_utilisateur(htmlspecialchars($username),$password_hash);
|
$succes = inscription_utilisateur(htmlspecialchars($username),$password_hash);
|
||||||
|
if($succes){
|
||||||
if($succes == 1){
|
echo( json_encode(["status"=> 1,"msg"=> "Utilisateur inscrit !" ]) );
|
||||||
echo( json_encode(["status"=> "1","msg"=> "Utilisateur inscrit !" ]) );
|
|
||||||
}else{
|
}else{
|
||||||
echo( json_encode(["status"=> "0","msg"=> "Une erreur est survenue lors de votre inscription :/" ]) );
|
echo( json_encode(["status"=> "0","msg"=> "Une erreur est survenue lors de votre inscription :/" ]) );
|
||||||
}
|
}
|
||||||
|
|
15
bdd.php
15
bdd.php
|
@ -385,17 +385,18 @@ function inscription_utilisateur($username,$password_hash){
|
||||||
|
|
||||||
$stmt = $conn->prepare("INSERT INTO users (username, password_hash) VALUES (?, ?)");
|
$stmt = $conn->prepare("INSERT INTO users (username, password_hash) VALUES (?, ?)");
|
||||||
$stmt->bind_param("ss", $username, $password_hash);
|
$stmt->bind_param("ss", $username, $password_hash);
|
||||||
|
|
||||||
|
|
||||||
// met le statut de l'utilisateur à connecté pour lui eviter de se connecter just après l'inscription
|
|
||||||
$_SESSION["utilisateur_authentifie"] = true;
|
|
||||||
$_SESSION["username"] = $username;
|
|
||||||
$_SESSION["admin"] = 0;
|
|
||||||
|
|
||||||
|
|
||||||
$ret = $stmt->execute();
|
$ret = $stmt->execute();
|
||||||
|
|
||||||
$stmt->close();
|
$stmt->close();
|
||||||
|
|
||||||
|
if($ret){
|
||||||
|
// met le statut de l'utilisateur à connecté pour lui eviter de se connecter just après l'inscription
|
||||||
|
$_SESSION["utilisateur_authentifie"] = true;
|
||||||
|
$_SESSION["username"] = $username;
|
||||||
|
$_SESSION["admin"] = 0;
|
||||||
|
}
|
||||||
|
|
||||||
return $ret;
|
return $ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -11,7 +11,7 @@ function inscription(){
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
body: formData
|
body: formData
|
||||||
})
|
})
|
||||||
.then(response => response.text())
|
.then(response => response.json())
|
||||||
.then(data => {
|
.then(data => {
|
||||||
if(data.status == 1){
|
if(data.status == 1){
|
||||||
window.location.href = "index.php";
|
window.location.href = "index.php";
|
||||||
|
|
|
@ -1,13 +1,14 @@
|
||||||
<?php
|
<?php
|
||||||
session_start();
|
session_start();
|
||||||
|
include("test_creds.php");
|
||||||
|
|
||||||
// Check if user is logged in and is an admin
|
// Check if user is logged in and is an admin
|
||||||
if (!isset($_SESSION["utilisateur_authentifie"]) || $_SESSION["utilisateur_authentifie"] !== true || !$_SESSION["admin"]) {
|
if (!isset($_SESSION["utilisateur_authentifie"]) || $_SESSION["utilisateur_authentifie"] !== true || !$_SESSION["admin"]) {
|
||||||
header("Location: login.php");
|
header("Location: index.php");
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
$conn = new mysqli('localhost', 'your_username', 'your_password', 'user_registration');
|
$conn = new mysqli($servername, $username, $password,$dbname);
|
||||||
|
|
||||||
if ($conn->connect_error) {
|
if ($conn->connect_error) {
|
||||||
die("Connection failed: " . $conn->connect_error);
|
die("Connection failed: " . $conn->connect_error);
|
||||||
|
@ -62,7 +63,7 @@ $result = $conn->query("SELECT id, username, admin FROM users");
|
||||||
</style>
|
</style>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<h1>Admin Page</h1>
|
<h1>Liste des utilisateurs</h1>
|
||||||
<table>
|
<table>
|
||||||
<tr>
|
<tr>
|
||||||
<th>ID</th>
|
<th>ID</th>
|
||||||
|
@ -72,14 +73,14 @@ $result = $conn->query("SELECT id, username, admin FROM users");
|
||||||
</tr>
|
</tr>
|
||||||
<?php while ($row = $result->fetch_assoc()): ?>
|
<?php while ($row = $result->fetch_assoc()): ?>
|
||||||
<tr>
|
<tr>
|
||||||
<form method="post" action="admin.php">
|
<form method="post" action="utilisateurs.php">
|
||||||
<td><?php echo $row['id']; ?></td>
|
<td><?php echo $row['id']; ?></td>
|
||||||
<td><input type="text" name="username" value="<?php echo $row['username']; ?>"></td>
|
<td><input type="text" name="username" value="<?php echo $row['username']; ?>"></td>
|
||||||
<td><input type="checkbox" name="admin" <?php if ($row['admin']) echo "checked"; ?>></td>
|
<td><input type="checkbox" name="admin" <?php if ($row['admin']) echo "checked"; ?>></td>
|
||||||
<td>
|
<td>
|
||||||
<input type="hidden" name="id" value="<?php echo $row['id']; ?>">
|
<input type="hidden" name="id" value="<?php echo $row['id']; ?>">
|
||||||
<button type="submit" name="update">Update</button>
|
<button type="submit" name="update">Update</button>
|
||||||
<button type="submit" name="delete" onclick="return confirm('Are you sure you want to delete this user?');">Delete</button>
|
<button type="submit" name="delete" onclick="return confirm('T\'es sur sur sur de le supprimer ? ');">Delete</button>
|
||||||
</td>
|
</td>
|
||||||
</form>
|
</form>
|
||||||
</tr>
|
</tr>
|
||||||
|
|
Loading…
Reference in a new issue