<?php
session_start();
header('Access-Control-Allow-Origin:*');
header('Content-Type; application/json; charset=utf-8');
header('Access-control-Allow-Method: POST');
header('Access-control-Allow-Headers: Content-Type, Access-Control-Allow-Headers, Authorization, X-request-With');
include('db.php');
    $inputdata = json_decode(file_get_contents("php://input"), true);
    $email = $inputdata['email'];
    $password = $inputdata['password'];

    //verifier si le email existe avant conexion
    $verif_email=$db->prepare('SELECT * FROM tbl_user WHERE useremail=? AND password=? AND role=?');
    $verif_email->execute(array($email,$password,"admin"));
    $nbr = $verif_email->rowCount();

    if ($nbr == 1) {
        //conexion succès
        $user = $verif_email->fetchObject();
        $var_data = (object) $user;
        echo(json_encode(['loginData' => $user]));
    } else {
        // email ou mot de passe incorrect
        echo(json_encode(['errorlogin' => 1]));

    }
    
    

