<!doctype html>
<html>
<head>
</head>
<body>

<?php
session_start();

if(isset($_SESSION['login'])){
    header('Location: home.php');
}  
?>
<form id="login_form" action="#" method="POST">
    <table>
        <tr>
            <th>Login :</th>
            <td><input type="text" id ='login' name="login"></td>
        </tr>
        <tr>
            <th>Mot de passe :</th>
            <td><input type="password" id='password' name="password"></td>
        </tr>
        <tr>
            <th></th>
            <td><input type="submit" value="Se connecter..." /></td>
        </tr>
        <tr>
            <a href="signup.php">S'inscrire</a>
        </tr>
    </table>
</form>


<script type="text/javascript">
// show home page
function showHomePage(){
 
     // if valid, show homepage
var html = <a href="home.php">;
 
 }
</script>


<script
    src="https://code.jquery.com/jquery-3.4.1.min.js"
    integrity="sha256-CSXorXvZcTkaix6Yvo6HppcZGetbYMGWSFlBw8HfCJo="
    crossorigin="anonymous"></script>

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-serialize-object/2.5.0/jquery.serialize-object.min.js" ></script>

<script type="text/javascript">

$(document).ready( function($) {
    // will run if create identite form was submitted
    $(document).on('submit', '#login_form', function(){
        // get form data
        var form_data=JSON.stringify($(this).serializeObject());
        // console.log(form_data);

        // submit form data to api
        $.ajax({
            url: "https://eden.imt-lille-douai.fr/~liang.wu/API_LOGIN/identite/login.php",
            type : "POST",
            contentType : 'application/json',
            data : form_data,
            success : function(result){
            // show home page & tell the user it was a successful login
            showHomePage();
            $('#response').html("<div class='alert alert-success'>Successful login.</div>");
            }
        });
    });
});
</script>

</body>
</html>