Maintenance Gitlab - Jeudi 09 Décembre 2021 à partir de 10h - Mises à jour de sécurité

Commit 087d88e9 authored by ALGLAVE Ivan's avatar ALGLAVE Ivan
Browse files

Connection / Deconnection and Account creation handled - TODO : style. Fixed...

Connection / Deconnection and Account creation handled - TODO : style. Fixed issues with favourites, which are now synced with the database and local favourites, and merged on creation
parent 941156ce
<!DOCTYPE html>
<html>
<head>
<title>Drinkpedia</title>
<meta charset="UTF-8">
<link rel="stylesheet" type="text/css" href="css/MyAccount.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
</head>
<body>
<h1>Connexion</h1>
<label>Email</label>
<input id="emailInput" type="email">
<label>Mot de passe</label>
<input id="pwdInput" type="password">
<button onclick="tryConnect();">Se connecter</button>
<label>Pas de compte ?</label>
<a onclick="goToCreate();">Créer</a>
<script src="scripts/DataQuery.js"></script>
<script>
function goToCreate()
{
var data = {
event: 'usercreate',
value: ''
};
window.top.postMessage(data, [data.event, data.value]);
}
function tryConnect()
{
let ei = document.getElementById('emailInput');
let pi = document.getElementById('pwdInput');
let email = ei.value;
let pwd = pi.value;
connect_user(email, pwd, function(e){
if(e == '1')
{
var data = {
event: 'useraccount',
value: e
};
window.top.postMessage(data, [data.event, data.value]);
}
else
{
alert('Mauvaise combinaison email/mot de passe');
}
});
}
</script>
</body>
</html>
\ No newline at end of file
<!DOCTYPE html>
<html>
<head>
<title>Drinkpedia</title>
<meta charset="UTF-8">
<link rel="stylesheet" type="text/css" href="css/MyAccount.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
</head>
<body>
<h1>Création d'un compte</h1>
<label>Email</label>
<input id="emailInput" type="email">
<label>Mot de passe</label>
<input id="pwdInput" type="password">
<button onclick="createAccount();">Créer mon compte</button>
<label>Déjà un compte ?</label>
<a onclick="goToConnect();">Se connecter</a>
<script src="scripts/DataQuery.js"></script>
<script>
function goToConnect()
{
var data = {
event: 'userconnect',
value: ''
};
window.top.postMessage(data, [data.event, data.value]);
}
function createAccount()
{
let ei = document.getElementById('emailInput');
let pi = document.getElementById('pwdInput');
let email = ei.value;
let pwd = pi.value;
create_user(email, pwd, function(e){
if(e == '1')
{
connect_user(email, pwd, function(j)
{
if(j == '0')
{
alert('Oops something went wrong');
}
else
{
var data = {
event: 'useraccount',
value: e
};
window.top.postMessage(data, [data.event, data.value]);
}
})
}
else
{
alert('Erreur - email déjà associé à un compte')
}
});
}
</script>
</body>
</html>
\ No newline at end of file
......@@ -13,7 +13,6 @@
<!-- PHP -->
<?php
// DEBUT DES ACTIONS SUR LA PAGE :
include "scripts/Functions.php";
......
......@@ -8,6 +8,12 @@
<body id="body">
<?php
include 'scripts/SQL.php';
//connect_db();
?>
<div class="background"></div>
<div id="content">
......@@ -73,6 +79,18 @@
setActiveTab('tabBtnI');
switchView('Hierarchy.php?element="' + m_value + '"');
}
else if(m_event == 'useraccount')
{
switchView('MyAccount.php');
}
else if(m_event == 'userconnect')
{
switchView('AccountConnection.php');
}
else if(m_event == 'usercreate')
{
switchView('AccountCreation.php');
}
}
function hideBlurred()
......@@ -132,8 +150,8 @@
function tabButtonClicked(b)
{
setActiveTab(b.id);
switchView(activeTabButton.value);
setActiveTab(b.id);
switchView(activeTabButton.value);
}
function startLoadingScreen()
......
......@@ -4,20 +4,51 @@
<title>Drinkpedia</title>
<meta charset="UTF-8">
<link rel="stylesheet" type="text/css" href="css/MyAccount.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
<script src="scripts/DataQuery.js"></script>
</head>
<body>
<script>
is_connected(function(e)
{
if(e == '0')
{
var data = {
event: 'userconnect',
value: e
};
window.top.postMessage(data, [data.event, data.value]);
}
});
</script>
<h1>My Account</h1>
<?php
include "scripts/SQL.php";
<label id="email"></label>
<button onclick="disconnect();">Se déconnecter</button>
<script>
let emailLabel = document.getElementById('email');
get_email(function(e){
emailLabel.innerHTML = 'Adresse email : ' + e;
});
function disconnect()
{
disconnect_user(function(f)
{
var data = {
event: 'userconnect',
value: ''
};
window.top.postMessage(data, [data.event, data.value]);
});
}
</script>
echo connect('ivanalglave@outlook.fr', '123');
echo '<br>';
echo get_email();
echo '<br>';
echo get_favourites();
?>
</body>
</html>
\ No newline at end of file
......@@ -9,16 +9,17 @@
<body>
<script src="scripts/DataQuery.js"></script>
<script>
getFavourites(function(e)
{
var data = {
event: 'recipelist',
value: e,
showScore: 'false',
title: 'Favoris :'
};
window.top.postMessage(data, [data.event, data.value, data.showScore, data.title]);
})
getFavourites(function(e)
{
var data = {
event: 'recipelist',
value: e,
showScore: 'false',
title: 'Favoris :'
};
window.top.postMessage(data, [data.event, data.value, data.showScore, data.title]);
})
</script>
</body>
......
......@@ -10,7 +10,6 @@
<body>
<?php
include "Donnees.inc.php";
include "scripts/Functions.php";
......@@ -84,17 +83,12 @@
function switchFavourite(img)
{
//let new_src = "images/favourite_off.png";
if(!img.classList.contains('favouriteOn'))
{
new_src = "images/favourite_on.png";
img.classList.add('favouriteOn');
img.classList.remove('favouriteOff');
/*let f = sessionStorage.getItem('favourites');
if(f != '') f += '|';
f += img.alt;
sessionStorage.setItem('favourites', f);*/
addFavourite(img.alt, function(e) {
refreshFavourites();
});
......@@ -103,50 +97,19 @@
{
img.classList.remove('favouriteOn');
img.classList.add('favouriteOff');
/*let f = sessionStorage.getItem('favourites').split('|');
let nf = '';
for(let i = 0; i < f.length; i++)
{
if(img.alt != f[i])
{
if(i != 0) nf += '|';
nf += f[i];
}
}*/
removeFavourite(img.alt, function(e){
refreshFavourites();
});
}
//img.src= new_src;
}
function refreshFavourites()
{
let collection = document.getElementsByClassName('toggleFavourite');
/*let favourites = sessionStorage.getItem('favourites').split('|');
for(let i = 0; i < collection.length; i++)
{
let node = collection[i];
let r_id = node.value;
if(favourites.findIndex(val => val == node.alt) >= 0)
{
node.classList.add('favouriteOn');
node.classList.remove('favouriteOff');
node.src = "images/favourite_on.png";
}
else
{
node.classList.add('favouriteOff');
node.classList.remove('favouriteOn');
node.src = "images/favourite_off.png";
}
}*/
getFavourites(function(e) {
let favourites = e;
let favourites = e.split('|');
for(let i = 0; i < collection.length; i++)
{
let node = collection[i];
......
<!-- HTML Fragment to display a recipe -->
<head>
<link rel="stylesheet" type="text/css" href="css/RecipeView.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
</head>
<body>
......@@ -46,6 +47,7 @@
</div>
<script src="scripts/DataQuery.js"></script>
<script>
document.addEventListener('keyup', function (e)
......@@ -60,58 +62,56 @@
}
});
function switchFavourite(img)
{
let new_src = "images/favourite_off.png";
if(!img.classList.contains('favouriteOn'))
function switchFavourite(img)
{
new_src = "images/favourite_on.png";
img.classList.add('favouriteOn');
img.classList.remove('favouriteOff');
let f = sessionStorage.getItem('favourites');
if(f != '') f += '|';
f += img.alt;
sessionStorage.setItem('favourites', f);
if(!img.classList.contains('favouriteOn'))
{
new_src = "images/favourite_on.png";
img.classList.add('favouriteOn');
img.classList.remove('favouriteOff');
addFavourite(img.alt, function(e) {
refreshFavourites();
});
}
else
{
img.classList.remove('favouriteOn');
img.classList.add('favouriteOff');
removeFavourite(img.alt, function(e){
refreshFavourites();
});
}
}
else
function refreshFavourites()
{
img.classList.remove('favouriteOn');
img.classList.add('favouriteOff');
let collection = document.getElementsByClassName('toggleFavourite');
let f = sessionStorage.getItem('favourites').split('|');
let nf = '';
for(let i = 0; i < f.length; i++)
{
if(img.alt != f[i])
getFavourites(function(e) {
let favourites = e.split('|');
for(let i = 0; i < collection.length; i++)
{
if(i == 0) nf += '|';
nf += f[i];
let node = collection[i];
let r_id = node.value;
if(favourites.findIndex(val => val == node.alt) >= 0)
{
node.classList.add('favouriteOn');
node.classList.remove('favouriteOff');
node.src = "images/favourite_on.png";
}
else
{
node.classList.add('favouriteOff');
node.classList.remove('favouriteOn');
node.src = "images/favourite_off.png";
}
}
}
sessionStorage.setItem('favourites', nf);
})
}
img.src= new_src;
}
let collection = document.getElementsByClassName('toggleFavourite');
let favourites = sessionStorage.getItem('favourites').split('|');
for(let i = 0; i < collection.length; i++)
{
let node = collection[i];
let r_id = node.value;
if(favourites.findIndex(val => val == node.alt) >= 0)
{
node.classList.add('favouriteOn');
node.src = "images/favourite_on.png";
}
else
{
node.classList.add('favouriteOff');
node.src = "images/favourite_off.png";
}
}
refreshFavourites();
</script>
</body>
\ No newline at end of file
......@@ -10,7 +10,6 @@
<body>
<script src="scripts/DataQuery.js"></script>
<script>
getRecipes([], [], 0, true, true, function(e) {
var data = {
event: 'recipelist',
......
......@@ -25,14 +25,25 @@ function getAllIngredients(callback)
query('getAllIngredients', [], callback);
}
function connect_db(callback)
{
query('connect_db', [], callback);
}
function create_user(u_email, u_pwd, callback)
{
query('create_user', [u_email, u_pwd], callback);
}
function connect(u_email, u_pwd, callback)
function connect_user(u_email, u_pwd, callback)
{
query('connect_user', [u_email, u_pwd], callback);
}
function disconnect_user(callback)
{
query('connect', [u_email, u_pwd], callback);
sessionStorage.setItem('favourites', '');
query('disconnect_user', [], callback);
}
function is_connected(callback)
......@@ -62,18 +73,31 @@ function set_password(u_newpwd, callback)
function getFavourites(callback)
{
is_connected(function(e)
get_favourites(function(f)
{
alert('Connected : ' + (e ? 'true' : 'false'));
let localFavourites = sessionStorage.getItem('favourites').split('|');
let dbFavourites = f.split('|');
let res = (dbFavourites == '' ? localFavourites : joinCheckDuplicates(localFavourites, dbFavourites));
get_favourites(function(f)
var resultStr = '';
let first = true;
for(let i = 0; i < res.length; i++)
{
let localFavourites = sessionStorage.getItem('favourites').split('|');
let dbFavourites = f.split('|');
let res = joinCheckDuplicates(localFavourites, dbFavourites);
callback(res);
if(res[i] != '')
{
if(!first) resultStr += '|';
else first = false;
resultStr += res[i];
}
}
sessionStorage.setItem('favourites', resultStr);
set_favourites(resultStr, function(g) {
callback(resultStr);
});
})
});
}
function joinCheckDuplicates(e1, e2)
......@@ -83,7 +107,9 @@ function joinCheckDuplicates(e1, e2)
{
if(e3.indexOf(e2[i]) < 0) e3.push(e2[i]);
}
return e3;
return e3.sort(function(a, b) {
return a - b;
});
}
function addFavourite(id, callback)
......@@ -92,11 +118,12 @@ function addFavourite(id, callback)
{
let localFavourites = sessionStorage.getItem('favourites').split('|');
let dbFavourites = f.split('|');
let res = joinCheckDuplicates(localFavourites, dbFavourites);
let res = (dbFavourites == '' ? localFavourites : joinCheckDuplicates(localFavourites, dbFavourites));
let indexOfTest = res.indexOf(id);
if(indexOfTest < 0) res.push(id);
let resultStr = '';
var resultStr = '';
let first = true;
for(let i = 0; i < res.length; i++)
......@@ -108,12 +135,15 @@ function addFavourite(id, callback)
resultStr += res[i];
}
}
//alert(sessionStorage.getItem('favourites') + ' ~ ' + f + ' + ' + id + ' => ' + resultStr);
sessionStorage.setItem('favourites', resultStr);
set_favourites(function(g) {
set_favourites(resultStr, function(g) {
//alert('New favourites : ' + g);
callback(resultStr);
})
});
});
}
......@@ -123,11 +153,12 @@ function removeFavourite(id, callback)
{
let localFavourites = sessionStorage.getItem('favourites').split('|');
let dbFavourites = f.split('|');
let res = joinCheckDuplicates(localFavourites, dbFavourites);
let res = (dbFavourites == '' ? localFavourites : joinCheckDuplicates(localFavourites, dbFavourites));
res.sort();
let indexOfToRemove = res.indexOf(id);
if(indexOfToRemove >= 0) res.splice(indexOfToRemove, 1);
let resultStr = '';
var resultStr = '';
let first = true;
for(let i = 0; i < res.length; i++)
......@@ -135,14 +166,18 @@ function removeFavourite(id, callback)
if(res[i] != '')
{
if(!first) resultStr += '|';
else first = false;
resultStr += res[i];
}
}
//alert(sessionStorage.getItem('favourites') + ' ~ ' + f + ' - ' + id + ' => ' + resultStr);
sessionStorage.setItem('favourites', resultStr);
set_favourites(function(g) {
set_favourites(resultStr, function(g) {
//alert('New favourites : ' + g);
callback(resultStr);
})
});
});
}
\ No newline at end of file
......@@ -27,13 +27,21 @@
{
echo implode('|', getAllIngredients());
}
else if($funcName == 'connect_db')
{
echo connect_db();
}
else if($funcName == 'create_user')
{
echo create_user($_POST['arguments'][