commit 0f231d80abdd6af85fd01a6bea665a21b6e1dd14
parent 05920d224f53a5a7c4bb6f1b8059f27f652fc150
Author: Bertrand BRUN <bertrand0brun@gmail.com>
Date: Sat, 7 May 2011 21:33:02 +0200
Merge branch 'unstable' of https://github.com/jsmaniac/2011-m1s2-ter into unstable
Diffstat:
6 files changed, 255 insertions(+), 47 deletions(-)
diff --git a/code/PtiClic/src/org/pticlic/model/Network.java b/code/PtiClic/src/org/pticlic/model/Network.java
@@ -24,14 +24,14 @@ public class Network {
public static class Check implements Serializable {
private static final long serialVersionUID = 1L;
- private boolean login_ok = false;
+ private boolean loginOk = false;
- public boolean isLogin_ok() {
- return login_ok;
+ public boolean isLoginOk() {
+ return loginOk;
}
- public void setLogin_ok(boolean login_ok) {
- this.login_ok = login_ok;
+ public void setLoginOk(boolean loginOk) {
+ this.loginOk = loginOk;
}
}
@@ -97,7 +97,7 @@ public class Network {
json = HttpClient.SendHttpPost(urlS);
Check check = gson.fromJson(json, Check.class);
- res = check.isLogin_ok();
+ res = check.isLoginOk();
SharedPreferences.Editor editor = sp.edit();
editor.putBoolean(Constant.SERVER_AUTH, res);
diff --git a/code/serveur/php/jeu.html b/code/serveur/php/jeu.html
@@ -84,7 +84,7 @@ html, body {
<div><img class="icon" alt="" src="ressources/img/72/default.png" /></div>
<div class="text">Connexion</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 class="text">A Propos</div>
</div>
@@ -94,6 +94,49 @@ html, body {
<div class="scores"></div>
<input type="button" value="J'ai vu !" id="jaivu"/>
</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 class="relationBox">
<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>
</body>
</html>
+<html>
diff --git a/code/serveur/php/ressources/backend.inc b/code/serveur/php/ressources/backend.inc
@@ -40,7 +40,10 @@ require_once("ressources/db.inc");
function checkLogin($user, $passwd) {
if(isset($_SESSION['userId']))
return true;
-
+ connect($user, $passwd);
+}
+
+function connect($user, $passwd) {
$db = getDB();
$hashPasswd = md5($passwd);
$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.
* @param node : le mot dont on veut obtenir l'eid.
*/
-
function getNodeEid($node) {
$db = getDB();
diff --git a/code/serveur/php/ressources/my-extensions.js b/code/serveur/php/ressources/my-extensions.js
@@ -45,27 +45,30 @@ $.fn.sumHeight = function() {
} catch(e) {alert("Error sumHeight");alert(e);}
}
-$.fn.fitFont = function(w, h, minFont, maxFont) {
+$.fn.fitFont = function(w, h, minFont, maxFont, noContainer) {
try {
var oldpos = this.css("position");
this.css({
position: "absolute",
maxWidth: w
});
- var wrappers = this.wrapInner("<span/>").children();
+ if (noContainer) {
+ var wrappers = this;
+ } else {
+ var wrappers = this.wrapInner("<span/>").children();
+ }
var that = this;
this.css("font-size", dichotomy(parseInt(this.css("font-size"), 10), function(x) {
try {
that.css("fontSize", x);
- fubar = wrappers;
return (wrappers.maxHeight() > h || wrappers.maxWidth() > w);
} catch(e) {alert("Error anonymous in $.fn.fitFont");alert(e);}
},this).clip(minFont || 0, maxFont || Infinity));
// Restore stuff
this.css("position", oldpos);
- //wrappers.children().unwrap();
+ if (!noContainer) wrappers.children().unwrap();
return this;
} catch(e) {alert("Error $.fn.fitFont");alert(e);}
}
diff --git a/code/serveur/php/ressources/pticlic.js b/code/serveur/php/ressources/pticlic.js
@@ -64,7 +64,7 @@ function jss() {
else if(h > 500) iconSize = 48;
else iconSize = 36;
- $("#"+"state.screen"+".screen")
+ $("#"+state.screen+".screen")
.wh(w, h)
.northWest({top:0,left:0});
@@ -124,14 +124,58 @@ $(function() {
} 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 {
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);
UI().exit();
- } catch(e) {alert("Error ajaxError");alert(e);}
+ } catch(e) {alert("Error ajaj.error");alert(e);}
}
// ==== Code métier pour le splash
@@ -205,7 +249,7 @@ frontpage.jss = function(w, h, iconSize) {
$fp(".game .icon").data('image', 'mode_normal');
$fp(".prefs .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")
.css('text-align', 'center')
@@ -233,19 +277,36 @@ frontpage.jss = function(w, h, iconSize) {
frontpage.enter = function () {
try {
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();
UI().dismiss();
} catch(e) {alert("Error frontpage.enter");alert(e);}
};
frontpage.click = {};
-frontpage.click.game = function(){
+frontpage.click.goGame = function(){
try {
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
game = {};
@@ -315,9 +376,7 @@ game.enter = function () {
};
if (notAlreadyFetching) {
UI().show("PtiClic", "Récupération de la partie");
- $.getJSON("getGame.php?callback=?", {
- user:"foo",
- passwd:"bar",
+ ajaj.request("getGame.php?callback=?", {
nonce:Math.random()
}, function(data) {
try {
@@ -325,7 +384,7 @@ game.enter = function () {
runstate.gameFetched = false;
fn(data);
} catch(e) {alert("Error anonymous 2 in game.enter");alert(e);}
- }).error(ajaxError);
+ });
}
} else {
game.buildUi();
@@ -429,7 +488,7 @@ score = {};
score.jss = function(w, h, iconSize) {
try {
- $(".screen")
+ $("#score.screen")
.css('text-align', 'center');
} catch(e) {alert("Error score.jss");alert(e);}
};
@@ -452,9 +511,7 @@ score.enter = function () {
};
if (notAlreadyFetching) {
UI().show("PtiClic", "Calcul de votre score");
- $.getJSON("server.php?callback=?", {
- user: "foo",
- passwd: "bar",
+ ajaj.request("server.php?callback=?", {
action: 1,
pgid: state.game.pgid,
gid: state.game.gid,
@@ -466,7 +523,7 @@ score.enter = function () {
runstate.scoreFetched = false;
fn(data);
} catch(e) {alert("Error anonymous 2 in score.enter");alert(e);}
- }).error(ajaxError);
+ });
}
} else {
score.ui();
@@ -515,3 +572,88 @@ score.click.jaivu = function() {
state = new State().validate();
} 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);}
+};
diff --git a/code/serveur/php/server.php b/code/serveur/php/server.php
@@ -31,27 +31,38 @@ function logError($errNum, $msg, $other="")
*/
function main()
{
- if(!isset($_GET['action']))
- throw new Exception("La requête est incomplète", 2);
- else if(!isset($_SESSION['userId']) && (!isset($_GET['user']) || !isset($_GET['passwd'])))
- throw new Exception("La requête est incomplète", 2);
- else if(isset($_SESSION['userId'])) {
- $user = $_SESSION['userId'];
- $loginIsOk = true;
+ $loginIsOk = false;
+ $user = 'nobody';
+ if(!isset($_GET['action'])) {
+ throw new Exception("La requête est incomplète.", 2);
}
- else {
+ if(isset($_GET['user']) && isset($_GET['passwd'])) {
+ unset($_SESSION['userId']);
$user = SQLite3::escapeString($_GET['user']);
- $loginIsOk = checkLogin($user, $_GET['passwd']);
+ $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'];
+ $loginIsOk = true;
}
$action = $_GET['action'];
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) {
- echo '{"login_ok":' . ($loginIsOk ? 'true' : 'false') . '}';
- exit;
+ echo json_encode(
+ Array(
+ "loginOk" => !!$loginIsOk,
+ "whoami" => "".$user
+ )
+ );
+ return;
}
// 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']);
} else if($action == 4) { // CheckWord
if (!isset($_GET['word']))
- errRequestIncomplete();
+ throw new Exception("La requête est incomplète", 2);
if(wordExist($_GET['word']))
echo "true";
@@ -90,13 +101,13 @@ function main()
}
else if($action == 6) {
if (!isset($_GET['game']))
- errRequestIncomplete();
+ throw new Exception("La requête est incomplète", 2);
decodeAndInsertGame($user,$_GET['game']);
-
} else {
throw new Exception("Commande inconnue", 2);
}
+ // Attention, il y a une $action == 7, mais plus haut.
}
function server() {
@@ -108,7 +119,13 @@ function server() {
ob_end_flush();
} catch (Exception $e) {
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"));
closeDB();
}