Merge branch 'unstable' of https://github.com/jsmaniac/2011-m1s2-ter into unstable
This commit is contained in:
commit
0f231d80ab
|
@ -24,14 +24,14 @@ public class Network {
|
||||||
|
|
||||||
public static class Check implements Serializable {
|
public static class Check implements Serializable {
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
private boolean login_ok = false;
|
private boolean loginOk = false;
|
||||||
|
|
||||||
public boolean isLogin_ok() {
|
public boolean isLoginOk() {
|
||||||
return login_ok;
|
return loginOk;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setLogin_ok(boolean login_ok) {
|
public void setLoginOk(boolean loginOk) {
|
||||||
this.login_ok = login_ok;
|
this.loginOk = loginOk;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -97,7 +97,7 @@ public class Network {
|
||||||
json = HttpClient.SendHttpPost(urlS);
|
json = HttpClient.SendHttpPost(urlS);
|
||||||
|
|
||||||
Check check = gson.fromJson(json, Check.class);
|
Check check = gson.fromJson(json, Check.class);
|
||||||
res = check.isLogin_ok();
|
res = check.isLoginOk();
|
||||||
|
|
||||||
SharedPreferences.Editor editor = sp.edit();
|
SharedPreferences.Editor editor = sp.edit();
|
||||||
editor.putBoolean(Constant.SERVER_AUTH, res);
|
editor.putBoolean(Constant.SERVER_AUTH, res);
|
||||||
|
|
|
@ -84,7 +84,7 @@ html, body {
|
||||||
<div><img class="icon" alt="" src="ressources/img/72/default.png" /></div>
|
<div><img class="icon" alt="" src="ressources/img/72/default.png" /></div>
|
||||||
<div class="text">Connexion</div>
|
<div class="text">Connexion</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="frontpage-button about">
|
<div class="frontpage-button info">
|
||||||
<div><img class="icon" alt="" src="ressources/img/72/default.png" /></div>
|
<div><img class="icon" alt="" src="ressources/img/72/default.png" /></div>
|
||||||
<div class="text">A Propos</div>
|
<div class="text">A Propos</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -94,6 +94,49 @@ html, body {
|
||||||
<div class="scores"></div>
|
<div class="scores"></div>
|
||||||
<input type="button" value="J'ai vu !" id="jaivu"/>
|
<input type="button" value="J'ai vu !" id="jaivu"/>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="screen" id="connection">
|
||||||
|
<form id="connect-form" action="#" method="GET">
|
||||||
|
<label id="user-label" for="user">Login : </label>
|
||||||
|
<input type="text" name="user" id="user" />
|
||||||
|
<label id="passwd-label" for="passwd">Mot de passe : </label>
|
||||||
|
<input type="password" name="passwd" id="passwd" />
|
||||||
|
<input type="submit" name="connect" id="connect" value="Se connecter" />
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
<div class="screen" id="info">
|
||||||
|
<div class="container">
|
||||||
|
<p>
|
||||||
|
PtiClic a été conçu et développé par Mathieu Lafourcade
|
||||||
|
(LIRMM - Université Montpellier 2) et Virginie Zampa
|
||||||
|
(LIDILEM - Université Stendhal Grenoble 3)
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
La présente version pour SmartPhone sous Android, en cours
|
||||||
|
de développement a été conçue et réalisée par des
|
||||||
|
étudiants en Master 1 à l'Université Montpellier II :
|
||||||
|
Yoann BONAVERO, Bertrand BRUN, John CHARRON et
|
||||||
|
Georges DUPÉRON.
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
Cette version du PtiClic est une version Alpha. Elle n'est
|
||||||
|
pas exempte de bogues.
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
Si vous souhaitez participer au projet en tant que
|
||||||
|
Bêta-testeur, rendez-vous sur le site
|
||||||
|
<a href="http://pticlic.fr/">http://pticlic.fr</a>
|
||||||
|
pour vous y inscrire.
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
Si vous souhaitez signaler des bogues ou nous faire part
|
||||||
|
de vos commentaires, vous pouvez nous contacter par
|
||||||
|
courriel à l'adresse suivante : <a href="mailto:pticlic.android.beta@gmail.com">pticlic.android.beta@gmail.com</a>
|
||||||
|
</p>
|
||||||
|
<p id="info-back-p">
|
||||||
|
<input id="info-back" type="button" value="Retour" />
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
<div id="templates" style="display: none;">
|
<div id="templates" style="display: none;">
|
||||||
<div class="relationBox">
|
<div class="relationBox">
|
||||||
<div class="relation"><img class="icon" alt="" src="ressources/img/72/default.png" /><span class="text"></span></div>
|
<div class="relation"><img class="icon" alt="" src="ressources/img/72/default.png" /><span class="text"></span></div>
|
||||||
|
@ -105,3 +148,4 @@ html, body {
|
||||||
</div>
|
</div>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
<html>
|
||||||
|
|
|
@ -40,7 +40,10 @@ require_once("ressources/db.inc");
|
||||||
function checkLogin($user, $passwd) {
|
function checkLogin($user, $passwd) {
|
||||||
if(isset($_SESSION['userId']))
|
if(isset($_SESSION['userId']))
|
||||||
return true;
|
return true;
|
||||||
|
connect($user, $passwd);
|
||||||
|
}
|
||||||
|
|
||||||
|
function connect($user, $passwd) {
|
||||||
$db = getDB();
|
$db = getDB();
|
||||||
$hashPasswd = md5($passwd);
|
$hashPasswd = md5($passwd);
|
||||||
$loginIsOk = ($hashPasswd == $db->querySingle("SELECT hash_passwd FROM user WHERE login='".$user."';"));
|
$loginIsOk = ($hashPasswd == $db->querySingle("SELECT hash_passwd FROM user WHERE login='".$user."';"));
|
||||||
|
@ -752,7 +755,6 @@ function insertNode($node) {
|
||||||
/** retourne l'eid d'un mot.
|
/** retourne l'eid d'un mot.
|
||||||
* @param node : le mot dont on veut obtenir l'eid.
|
* @param node : le mot dont on veut obtenir l'eid.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
function getNodeEid($node) {
|
function getNodeEid($node) {
|
||||||
$db = getDB();
|
$db = getDB();
|
||||||
|
|
||||||
|
|
|
@ -45,27 +45,30 @@ $.fn.sumHeight = function() {
|
||||||
} catch(e) {alert("Error sumHeight");alert(e);}
|
} catch(e) {alert("Error sumHeight");alert(e);}
|
||||||
}
|
}
|
||||||
|
|
||||||
$.fn.fitFont = function(w, h, minFont, maxFont) {
|
$.fn.fitFont = function(w, h, minFont, maxFont, noContainer) {
|
||||||
try {
|
try {
|
||||||
var oldpos = this.css("position");
|
var oldpos = this.css("position");
|
||||||
this.css({
|
this.css({
|
||||||
position: "absolute",
|
position: "absolute",
|
||||||
maxWidth: w
|
maxWidth: w
|
||||||
});
|
});
|
||||||
|
if (noContainer) {
|
||||||
|
var wrappers = this;
|
||||||
|
} else {
|
||||||
var wrappers = this.wrapInner("<span/>").children();
|
var wrappers = this.wrapInner("<span/>").children();
|
||||||
|
}
|
||||||
|
|
||||||
var that = this;
|
var that = this;
|
||||||
this.css("font-size", dichotomy(parseInt(this.css("font-size"), 10), function(x) {
|
this.css("font-size", dichotomy(parseInt(this.css("font-size"), 10), function(x) {
|
||||||
try {
|
try {
|
||||||
that.css("fontSize", x);
|
that.css("fontSize", x);
|
||||||
fubar = wrappers;
|
|
||||||
return (wrappers.maxHeight() > h || wrappers.maxWidth() > w);
|
return (wrappers.maxHeight() > h || wrappers.maxWidth() > w);
|
||||||
} catch(e) {alert("Error anonymous in $.fn.fitFont");alert(e);}
|
} catch(e) {alert("Error anonymous in $.fn.fitFont");alert(e);}
|
||||||
},this).clip(minFont || 0, maxFont || Infinity));
|
},this).clip(minFont || 0, maxFont || Infinity));
|
||||||
|
|
||||||
// Restore stuff
|
// Restore stuff
|
||||||
this.css("position", oldpos);
|
this.css("position", oldpos);
|
||||||
//wrappers.children().unwrap();
|
if (!noContainer) wrappers.children().unwrap();
|
||||||
return this;
|
return this;
|
||||||
} catch(e) {alert("Error $.fn.fitFont");alert(e);}
|
} catch(e) {alert("Error $.fn.fitFont");alert(e);}
|
||||||
}
|
}
|
||||||
|
|
|
@ -64,7 +64,7 @@ function jss() {
|
||||||
else if(h > 500) iconSize = 48;
|
else if(h > 500) iconSize = 48;
|
||||||
else iconSize = 36;
|
else iconSize = 36;
|
||||||
|
|
||||||
$("#"+"state.screen"+".screen")
|
$("#"+state.screen+".screen")
|
||||||
.wh(w, h)
|
.wh(w, h)
|
||||||
.northWest({top:0,left:0});
|
.northWest({top:0,left:0});
|
||||||
|
|
||||||
|
@ -124,14 +124,58 @@ $(function() {
|
||||||
} catch(e) {alert("Error main function");alert(e);}
|
} catch(e) {alert("Error main function");alert(e);}
|
||||||
});
|
});
|
||||||
|
|
||||||
function ajaxError(x) {
|
// ==== Asynchronous Javascript And Json.
|
||||||
|
ajaj = {};
|
||||||
|
ajaj.request = function(url, data, okFunction, smallErrorFunction, bigErrorFunction) {
|
||||||
|
smallErrorFunction = smallErrorFunction || ajaj.smallError;
|
||||||
|
bigErrorFunction = bigErrorFunction || ajaj.bigError;
|
||||||
|
var user = UI().getPreference("user");
|
||||||
|
var passwd = UI().getPreference("passwd");
|
||||||
|
if (user != '' && passwd != '') {
|
||||||
|
// TODO : on transfère le user/passwd à chaque fois ici… c'est pas très bon.
|
||||||
|
data = $.extend({user:user, passwd:passwd}, data);
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
return $.getJSON(url, data, function(data) {
|
||||||
|
if (data && data.isError) {
|
||||||
|
smallErrorFunction(data);
|
||||||
|
} else {
|
||||||
|
okFunction(data);
|
||||||
|
}
|
||||||
|
}).error(bigErrorFunction);
|
||||||
|
} catch(e) {alert("Error ajaj.request");alert(e);}
|
||||||
|
}
|
||||||
|
ajaj.smallError = function(x) {
|
||||||
|
try {
|
||||||
|
if (x.error == 10) {
|
||||||
|
state.set('screen', 'connection').commit().validate();
|
||||||
|
} else {
|
||||||
|
ajaj.error(
|
||||||
|
"Erreur fatale. Merci de nous envoyer ce message : \n"
|
||||||
|
+ "Erreur signalée par le serveur\n"
|
||||||
|
+ "Code:"+x.error+"\n"
|
||||||
|
+ "Message:"+x.msg+"\n"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
} catch(e) {alert("Error ajaj.smallError");alert(e);}
|
||||||
|
}
|
||||||
|
ajaj.bigError = function(x) {
|
||||||
|
try {
|
||||||
|
ajaj.error(
|
||||||
|
"Erreur fatale. Merci de nous envoyer ce message : \n"
|
||||||
|
+ "Erreur de transmission\n"
|
||||||
|
+ "Code:"+x.status+"\n"
|
||||||
|
+ "État:"+x.statusText+"\n"
|
||||||
|
+ "Message:"+x.responseText.substring(0,20)+" ("+x.responseText.length+")"
|
||||||
|
);
|
||||||
|
} catch(e) {alert("Error ajaj.bigError");alert(e);}
|
||||||
|
}
|
||||||
|
ajaj.error = function(msg) {
|
||||||
try {
|
try {
|
||||||
UI().dismiss();
|
UI().dismiss();
|
||||||
var msg = "Erreur fatale. Merci de nous envoyer ce message : ";
|
|
||||||
msg += x.status+" - "+x.statusText+"\n"+x.responseText.substring(0,20)+((x.responseText == '') ? '': '…');
|
|
||||||
alert(msg);
|
alert(msg);
|
||||||
UI().exit();
|
UI().exit();
|
||||||
} catch(e) {alert("Error ajaxError");alert(e);}
|
} catch(e) {alert("Error ajaj.error");alert(e);}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ==== Code métier pour le splash
|
// ==== Code métier pour le splash
|
||||||
|
@ -205,7 +249,7 @@ frontpage.jss = function(w, h, iconSize) {
|
||||||
$fp(".game .icon").data('image', 'mode_normal');
|
$fp(".game .icon").data('image', 'mode_normal');
|
||||||
$fp(".prefs .icon").data('image', 'config');
|
$fp(".prefs .icon").data('image', 'config');
|
||||||
$fp(".connection .icon").data('image', 'config');
|
$fp(".connection .icon").data('image', 'config');
|
||||||
$fp(".about .icon").data('image', 'aide');
|
$fp(".info .icon").data('image', 'aide');
|
||||||
|
|
||||||
$fp(".frontpage-button")
|
$fp(".frontpage-button")
|
||||||
.css('text-align', 'center')
|
.css('text-align', 'center')
|
||||||
|
@ -233,19 +277,36 @@ frontpage.jss = function(w, h, iconSize) {
|
||||||
frontpage.enter = function () {
|
frontpage.enter = function () {
|
||||||
try {
|
try {
|
||||||
if (location.hash != '') state.commit();
|
if (location.hash != '') state.commit();
|
||||||
$("#frontpage .frontpage-button.game").clickOnce(frontpage.click.game);
|
$("#frontpage .frontpage-button.game").clickOnce(frontpage.click.goGame);
|
||||||
|
$("#frontpage .frontpage-button.connection").clickOnce(frontpage.click.goConnection);
|
||||||
|
$("#frontpage .frontpage-button.info").clickOnce(frontpage.click.goInfo);
|
||||||
jss();
|
jss();
|
||||||
UI().dismiss();
|
UI().dismiss();
|
||||||
} catch(e) {alert("Error frontpage.enter");alert(e);}
|
} catch(e) {alert("Error frontpage.enter");alert(e);}
|
||||||
};
|
};
|
||||||
|
|
||||||
frontpage.click = {};
|
frontpage.click = {};
|
||||||
frontpage.click.game = function(){
|
frontpage.click.goGame = function(){
|
||||||
try {
|
try {
|
||||||
state.set('screen', 'game').validate();
|
state.set('screen', 'game').validate();
|
||||||
} catch(e) {alert("Error frontpage.click.game");alert(e);}
|
} catch(e) {alert("Error frontpage.click.goGame");alert(e);}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
frontpage.click.goConnection = function() {
|
||||||
|
try {
|
||||||
|
UI().show("PtiClic", "Chargement…");
|
||||||
|
state.set('screen', 'connection').commit().validate();
|
||||||
|
} catch(e) {alert("Error frontpage.click.goConnection");alert(e);}
|
||||||
|
};
|
||||||
|
|
||||||
|
frontpage.click.goInfo = function() {
|
||||||
|
try {
|
||||||
|
UI().show("PtiClic", "Chargement…");
|
||||||
|
state.set('screen', 'info').commit().validate();
|
||||||
|
} catch(e) {alert("Error frontpage.click.goInfo");alert(e);}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
// ==== Code métier pour le jeu
|
// ==== Code métier pour le jeu
|
||||||
game = {};
|
game = {};
|
||||||
|
|
||||||
|
@ -315,9 +376,7 @@ game.enter = function () {
|
||||||
};
|
};
|
||||||
if (notAlreadyFetching) {
|
if (notAlreadyFetching) {
|
||||||
UI().show("PtiClic", "Récupération de la partie");
|
UI().show("PtiClic", "Récupération de la partie");
|
||||||
$.getJSON("getGame.php?callback=?", {
|
ajaj.request("getGame.php?callback=?", {
|
||||||
user:"foo",
|
|
||||||
passwd:"bar",
|
|
||||||
nonce:Math.random()
|
nonce:Math.random()
|
||||||
}, function(data) {
|
}, function(data) {
|
||||||
try {
|
try {
|
||||||
|
@ -325,7 +384,7 @@ game.enter = function () {
|
||||||
runstate.gameFetched = false;
|
runstate.gameFetched = false;
|
||||||
fn(data);
|
fn(data);
|
||||||
} catch(e) {alert("Error anonymous 2 in game.enter");alert(e);}
|
} catch(e) {alert("Error anonymous 2 in game.enter");alert(e);}
|
||||||
}).error(ajaxError);
|
});
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
game.buildUi();
|
game.buildUi();
|
||||||
|
@ -429,7 +488,7 @@ score = {};
|
||||||
|
|
||||||
score.jss = function(w, h, iconSize) {
|
score.jss = function(w, h, iconSize) {
|
||||||
try {
|
try {
|
||||||
$(".screen")
|
$("#score.screen")
|
||||||
.css('text-align', 'center');
|
.css('text-align', 'center');
|
||||||
} catch(e) {alert("Error score.jss");alert(e);}
|
} catch(e) {alert("Error score.jss");alert(e);}
|
||||||
};
|
};
|
||||||
|
@ -452,9 +511,7 @@ score.enter = function () {
|
||||||
};
|
};
|
||||||
if (notAlreadyFetching) {
|
if (notAlreadyFetching) {
|
||||||
UI().show("PtiClic", "Calcul de votre score");
|
UI().show("PtiClic", "Calcul de votre score");
|
||||||
$.getJSON("server.php?callback=?", {
|
ajaj.request("server.php?callback=?", {
|
||||||
user: "foo",
|
|
||||||
passwd: "bar",
|
|
||||||
action: 1,
|
action: 1,
|
||||||
pgid: state.game.pgid,
|
pgid: state.game.pgid,
|
||||||
gid: state.game.gid,
|
gid: state.game.gid,
|
||||||
|
@ -466,7 +523,7 @@ score.enter = function () {
|
||||||
runstate.scoreFetched = false;
|
runstate.scoreFetched = false;
|
||||||
fn(data);
|
fn(data);
|
||||||
} catch(e) {alert("Error anonymous 2 in score.enter");alert(e);}
|
} catch(e) {alert("Error anonymous 2 in score.enter");alert(e);}
|
||||||
}).error(ajaxError);
|
});
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
score.ui();
|
score.ui();
|
||||||
|
@ -515,3 +572,88 @@ score.click.jaivu = function() {
|
||||||
state = new State().validate();
|
state = new State().validate();
|
||||||
} catch(e) {alert("Error score.click.jaivu");alert(e);}
|
} catch(e) {alert("Error score.click.jaivu");alert(e);}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// ==== Code métier pour la connexion
|
||||||
|
connection = {};
|
||||||
|
|
||||||
|
connection.jss = function(w, h, iconSize) {
|
||||||
|
try {
|
||||||
|
var c = $("#connection.screen");
|
||||||
|
var $c = function() {
|
||||||
|
try {
|
||||||
|
return c.find.apply(c,arguments);
|
||||||
|
} catch(e) {alert("Error anonymous 1 in connection.jss");alert(e);}
|
||||||
|
};
|
||||||
|
|
||||||
|
(c)
|
||||||
|
.css('text-align', 'center');
|
||||||
|
|
||||||
|
$c("label")
|
||||||
|
.css("white-space", "nowrap");
|
||||||
|
$c("input, label")
|
||||||
|
.css('position', 'absolute')
|
||||||
|
.fitFont(w*0.3, h*0.25);
|
||||||
|
$c("#user-label").east({left:w/2,top:h*0.25});
|
||||||
|
$c("#user").west({left:w/2,top:h*0.25});
|
||||||
|
$c("#passwd-label").east({left:w/2,top:h*0.5});
|
||||||
|
$c("#passwd").west({left:w/2,top:h*0.5});
|
||||||
|
$c("#connect").center({left:w/2,top:h*0.75});
|
||||||
|
} catch(e) {alert("Error connection.jss");alert(e);}
|
||||||
|
};
|
||||||
|
|
||||||
|
connection.enter = function() {
|
||||||
|
try {
|
||||||
|
jss();
|
||||||
|
$("#connect-form").unbind("submit", connection.connect).submit(connection.connect);
|
||||||
|
UI().dismiss();
|
||||||
|
} catch(e) {alert("Error connection.enter");alert(e);}
|
||||||
|
};
|
||||||
|
|
||||||
|
connection.connect = function() {
|
||||||
|
try {
|
||||||
|
UI().setPreference("user", $("#user").val());
|
||||||
|
UI().setPreference("passwd", $("#passwd").val());
|
||||||
|
ajaj.request("server.php?callback=?", {
|
||||||
|
action: 3,
|
||||||
|
user: $("#user").val(),
|
||||||
|
passwd: $("#passwd").val(),
|
||||||
|
}, connection.connectFetched, connection.connectFetched);
|
||||||
|
return false
|
||||||
|
} catch(e) {alert("Error connection.connect");alert(e);}
|
||||||
|
}
|
||||||
|
|
||||||
|
connection.connectFetched = function(data) {
|
||||||
|
try {
|
||||||
|
if (data && data.loginOk) {
|
||||||
|
alert("Vous êtes connecté !");
|
||||||
|
} else if (data && data.isError && data.error == 3) {
|
||||||
|
alert(data.msg);
|
||||||
|
} else {
|
||||||
|
ajaj.smallError(data);
|
||||||
|
}
|
||||||
|
state.set('screen', 'frontpage').validate();
|
||||||
|
} catch(e) {alert("Error connection.connectFetched");alert(e);}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ==== Code métier pour la page d'info
|
||||||
|
info = {};
|
||||||
|
|
||||||
|
info.jss = function(w,h,iconSize) {
|
||||||
|
$("#info-back-p").css('text-align', 'center');
|
||||||
|
$("#info.screen .container input").css('font-size', 'inherit');
|
||||||
|
$("#info.screen .container")
|
||||||
|
.fitFont(w*0.9, h*0.9, null, null, true)
|
||||||
|
.center($("#info.screen"));
|
||||||
|
}
|
||||||
|
|
||||||
|
info.enter = function() {
|
||||||
|
try {
|
||||||
|
jss();
|
||||||
|
$("#info-back").clickOnce(function(){
|
||||||
|
try {
|
||||||
|
state.set('screen', 'frontpage').validate();
|
||||||
|
} catch(e) {alert("Error anonymous in info.enter");alert(e);}
|
||||||
|
});
|
||||||
|
UI().dismiss();
|
||||||
|
} catch(e) {alert("Error info.enter");alert(e);}
|
||||||
|
};
|
||||||
|
|
|
@ -31,27 +31,38 @@ function logError($errNum, $msg, $other="")
|
||||||
*/
|
*/
|
||||||
function main()
|
function main()
|
||||||
{
|
{
|
||||||
if(!isset($_GET['action']))
|
$loginIsOk = false;
|
||||||
throw new Exception("La requête est incomplète", 2);
|
$user = 'nobody';
|
||||||
else if(!isset($_SESSION['userId']) && (!isset($_GET['user']) || !isset($_GET['passwd'])))
|
if(!isset($_GET['action'])) {
|
||||||
throw new Exception("La requête est incomplète", 2);
|
throw new Exception("La requête est incomplète.", 2);
|
||||||
else if(isset($_SESSION['userId'])) {
|
}
|
||||||
|
if(isset($_GET['user']) && isset($_GET['passwd'])) {
|
||||||
|
unset($_SESSION['userId']);
|
||||||
|
$user = SQLite3::escapeString($_GET['user']);
|
||||||
|
$loginIsOk = connect($user, $_GET['passwd']);
|
||||||
|
if ($loginIsOk) {
|
||||||
|
$_SESSION['userId'] = $user;
|
||||||
|
} else {
|
||||||
|
throw new Exception("Utilisateur non enregistré ou mauvais mot de passe.", 3);
|
||||||
|
}
|
||||||
|
} elseif(isset($_SESSION['userId'])) {
|
||||||
$user = $_SESSION['userId'];
|
$user = $_SESSION['userId'];
|
||||||
$loginIsOk = true;
|
$loginIsOk = true;
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
$user = SQLite3::escapeString($_GET['user']);
|
|
||||||
$loginIsOk = checkLogin($user, $_GET['passwd']);
|
|
||||||
}
|
|
||||||
|
|
||||||
$action = $_GET['action'];
|
$action = $_GET['action'];
|
||||||
|
|
||||||
if ($action != 3 && (!$loginIsOk)) {
|
if ($action != 3 && (!$loginIsOk)) {
|
||||||
throw new Exception("Utilisateur non enregistré ou mauvais mot de passe", 3);
|
throw new Exception("Vous n'êtes pas connecté.", 10);
|
||||||
}
|
}
|
||||||
if ($action == 3) {
|
if ($action == 3) {
|
||||||
echo '{"login_ok":' . ($loginIsOk ? 'true' : 'false') . '}';
|
echo json_encode(
|
||||||
exit;
|
Array(
|
||||||
|
"loginOk" => !!$loginIsOk,
|
||||||
|
"whoami" => "".$user
|
||||||
|
)
|
||||||
|
);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Sinon tout est bon on effectue l'opération correspondant à la commande passée.
|
// Sinon tout est bon on effectue l'opération correspondant à la commande passée.
|
||||||
|
@ -78,7 +89,7 @@ function main()
|
||||||
setGameGetScore($user, $_GET['pgid'], $_GET['gid'], $_GET['answers']);
|
setGameGetScore($user, $_GET['pgid'], $_GET['gid'], $_GET['answers']);
|
||||||
} else if($action == 4) { // CheckWord
|
} else if($action == 4) { // CheckWord
|
||||||
if (!isset($_GET['word']))
|
if (!isset($_GET['word']))
|
||||||
errRequestIncomplete();
|
throw new Exception("La requête est incomplète", 2);
|
||||||
|
|
||||||
if(wordExist($_GET['word']))
|
if(wordExist($_GET['word']))
|
||||||
echo "true";
|
echo "true";
|
||||||
|
@ -90,13 +101,13 @@ function main()
|
||||||
}
|
}
|
||||||
else if($action == 6) {
|
else if($action == 6) {
|
||||||
if (!isset($_GET['game']))
|
if (!isset($_GET['game']))
|
||||||
errRequestIncomplete();
|
throw new Exception("La requête est incomplète", 2);
|
||||||
|
|
||||||
decodeAndInsertGame($user,$_GET['game']);
|
decodeAndInsertGame($user,$_GET['game']);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
throw new Exception("Commande inconnue", 2);
|
throw new Exception("Commande inconnue", 2);
|
||||||
}
|
}
|
||||||
|
// Attention, il y a une $action == 7, mais plus haut.
|
||||||
}
|
}
|
||||||
|
|
||||||
function server() {
|
function server() {
|
||||||
|
@ -108,7 +119,13 @@ function server() {
|
||||||
ob_end_flush();
|
ob_end_flush();
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
ob_end_clean();
|
ob_end_clean();
|
||||||
echo "{\"error\":".$e->getCode().",\"msg\":".json_encode("".$e->getMessage())."}";
|
echo json_encode(
|
||||||
|
Array(
|
||||||
|
"error" => $e->getCode(),
|
||||||
|
"msg" => "".$e->getMessage(),
|
||||||
|
"isError" => true
|
||||||
|
)
|
||||||
|
);
|
||||||
logError($e->getCode(), $e->getMessage(), date("c"));
|
logError($e->getCode(), $e->getMessage(), date("c"));
|
||||||
closeDB();
|
closeDB();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user