<?php
// required headers
header("Access-Control-Allow-Origin: *");
header("Content-Type: application/json; charset=UTF-8");
header("Access-Control-Allow-Methods: POST");
header("Access-Control-Max-Age: 3600");
header("Access-Control-Allow-Headers: Content-Type, Access-Control-Allow-Headers, Authorization, X-Requested-With");
  
// get database connection
include_once '../config/database.php';
  
// instantiate product object
include_once '../objects/identite.php';
  
$database = new Database();
$db = $database->getConnection();
  
$identite = new Identite($db);
  
// get posted data
$data = json_decode(file_get_contents("php://input"));

// make sure data is not empty
if(
    !empty($data->login) &&
    !empty($data->password) &&
    !empty($data->pseudo) &&
    !empty($data->age) &&
    !empty($data->poids) &&
    !empty($data->taille) &&
    !empty($data->sexe) &&
    !empty($data->niveaudusport)
){
    // set product property values
    $identite->login = $data->login;
    $identite->password = $data->password;
    $identite->pseudo = $data->pseudo;
    $identite->age = $data->age;
    $identite->poids = $data->poids;
    $identite->taille = $data->taille;
    $identite->sexe = $data->sexe;
    $identite->niveaudusport = $data->niveaudusport;
    
    if($identite->create()){
    // set response code - 201 created
        http_response_code(201);
  
        // tell the user
        echo json_encode(array("message" => "L'identifiant est bien crée!"));
    }
  
    // if unable to create the product, tell the user
    else{
  
        // set response code - 503 service unavailable
        http_response_code(503);
  
        // tell the user
        echo json_encode(array("message" => "Impossible de créer."));
    }
}
  
// tell the user data is incomplete
else{
  
    // set response code - 400 bad request
    http_response_code(400);
  
    // tell the user
    echo json_encode(array("message" => "Informations incomplètes"));
}
?>
