Commit 76c7c884 authored by Raulin's avatar Raulin
parents ff0431ae 5c91a8e4
No preview for this file type
......@@ -25,21 +25,21 @@ if(
!empty($data->login) &&
!empty($data->password) &&
!empty($data->pseudo) &&
!empty($data->âge) &&
!empty($data->age) &&
!empty($data->poids) &&
!empty($data->taille) &&
!empty($data->sexe) &&
!empty($data->niveau_du_sport)
!empty($data->niveaudusport)
){
// set product property values
$identite->login = $data->login;
$identite->password = $data->password;
$identite->pseudo = $data->pseudo;
$identite->âge = $data->âge;
$identite->age = $data->age;
$identite->poids = $data->poids;
$identite->taille = $data->taille;
$identite->sexe = $data->sexe;
$identite->niveau_du_sport = $data->niveau_du_sport;
$identite->niveaudusport = $data->niveaudusport;
if($identite->create()){
// set response code - 201 created
......
<?php
// required headers
header("Access-Control-Allow-Origin: https://eden.imt-lille-douai.fr/~liang.wu/API_LOGIN/identite/");
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");
......@@ -16,18 +16,29 @@
// instantiate user object
$identite = new Identite($db);
$login_exists = $identite->loginExists();
// get posted data
$data = json_decode(file_get_contents("php://input"));
// set product property values
$identite->login = $data->login;
$identite->password = $data->password;
$login_exists = $identite->loginExists();
// check if email exists and if password is correct
if($login_exists){
$password = $identite->password;
if($password==$data->password){
http_response_code(200);
echo json_encode(array("message" => "Successful login."));}
echo json_encode(array(
"message" => "Successful login."
));
}
else{
http_response_code(401);
// tell the user login failed
echo json_encode(array("message" => "Mot de passe incorrect"));
}
}
// login failed
......
......@@ -40,11 +40,11 @@ if($num>0){
"login" => $login,
"password" => $password,
"pseudo" => $pseudo,
"âge" => ge,
"age" => $age,
"poids" => $poids,
"taille" => $taille,
"sexe" => $sexe,
"niveau_du_sport" =>$niveau_du_sport
"niveaudusport" =>$niveaudusport
);
array_push($identites_arr["records"], $identite_item);
......
......@@ -18,23 +18,23 @@ $db = $database->getConnection();
$identite = new Identite($db);
// set ID property of record to read
$identite->id = isset($_GET['id']) ? $_GET['id'] : die();
$identite->login = isset($_GET['login']) ? $_GET['login'] : die();
// read the details of product to be edited
$identite->readOne();
if($identite->login!=null){
if($identite->id!=null){
// create array
$identite_arr = array(
"id" => $identite->id,
"login" => $identite->login,
"password" => $identite->password,
"pseudo" => $identite->pseudo,
"âge" => $identite->âge,
"age" => $identite->age,
"poids" => $identite->poids,
"taille" => $identite->taille,
"sexe" => $identite->sexe,
"niveau_du_sport" =>$identite->niveau_du_sport
"niveaudusport" =>$identite->niveaudusport
);
// set response code - 200 OK
......
......@@ -43,11 +43,11 @@ if($num>0){
"login" => $login,
"password" => $password,
"pseudo" => $pseudo,
"âge" => ge,
"age" => $age,
"poids" => $poids,
"taille" => $taille,
"sexe" => $sexe,
"niveau_du_sport" =>$niveau_du_sport
"niveaudusport" =>$niveaudusport
);
array_push($identites_arr["records"], $identite_item);
......
......@@ -27,11 +27,11 @@ $identite->id = $data->id;
$identite->login = $data->login;
$identite->password = $data->password;
$identite->pseudo = $data->pseudo;
$identite->âge = $data->âge;
$identite->age = $data->age;
$identite->poids = $data->poids;
$identite->taille = $data->taille;
$identite->sexe = $data->sexe;
$identite->niveau_du_sport = $data->niveau_du_sport;
$identite->niveaudusport = $data->niveaudusport;
// update the product
if($identite->update()){
......
<?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");
// required to decode jwt
include_once '../config/core.php';
include_once '../libs/php-jwt-master/src/BeforeValidException.php';
include_once '../libs/php-jwt-master/src/ExpiredException.php';
include_once '../libs/php-jwt-master/src/SignatureInvalidException.php';
include_once '../libs/php-jwt-master/src/JWT.php';
use \Firebase\JWT\JWT;
// get posted data
$data = json_decode(file_get_contents("php://input"));
// get jwt
$jwt=isset($data->jwt) ? $data->jwt : "";
// if jwt is not empty
if($jwt){
// if decode succeed, show user details
try {
// decode jwt
$decoded = JWT::decode($jwt, $key, array('HS256'));
// set response code
http_response_code(200);
// show user details
echo json_encode(array(
"message" => "Access granted.",
"data" => $decoded->data
));
}
// if decode fails, it means jwt is invalid
catch (Exception $e){
// set response code
http_response_code(401);
// tell the user access denied & show error message
echo json_encode(array(
"message" => "Access denied.",
"error" => $e->getMessage()
));
}
}
// show error message if jwt is empty
else{
// set response code
http_response_code(401);
// tell the user access denied
echo json_encode(array("message" => "Access denied."));
}
?>
\ No newline at end of file
No preview for this file type
......@@ -9,11 +9,11 @@ class Identite{
public $login;
public $password;
public $pseudo;
public $âge;
public $age;
public $poids;
public $taille;
public $sexe;
public $niveau_du_sport;
public $niveaudusport;
// constructor with $db as database connection
public function __construct($db){
......@@ -40,7 +40,7 @@ class Identite{
// query to check if email exists
$query = "SELECT *
FROM $this->table_name
WHERE login =:login AND password =: password
WHERE login = ?
LIMIT 0,1";
// prepare the query
......@@ -48,12 +48,9 @@ class Identite{
// sanitize
$this->login=htmlspecialchars(strip_tags($this->login));
$this->password=htmlspecialchars(strip_tags($this->password));
// bind given email value
$stmt->bindParam(':login', $this->login);
$stmt->bindParam(':password', $this->password);
$stmt->bindParam(1, $this->login);
// execute the query
$stmt->execute();
......@@ -70,11 +67,11 @@ class Identite{
$this->id = $row['id'];
$this->password = $row['password'];
$this->pseudo = $row['pseudo'];
$this->âge = $row[ge'];
$this->age = $row['age'];
$this->poids = $row['poids'];
$this->taille = $row['taille'];
$this->sexe = $row['sexe'];
$this->niveau_du_sport = $row['niveau_du_sport'];
$this->niveaudusport = $row['niveaudusport'];
// return true because email exists in the database
return true;
......@@ -90,9 +87,9 @@ class Identite{
// query to insert record
$query = "INSERT INTO
" . $this->table_name . "
".$this->table_name."
SET
login=:login, password=:password, pseudo=:pseudo, âge=:âge, poids=:poids, taille=:taille, sexe=:sexe, niveau_du_sport=:niveau_du_sport";
login=:login, password=:password, pseudo=:pseudo, age=:age, poids=:poids, taille=:taille, sexe=:sexe, niveaudusport=:niveaudusport";
// prepare query
$stmt = $this->conn->prepare($query);
......@@ -101,21 +98,22 @@ class Identite{
$this->login=htmlspecialchars(strip_tags($this->login));
$this->password=htmlspecialchars(strip_tags($this->password));
$this->pseudo=htmlspecialchars(strip_tags($this->pseudo));
$this->âge=htmlspecialchars(strip_tags($this->âge));
$this->age=htmlspecialchars(strip_tags($this->age));
$this->poids=htmlspecialchars(strip_tags($this->poids));
$this->taille=htmlspecialchars(strip_tags($this->taille));
$this->sexe=htmlspecialchars(strip_tags($this->sexe));
$this->niveau_du_sport=htmlspecialchars(strip_tags($this->niveau_du_sport));
$this->niveaudusport=htmlspecialchars(strip_tags($this->niveaudusport));
// bind values
$stmt->bindParam(":login", $this->login);
$stmt->bindParam(":password", $this->password);
$stmt->bindParam(":pseudo", $this->pseudo);
$stmt->bindParam(":âge", $this->âge);
$stmt->bindParam(":age", $this->age);
$stmt->bindParam(":poids", $this->poids);
$stmt->bindParam(":taille", $this->taille);
$stmt->bindParam(":sexe", $this->sexe);
$stmt->bindParam(":niveau_du_sport", $this->niveau_du_sport);
$stmt->bindParam(":niveaudusport", $this->niveaudusport);
// execute query
if($stmt->execute()){
......@@ -129,13 +127,13 @@ class Identite{
function readOne(){
// query to read single record
$query = "SELECT * FROM $this->table_name WHERE id = ?";
$query = "SELECT * FROM $this->table_name WHERE login = ?";
// prepare query statement
$stmt = $this->conn->prepare( $query );
// bind id of product to be updated
$stmt->bindParam(1, $this->id);
$stmt->bindParam(1, $this->login);
// execute query
$stmt->execute();
......@@ -144,14 +142,14 @@ class Identite{
$row = $stmt->fetch(PDO::FETCH_ASSOC);
// set values to object properties
$this->login = $row['login'];
$this->id = $row['id'];
$this->password = $row['password'];
$this->pseudo = $row['pseudo'];
$this->âge = $row[ge'];
$this->age = $row['age'];
$this->poids = $row['poids'];
$this->taille = $row['taille'];
$this->sexe = $row['sexe'];
$this->niveau_du_sport = $row['niveau_du_sport'];
$this->niveaudusport = $row['niveaudusport'];
//$this->besoin_en_calories = $row['besoin_en_calories'];
}
// update the product
......@@ -161,17 +159,17 @@ class Identite{
$query = "UPDATE
" . $this->table_name . "
SET
login = :login,
password = :password,
pseudo = :pseudo,
âge = :âge,
poids = :poids,
taille = :taille,
sexe = :sexe,
niveau_du_sport = :niveau_du_sport
login=:login,
password=:password,
pseudo=:pseudo,
age=:age,
poids=:poids,
taille=:taille,
sexe=:sexe,
niveaudusport=:niveaudusport
//besoin_en_calories =:besoin_en_calories
WHERE
id = :id";
id=:id";
// prepare query statement
$stmt = $this->conn->prepare($query);
......@@ -181,11 +179,11 @@ class Identite{
$this->login=htmlspecialchars(strip_tags($this->login));
$this->password=htmlspecialchars(strip_tags($this->password));
$this->pseudo=htmlspecialchars(strip_tags($this->pseudo));
$this->âge=htmlspecialchars(strip_tags($this->âge));
$this->age=htmlspecialchars(strip_tags($this->age));
$this->poids=htmlspecialchars(strip_tags($this->poids));
$this->taille=htmlspecialchars(strip_tags($this->taille));
$this->sexe=htmlspecialchars(strip_tags($this->sexe));
$this->niveau_du_sport=htmlspecialchars(strip_tags($this->niveau_du_sport));
$this->niveaudusport=htmlspecialchars(strip_tags($this->niveaudusport));
//$this->besoin_en_calories=htmlspecialchars(strip_tags($this->besoin_en_calories));
......@@ -194,11 +192,11 @@ class Identite{
$stmt->bindParam(':login', $this->login);
$stmt->bindParam(':password', $this->password);
$stmt->bindParam(':pseudo', $this->pseudo);
$stmt->bindParam(':âge', $this->âge);
$stmt->bindParam(':age', $this->age);
$stmt->bindParam(':poids', $this->poids);
$stmt->bindParam(':taille', $this->taille);
$stmt->bindParam(':sexe', $this->sexe);
$stmt->bindParam(':niveau_du_sport', $this->niveau_du_sport);
$stmt->bindParam(':niveaudusport', $this->niveaudusport);
// $stmt->bindParam(':besoin_en_calories', $this->besoin_en_calories);
......
File added
<?php
require_once('template_header.php');
?>
<script type="text/javascript">
$(document).ready( function() {
$.getJSON('https://eden.imt-lille-douai.fr/~liang.wu/API_LOGIN/identite/read.php',
function(json){
// console.log(json);
var table = <?php echo json_encode($users); ?>;
table.php('');
// cf. https://api.jquery.com/jQuery.getJSON/
$.each( json, function( key, val ) {
table.append(val['login']+'=>'+val['password']+',');
});
}
)
});
</script>
<?php
$users = array();
$login = "anonymous";
$errorText = "";
$successfullyLogged = false;
if(isset($_GET['login']) && isset($_GET['password'])){
$tryLogin=$_GET['login'];
$tryPwd=$_GET['password'];
//si le mdp est correct
if(array_key_exists($tryLogin,$users) && $users[$tryLogin]==$tryPwd){
$successfullyLogged = true;
$login = $tryLogin;
} else
$errorText = "Erreur de login/password1";
} else
$errorText = "Merci d'utiliser le formulaire de login";
if(!$successfullyLogged) {
echo $errorText;
} else {
session_start();
$_SESSION['login']=$login;
$_SESSION['password']=$password;
header('Location: home.php');
}
?>
......@@ -2,7 +2,7 @@
require_once('template_header.php');
require_once('template_menu.php');
$currentPageId='index';
$currentPageId='home';
if(isset($_GET['page'])){
$currentPageId=$_GET['page'];
}
......
<!doctype html>
<html>
<head>
</head>
<body>
<?php
session_start();
if(isset($_SESSION['login'])){
header('Location: home.php');
}
require_once('template_header.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(){
<main role="main" class="container starter-template">
// if valid, show homepage
var html = <a href="home.php">;
<div class="row">
<div class="col">
}
</script>
<!-- where prompt / messages will appear -->
<div id="response"></div>
<div>
<form id="login_form" 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>
</div>
</div>
</div>
</main>
<script
src="https://code.jquery.com/jquery-3.4.1.min.js"
......@@ -50,14 +43,17 @@ var html = <a href="home.php">;
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-serialize-object/2.5.0/jquery.serialize-object.min.js" ></script>
<script type="text/javascript">
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
<!-- jquery scripts will be here -->
$(document).ready( function($) {
<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({
......@@ -66,14 +62,22 @@ $(document).ready( function($) {
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>");
var ac_log=JSON.parse(form_data);
document.cookie ="IdentifiantActuel="+ac_log.login;
window.location="https://eden.imt-lille-douai.fr/~liang.wu/projet_idaw/home.php";
},
error: function(xhr, resp, text){
// on error, tell the user login has failed & empty the input boxes
$('#response').html("<div class='alert alert-danger'>Login failed. login or password is incorrect.</div>");
login_form.find('input').val('');
}
});
});
});
</script>
</body>
</html>
\ No newline at end of file
<?php
require_once('template_footer.php');
?>
\ No newline at end of file
<section>
<h2>Charlotte Raulin</h2>
<img src="logo.png" alt="" height="90px" width="150px"/><br>
<label> Age : < 40 </label><br>
<label> Sexe : Femme </label><br>
<label> Niveau de pratique sportive : Bas </label>
<head>
<meta charset="utf-8"/>
<script src="https://code.jquery.com/jquery-3.4.1.js" integrity="sha256-WpOohJOqMqqyKL9FccASB9O0KwACQJpFTUBLTYOVvVU=" crossorigin="anonymous"></script>
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.10.20/css/jquery.dataTables.css">
<script type="text/javascript" charset="utf8" src="https://cdn.datatables.net/1.10.20/js/jquery.dataTables.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$('#table_info').DataTable();
} );
</script>
<script type="text/javascript">
$(document).ready( function() {
// $ident= getCookie("IdentifiantActuel");
$.getJSON('https://eden.imt-lille-douai.fr/~liang.wu/API_LOGIN/identite/read.php',
function(data){
table = $('#tbody_info');
table.html('');
$.each( data.records, function( key, val ) {
table.append('<tr><td>'+val.id+'</td><td>'+val.login+'</td><td>'+val.password+'</td><td>'+val.pseudo+'</td><td>'+val.age+'</td><td>'+val.poids+'</td><td>'+val.taille+'</td><td>'+val.sexe+'</td><td>'+val.niveaudusport+'</td></tr>');
});
}
);
</script>
</head>
<section id="profil_contenu" style="display : flex; flex-direction : row; ">
<div style="margin-right:100px">
<table id="table_info" class="dataTable" style="color : #212529; ">
<thead>
<tr>
<th>id</th>
<th>login</th>
<th>password</th>
<th>pseudo</th>
<th>âge</th>
<th>poids(kg)</th>
<th>taille(cm)</th>
<th>sexe</th>
<th>niveau_du_sport</th>
<th>Action</th>
</tr>
</thead>
<tbody id="tbody_info"><tbody>
</table>
</div>
</section>
\ No newline at end of file
<!doctype html>
<html>
<head>
</head>
<body>
<?php
require_once('template_header.php');
?>
<section>
<div id="response"></div>
<div><a href="index.php">Se connecter</a></div>
</section>
<section>
<!-- 'create identite' html form -->
<form id='creation' action='#' method='post' >
<table class='table_signup'>
<tr>
<td>Login</td>
<td><input type='text' name='login' class='form-control' required /></td>
</tr>
<tr>
<td>Password</td>
<td><input type='text' name='password' class='form-control' required /></td>
</tr>
<tr>
<td>Pseudo</td>
<td><input type='text' name='pseudo' class='form-control' required/></td>
</tr>
<tr>
<td>Age</td>
<td><input type='text' name='âge' class='form-control' required/></td>
</tr>
<tr>
<td>Poids(kg)</td>
<td><input type='text' name='poids' class='form-control' required/></td>
</tr>
<tr>
<td>Taille(cm)</td>
<td><input type='text' name='taille' class='form-control' required/></td>
</tr>
<tr>
<td>Sexe</td>
<td>
<label> Homme
<input type="radio" name="sexe" id="M">
</label><br>
<label> Femme
<input type="radio" name="sexe" id="F">
</label>
</td>
</tr>
<tr>
<td>Niveau de pratique sportive</td>
<td>
<label> Bas
<input type="radio" name="niveau_du_sport" id="bas">
</label><br>
<label> Moyen
<input type="radio" name="niveau_du_sport" id="moyen">
</label><br>
<label> Elevé
<input type="radio" name="niveau_du_sport" id="eleve">
</label>
</td>
</tr>
<form id="form_signup" action="#" method="POST" >
<div>
<label>Login</label>
<input type='text' id='login' name='login' class="form-control" required />
</div>
<div>
<label>Password</label>
<input type='text' id='password' name='password' class="form-control" required />
</div>
<div>
<label>Pseudo</label>
<input type='text' id='pseudo' name='pseudo' class="form-control" required/>
</div>
<div>
<label>Âge</label>
<input type='text' id='age' name='age' class="form-control" required />
</div>
<div>
<label>Poids(kg)</label>
<input type='text' id='poids' name='poids' class="form-control" required/>
</div>
<div>
<label>Taille(cm)</label>
<input type='text' id='taille' name='taille' class="form-control" required/>
</div>
<div class="form-group">
<label>Sexe</label>
<select class="form-control" id="sexe" name="sexe">
<option selected>Choisir...</option>
<option>Femme</option>
<option>Homme</option>
</select>
</div>
<div class="form-group">
<label>Niveau de sport</label>
<select class="form-control" id="niveaudusport" name="niveaudusport">
<option selected>Choisir...</option>
<option>Bas</option>
<option>Moyen</option>
<option>Elevé</option>
</select>
</div>
<!-- button to submit form -->
<tr>
<td></td>
<td>
<button type='submit' class='submit'>créer</button>
</td>
</tr>
</table>
</div>
<div class="form-action-buttons">
<input type="submit" value="Créer">
</div>
</form>
<script
src="https://code.jquery.com/jquery-3.4.1.min.js"
integrity="sha256-CSXorXvZcTkaix6Yvo6HppcZGetbYMGWSFlBw8HfCJo="
......@@ -85,7 +79,7 @@
$(document).ready( function($) {
// will run if create identite form was submitted
$(document).on('submit', '#creation', function(){
$(document).on('submit', '#form_signup', function(){
// get form data
var form_data=JSON.stringify($(this).serializeObject());
// console.log(form_data);
......@@ -95,10 +89,26 @@ $(document).ready( function($) {
url: "https://eden.imt-lille-douai.fr/~liang.wu/API_LOGIN/identite/create.php",
type : "POST",
contentType : 'application/json',
data : form_data
data : form_data,
success : function(result){
$('#response').html("<div class='alert alert-danger'>success.</div>");
},
error: function(xhr, resp, text){
// on error, tell the user login has failed & empty the input boxes
$('#response').html("<div class='alert alert-danger'>failed</div>");
login_form.find('input').val('');
}
});
});
});
</script>
</body>
</html>
\ No newline at end of file
</section>
<?php
require_once('template_footer.php');
?>
......@@ -3,7 +3,7 @@
// un tableau qui d\'efinit la structure du site
$mymenu = array(
// idPage titre
'index' => array( 'Accueil' ),
'home' => array( 'Accueil' ),
'profil_affichage' => array( 'Profil' ),
'profil_modif' => array( 'Modifier mon profil' ),
'aliments' => array('Aliments'),
......@@ -23,7 +23,7 @@ foreach($mymenu as $pageId => $pageParameters) {
$id="";
}
echo ' <li class="nav-item mx-0 mx-lg-1"><a class="nav-link py-3 px-0 px-lg-3 rounded js-scroll-trigger"'.$id.' href= "index.php?page='.$pageId.'">'.$pageParameters[0].'</a></li>';
echo ' <li class="nav-item mx-0 mx-lg-1"><a class="nav-link py-3 px-0 px-lg-3 rounded js-scroll-trigger"'.$id.' href= "home.php?page='.$pageId.'">'.$pageParameters[0].'</a></li>';
}
echo '</ul> </div> </div> </nav>';
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment