|
|
|
@ -1,4 +1,5 @@
|
|
|
|
|
<?php
|
|
|
|
|
//from : https://api.wordpress.org/secret-key/1.1/salt
|
|
|
|
|
define('AUTH_KEY', '2(QMu)jt|2!(9t]V!4SB/y,+T]LcvGZ8-sV@vS6RUgR!_]&S}{6/RZjAmLeW28On');
|
|
|
|
|
|
|
|
|
|
//header('Content-type: text/plain;charset=utf-8');
|
|
|
|
@ -33,6 +34,7 @@
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case "/key/" :
|
|
|
|
|
case "/key" :
|
|
|
|
|
if($vars['REQUEST_METHOD'] == "POST")
|
|
|
|
|
{
|
|
|
|
|
if(!empty($_POST['user']) && !empty($_POST['password']))
|
|
|
|
@ -40,12 +42,50 @@
|
|
|
|
|
$user = $_POST['user'];
|
|
|
|
|
$password = md5($_POST['password'].AUTH_KEY);
|
|
|
|
|
$response = array('user'=>$user,'md5'=>$password);
|
|
|
|
|
|
|
|
|
|
//essayer de se connecter à ùysql (nb sur un xampp/wammp souvent l'utilisateur root avec mot de passe vide)
|
|
|
|
|
//https://www.tutorialspoint.com/mysqli/mysqli_connection.htm
|
|
|
|
|
// na pas oublier de convertir les → en ->
|
|
|
|
|
$dbhost = 'localhost';
|
|
|
|
|
$dbuser = 'root';
|
|
|
|
|
$dbpass = '';
|
|
|
|
|
$dbname = 'apib3';
|
|
|
|
|
//si je préfixe avec @je n'aurais pas le message d'erreur.
|
|
|
|
|
@ $mysqli = new mysqli($dbhost, $dbuser, $dbpass, $dbname);
|
|
|
|
|
|
|
|
|
|
if($mysqli->connect_errno ) {
|
|
|
|
|
header('HTTP/1.1 500 Internal Server Error');
|
|
|
|
|
echo json_encode( (object) array('error'=>"Connect failed: ".$mysqli->connect_error ));
|
|
|
|
|
exit();
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
$response['connection'] = 'successful';
|
|
|
|
|
// vérifier si l'utilisateur existe
|
|
|
|
|
$sql = "SELECT * FROM `user` WHERE `user` LIKE '".$user."' AND `password` ='".$password."'";
|
|
|
|
|
$result = $mysqli->query($sql);
|
|
|
|
|
if ($result->num_rows > 0) {
|
|
|
|
|
//
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
$sql ="INSERT INTO `user` VALUES (NULL,'".$user."','".$password."')";
|
|
|
|
|
$result = $mysqli->query($sql);
|
|
|
|
|
if($mysqli->connect_errno ) {
|
|
|
|
|
header('HTTP/1.1 500 Internal Server Error');
|
|
|
|
|
echo json_encode( (object) array('error'=>"Insert failed: ".$mysqli->connect_error ));
|
|
|
|
|
exit();
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
$response['insert'] = 'successful';
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
$mysqli->close();
|
|
|
|
|
header('HTTP/1.1 200 OK');
|
|
|
|
|
echo json_encode( (object) $response );
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
header('HTTP/1.1 403 Forbidden');
|
|
|
|
|
|
|
|
|
|
echo json_encode( (object) array('error'=>'PLease provide a valid user and matching password') );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|