From 35838780dce22af9f2dc80af9149a30a0433de0a Mon Sep 17 00:00:00 2001 From: Greg Burri Date: Wed, 30 Apr 2008 11:09:05 +0000 Subject: [PATCH] =?utf8?q?MOD=20passage=20au=20JSON=20termin=C3=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- doc/protocole3.txt | 60 +-- js/euphorik.js | 306 +++++---------- js/pageMinichat.js | 234 +++++------- js/pageProfile.js | 6 +- modules/erl/euphorik_minichat.erl | 2 +- .../erl/euphorik_minichat_conversation.erl | 1 - modules/erl/euphorik_protocole.erl | 358 +++++++----------- modules/erl/euphorik_requests.erl | 19 +- 8 files changed, 368 insertions(+), 618 deletions(-) diff --git a/doc/protocole3.txt b/doc/protocole3.txt index 033c9ab..f8b4c00 100644 --- a/doc/protocole3.txt +++ b/doc/protocole3.txt @@ -40,35 +40,45 @@ Message ok g } -=== Login === -Le mot de passe est hashé en md5. -L'action 'register' permet de créer un nouvel utilisateur. +=== Enregistrement et authentification === +Permet de créer un nouvel utilisateur. +"login" et "password" peuvent ne pas être fournis avec un message de type "register", dans ce cas l'utilisateur ne pourra s'authentifier qu'a l'aide de son cookie. +Le mot de passe est hashé en md5. -c -> s - { - "action" : "authentification", - "login" : "Paul", - "password" : "IJKJDHHSAD9081238" +c -> s + { + "action" : "authentification", + "login" : "paul", + "password" : "IJKJDHHSAD9081238" } -ou - { - "action" : "authentification", - "cookie" : "LKJDLAKSJBFLKASN" +ou + { + "action" : "authentification", + "cookie" : "LKJDLAKSJBFLKASN" } -ou - { - "action" : "register", - "login" : "Paul", - "password" : "IJKJDHHSAD9081238" +ou + { + "action" : "register", + "login" : "paul", + "password" : "IJKJDHHSAD9081238" } -s -> c - { - "reply" : "login", - "status" : "registration_ok" | "authentification_ok", +s -> c + { + "reply" : "register" | "authentification", + "status" : "auth_not_registered", + "cookie" : "LKJDLAKSJBFLKASN", + "id" : 193, + "css" : "css/1/euphorik.css", + "main_page" : 1 + } +ou + { + "reply" : "register" | "authentification", + "status" : "auth_registered", "cookie" : "LKJDLAKSJBFLKASN", "id" : 193, - "pseudo" : "Paul", + "nick" : "Paul", "login" : "paul49", "email" : "paul@pierre.com", "css" : "css/3/euphorik.css", @@ -117,7 +127,8 @@ ou === Wait event === Si "last_message_id" est absent alors le client ne possède pas de message. -Les conversations lié aux trolls sont définies dans le profile. +Si "main_page" est absent alors est vaut 1. +"cookie" n'est pas obligatoire. c -> s { @@ -126,6 +137,7 @@ c -> s "cookie" : "LKJDLAKSJBFLKASN", "message_count" : 10, "last_message_id" : 163, + "main_page" : 1 "conversations" : [ { "racine" : 123, @@ -155,7 +167,7 @@ Le format de la date n'est pas formel. "login" : "paul_22", "content" : "Salut", "answer_to" : [ - { "id" : 123, "pseudo" : "Pierre", "login" : "pierre_45" } + { "id" : 123, "nick" : "Pierre", "login" : "pierre_45" } ] } ] diff --git a/js/euphorik.js b/js/euphorik.js index f78e103..88ef6e7 100755 --- a/js/euphorik.js +++ b/js/euphorik.js @@ -6,6 +6,7 @@ * Auteur : GBurri * Date : 6.11.2007 */ + /** * La configuration. @@ -40,7 +41,7 @@ var conf = { String.prototype.trim = function() { - return this.replace(/^\s+|\s+$/g, ""); + return jQuery.trim(this) // anciennement : this.replace(/^\s+|\s+$/g, ""); } String.prototype.ltrim = function() @@ -53,27 +54,13 @@ String.prototype.rtrim = function() return this.replace(/\s+$/, ""); } -String.prototype.dump = function(titre) -{ - titre = titre == undefined ? "" : titre - if (typeof dump != "undefined") - { - dump("\n--- EUPHORIK.CH : " + titre + " ---\n") - dump(this) - dump("\n------\n") - } -} - /////////////////////////////////////////////////////////////////////////////////////////////////// /** * Cette classe regroupe des fonctions utilitaires (helpers). */ function Util() -{ - if(typeof XMLSerializer != "undefined") - this.serializer = new XMLSerializer() - +{ jQuery("#info .fermer").click(function(){ jQuery("#info").slideUp(50) }) @@ -111,49 +98,8 @@ Util.prototype.messageDialogue = function(message, type, boutons) jQuery("#info").slideDown(200) this.timeoutMessageDialogue = setTimeout(fermer, conf.tempsAffichageMessageDialogue) } -var messageType = {informatif: 0, question: 1, erreur: 2} - -/** - * Transforme un document XML en string. - */ -Util.prototype.serializeXML = function(documentXML) -{ - if (this.serializer) - return this.serializer.serializeToString(documentXML) - else - return documentXML.xml -} -var documentXMLBase = undefined // singleton -Util.prototype.creerDocumentXMLAction = function() -{ - // FIXME : essayer de garder le doc de base en cache (singleton) et d'en retourner une copie - if (true)//documentXMLBase == undefined) - { - if (document.implementation && document.implementation.createDocument) - { - // var doc = document.implementation.createDocument("", "action", null) - var parser = new DOMParser(); - documentXMLBase = parser.parseFromString("\n", "text/xml") - //alert(this.serializeXML(doc)) - } - else if (window.ActiveXObject) - { - documentXMLBase = new ActiveXObject("MSXML2.DOMDocument") //("Microsoft.XMLDOM") - documentXMLBase.appendChild(doc.createElement("action")); - //doc.loadXML("") - //alert(doc.documentElement) - //doc.createElement("action") - } - } - return documentXMLBase -} - -Util.prototype.xmlVersAction = function(xml) -{ - //return {action: this.to_utf8(this.serializeXML(xml /*, "UTF-8"*/))} - return {action: this.serializeXML(xml)} -} +var messageType = {informatif: 0, question: 1, erreur: 2} /** * Utilisé pour l'envoie de donnée avec la méthode ajax de jQuery. @@ -414,7 +360,15 @@ Formateur.prototype.traiterPourFenetreLightBox = function(M, urlCourante) /////////////////////////////////////////////////////////////////////////////////////////////////// -var statutType = {enregistre: 0, identifie: 1, non_identifie: 2} +// les statuts possibes du client +var statutType = { + // mode enregistré, peut poster des messages et modifier son profile + auth_registered : 0, + // mode identifié, peut poster des messages mais n'a pas accès au profile + auth_not_registered : 1, + // mode déconnecté, ne peut pas poster de message + deconnected : 2 +} function Client(util) { @@ -426,7 +380,7 @@ function Client(util) // données personnels this.resetDonneesPersonnelles() - this.setStatut(statutType.non_identifie) + this.setStatut(statutType.deconnected) // le dernier message d'erreur recut du serveur (par exemple une connexion foireuse : "login impossible") this.dernierMessageErreur = "" @@ -456,9 +410,6 @@ Client.prototype.setCss = function(css) this.css = css jQuery("link#cssPrincipale").attr("href", this.css) this.majMenu() - - if (this.identifie()) - this.flush() } Client.prototype.pageSuivante = function(numConv) @@ -467,7 +418,6 @@ Client.prototype.pageSuivante = function(numConv) this.pagePrincipale -= 1 else if (this.conversations[numConv].page > 1) this.conversations[numConv].page -= 1 - this.flush(false) } Client.prototype.pagePrecedente = function(numConv) @@ -476,7 +426,6 @@ Client.prototype.pagePrecedente = function(numConv) this.pagePrincipale += 1 else this.conversations[numConv].page += 1 - this.flush(false) } /** @@ -497,14 +446,13 @@ Client.prototype.goPremierePage = function(numConv) return false this.conversations[numConv].page = 1 } - this.flush(false) return true } /** * Ajoute une conversation à la vue de l'utilisateur. * Le profile de l'utilisateur est directement sauvegardé sur le serveur. - * @param racines la racine de la conversation + * @param racines la racine de la conversation (integer) * @return true si la conversation a été créée sinon false (par exemple si la conv existe déjà) */ Client.prototype.ajouterConversation = function(racine) @@ -515,7 +463,6 @@ Client.prototype.ajouterConversation = function(racine) return false this.conversations.push({racine : racine, page : 1}) - this.flush(false) return true } @@ -527,24 +474,6 @@ Client.prototype.supprimerConversation = function(num) for (var i = num; i < this.conversations.length - 1; i++) this.conversations[i] = this.conversations[i+1] this.conversations.pop() - - this.flush(false) -} - -Client.prototype.getXMLlogin = function(login, password) -{ - var XMLDocument = this.util.creerDocumentXMLAction() - XMLDocument.documentElement.setAttribute("name", "login") - - var nodeLogin = XMLDocument.createElement("login") - nodeLogin.appendChild(XMLDocument.createTextNode(login)) - XMLDocument.documentElement.appendChild(nodeLogin) - - var nodePassword = XMLDocument.createElement("password") - nodePassword.appendChild(XMLDocument.createTextNode(password)) - XMLDocument.documentElement.appendChild(nodePassword) - - return XMLDocument } Client.prototype.getJSONLogin = function(login, password) @@ -556,87 +485,51 @@ Client.prototype.getJSONLogin = function(login, password) } } -Client.prototype.getXMLloginCookie = function() +Client.prototype.getJSONLoginCookie = function() { - var XMLDocument = this.util.creerDocumentXMLAction() - XMLDocument.documentElement.setAttribute("name", "login") - - var nodeCookie = XMLDocument.createElement("cookie") - nodeCookie.appendChild(XMLDocument.createTextNode(this.cookie)) - XMLDocument.documentElement.appendChild(nodeCookie) - - return XMLDocument -} + return { + "action" : "authentification", + "cookie" : this.cookie + } +} -Client.prototype.getXMLEnregistrement = function(login, password) +/** + * le couple (login, password) est facultatif. S'il n'est pas fournit alors il ne sera pas possible + * de s'autentifier avec (login, password). + */ +Client.prototype.getJSONEnregistrement = function(login, password) { - var XMLDocument = this.util.creerDocumentXMLAction() - XMLDocument.documentElement.setAttribute("name", "register") - - var nodeLogin = XMLDocument.createElement("login") - nodeLogin.appendChild(XMLDocument.createTextNode(login)) - XMLDocument.documentElement.appendChild(nodeLogin) + var mess = { "action" : "register" } - var nodePassword = XMLDocument.createElement("password") - nodePassword.appendChild(XMLDocument.createTextNode(password)) - XMLDocument.documentElement.appendChild(nodePassword) + if (login != undefined && password != undefined) + { + mess["login"] = login + mess["password"] = password + } - return XMLDocument + return mess; } -/** - * Sérialize le profile en XML. - * TODO : méthode assez lourde, 3.25ms de moyenne - */ -Client.prototype.getXMLProfile = function() +Client.prototype.getJSONConversations = function() { - var XMLDocument = this.util.creerDocumentXMLAction() - XMLDocument.documentElement.setAttribute("name", "profile") - - var nodeCookie = XMLDocument.createElement("cookie") - nodeCookie.appendChild(XMLDocument.createTextNode(this.cookie)) - XMLDocument.documentElement.appendChild(nodeCookie) - - var nodeLogin = XMLDocument.createElement("login") - nodeLogin.appendChild(XMLDocument.createTextNode(this.login)) - XMLDocument.documentElement.appendChild(nodeLogin) - - var nodePassword = XMLDocument.createElement("password") - nodePassword.appendChild(XMLDocument.createTextNode(this.password)) - XMLDocument.documentElement.appendChild(nodePassword) - - var nodePseudo = XMLDocument.createElement("pseudo") - nodePseudo.appendChild(XMLDocument.createTextNode(this.pseudo)) - XMLDocument.documentElement.appendChild(nodePseudo) - - var nodeEmail = XMLDocument.createElement("email") - nodeEmail.appendChild(XMLDocument.createTextNode(this.email)) - XMLDocument.documentElement.appendChild(nodeEmail) - - var nodeCSS = XMLDocument.createElement("css") - nodeCSS.appendChild(XMLDocument.createTextNode(this.css)) - XMLDocument.documentElement.appendChild(nodeCSS) - - var nodePagePrincipale = XMLDocument.createElement("pagePrincipale") - nodePagePrincipale.appendChild(XMLDocument.createTextNode(this.pagePrincipale < 1 ? 1 : this.pagePrincipale)) - XMLDocument.documentElement.appendChild(nodePagePrincipale) - - // mémorise les conversations affichées + var conversations = new Array() for (var i = 0; i < this.conversations.length; i++) - { - var nodeConv = XMLDocument.createElement("conversation") - XMLDocument.documentElement.appendChild(nodeConv) - - var nodeRacine = XMLDocument.createElement("racine") - nodeRacine.appendChild(XMLDocument.createTextNode(this.conversations[i].racine)) - nodeConv.appendChild(nodeRacine) - - var nodePage = XMLDocument.createElement("page") - nodePage.appendChild(XMLDocument.createTextNode(this.conversations[i].page)) - nodeConv.appendChild(nodePage) + conversations.push({ "racine" : this.conversations[i].racine, "page" : this.conversations[i].page}) + return conversations +} + +Client.prototype.getJSONProfile = function() +{ + return { + "action" : "set_profile", + "cookie" : this.cookie, + "login" : this.login, + "password" : this.password, + "email" : this.email, + "css" : this.css, + "main_page" : this.pagePrincipale < 1 ? 1 : this.pagePrincipale, + "conversations" : this.getJSONConversations() } - - return XMLDocument } /** @@ -664,18 +557,20 @@ Client.prototype.setCookie = function(cookie) "; max-age=" + (60 * 60 * 24 * 365) } -Client.prototype.identifie = function() +Client.prototype.authentifie = function() { - return this.statut == statutType.enregistre || this.statut == statutType.identifie + return this.statut == statutType.auth_registered || this.statut == statutType.auth_not_registered } Client.prototype.setStatut = function(statut) -{ - if(typeof(statut) == "string") +{ + // conversation en "enum" si en "string" + if (typeof(statut) == "string") { statut = - statut == "enregistre" ? - statutType.enregistre : (statut == "identifie" ? statutType.identifie : statutType.non_identifie) + statut == "registered" ? + statutType.auth_registered : + (statut == "auth_not_registered" ? statutType.auth_not_registered : statutType.deconnected) } if (statut == this.statut) return @@ -694,36 +589,33 @@ Client.prototype.connexionCookie = function() { this.getCookie() if (this.cookie == null) return false; - return this.connexion(this.util.xmlVersAction(this.getXMLloginCookie())) + return this.connexion(this.getJSONLoginCookie()) } Client.prototype.connexionLogin = function(login, password) { - // return this.connexion(this.util.xmlVersAction(this.getXMLlogin(login, password))) - return this.connexion(this.util.jsonVersAction(this.getJSONLogin(login, password))) + return this.connexion(this.getJSONLogin(login, password)) } Client.prototype.enregistrement = function(login, password) { - if (this.identifie()) + if (this.authentifie()) { this.login = login this.password = password if(this.flush()) - this.setStatut(statutType.enregistre) + this.setStatut(statutType.auth_registered) return true } else - { - if (login == undefined) login = "" - if (password == undefined) password = "" - return this.connexion(this.util.xmlVersAction(this.getXMLEnregistrement(login, password))) + { + return this.connexion(this.getJSONEnregistrement(login, password)) } } -Client.prototype.connexion = function(action) +Client.prototype.connexion = function(messageJson) { - action.action.dump("Connexion client") + ;;; dumpObj(messageJson) thisClient = this jQuery.ajax( { @@ -731,22 +623,21 @@ Client.prototype.connexion = function(action) type: "POST", url: "request", dataType: "json", - data: action, + data: this.util.jsonVersAction(messageJson), success: function(data) { - //alert(data["error_message"]) - //thisClient.util.serializer.serializeToString(data).dump("Charger client") - //thisClient.chargerDonnees(data) + ;;; dumpObj(data) + thisClient.chargerDonnees(data) } } ) - return this.identifie() + return this.authentifie() } Client.prototype.deconnexion = function() { - this.setStatut(statutType.non_identifie) // deconnexion + this.setStatut(statutType.deconnected) // deconnexion this.resetDonneesPersonnelles() this.delCookie () } @@ -755,21 +646,20 @@ Client.prototype.chargerDonnees = function(data) { var thisClient = this - this.setStatut(jQuery("statut", data.documentElement).text()) + this.setStatut(data["status"]) - if (this.identifie()) + if (this.authentifie()) { - this.cookie = jQuery("cookie", data.documentElement).text() + this.cookie = data["cookie"] this.setCookie() - this.login = jQuery("login", data.documentElement).text() - this.pseudo = jQuery("pseudo", data.documentElement).text() - this.email = jQuery("email", data.documentElement).text() - this.css = jQuery("css", data.documentElement).text() + this.login = data["login"] + this.pseudo = data["nick"] + this.email = data["email"] + this.css = data["css"] // la page de la conversation principale - var tmp = jQuery("pagePrincipale", data.documentElement) - this.pagePrincipale = tmp.length < 1 ? 1 : parseInt(tmp.text()) + this.pagePrincipale = data["main_page"] == undefined ? 1 : data["main_page"] // met à jour la css if (this.css != "") @@ -778,35 +668,34 @@ Client.prototype.chargerDonnees = function(data) this.majMenu() } // les conversations - this.conversations = new Array() - jQuery("conversation", data.documentElement).each( - function(i) - { - thisClient.conversations.push( { racine : jQuery("racine", this).text(), page : jQuery("page", this).text() } ) - } - ) + thisClient.conversations = data["conversations"] + } - this.dernierMessageErreur = jQuery("information", data.documentElement).text() + this.dernierMessageErreur = data["error_message"] } /** * Met à jour les données personne sur serveur. * @param async de manière asynchrone ? défaut = true + * @return false si le flush n'a pas pû se faire sinon true */ Client.prototype.flush = function(async) { if (async == undefined) async = true + + if (!this.authentifie()) + return false thisClient = this - this.util.xmlVersAction(this.getXMLProfile()).action.dump("Flush client") + //this.util.jsonVersAction(this.getJSONProfile()).action.dump("Flush client") jQuery.ajax( { async: async, type: "POST", url: "request", - dataType: "xml", - data: this.util.xmlVersAction(this.getXMLProfile()), + dataType: "json", + data: this.util.jsonVersAction(this.getJSONProfile()), success: function(data) { @@ -823,13 +712,13 @@ Client.prototype.majMenu = function() var displayType = this.css == "css/3/euphorik.css" ? "block" : "inline" //this.client // met à jour le menu - if (this.statut == statutType.enregistre) + if (this.statut == statutType.auth_registered) { jQuery("#menu .profile").css("display", displayType).text("profile") jQuery("#menu .logout").css("display", displayType) jQuery("#menu .register").css("display", "none") } - else if (this.statut == statutType.identifie) + else if (this.statut == statutType.auth_not_registered) { jQuery("#menu .profile").css("display", "none") jQuery("#menu .logout").css("display", displayType) @@ -847,6 +736,8 @@ Client.prototype.majMenu = function() jQuery.noConflict() +// charge dynamiquement le script de debug +;;; jQuery.ajax({async : false, url : "js/debug.js", dataType : "script"}) // le main jQuery(document).ready( @@ -873,6 +764,14 @@ jQuery(document).ready( client.setCss("css/" + jQuery(this).attr("id").charAt(3) + "/euphorik.css") }) } + + jQuery(document).unload( + function() + { + alert("ok") + client.flush() + } + ) jQuery("#menu .minichat").click(function(){ pages.afficherPage("minichat") }) jQuery("#menu .profile").click(function(){ pages.afficherPage("profile") }) @@ -894,5 +793,4 @@ jQuery(document).ready( pages.ajouterPage(new PageRegister(client, formateur, util)) pages.afficherPage("minichat") } -) - +) \ No newline at end of file diff --git a/js/pageMinichat.js b/js/pageMinichat.js index f6b73c0..ec00d7b 100755 --- a/js/pageMinichat.js +++ b/js/pageMinichat.js @@ -107,36 +107,15 @@ PageMinichat.prototype.decharger = function() this.messages.stopAttenteCourante() } -PageMinichat.prototype.getXMLMessage = function(pseudo, message, repondA) -{ - var XMLDocument = this.util.creerDocumentXMLAction() - XMLDocument.documentElement.setAttribute("name", "message") - - var nodeCookie = XMLDocument.createElement("cookie") - nodeCookie.appendChild(XMLDocument.createTextNode(this.client.cookie)) - XMLDocument.documentElement.appendChild(nodeCookie) - - var nodePseudo = XMLDocument.createElement("pseudo") - nodePseudo.appendChild(XMLDocument.createTextNode(pseudo)) - XMLDocument.documentElement.appendChild(nodePseudo) - - var nodeContenu = XMLDocument.createElement("contenu") - nodeContenu.appendChild(XMLDocument.createTextNode(message)) - XMLDocument.documentElement.appendChild(nodeContenu) - - if (repondA.length > 0) - { - var nodeReponses = XMLDocument.createElement("reponses") - XMLDocument.documentElement.appendChild(nodeReponses) - for (var i = 0; i < repondA.length; i++) - { - var nodeReponse = XMLDocument.createElement("reponse") - nodeReponse.setAttribute("id", repondA[i]) - nodeReponses.appendChild(nodeReponse) - } +PageMinichat.prototype.getJSONMessage = function(pseudo, message, repondA) +{ + return { + "action" : "put_message", + "cookie" : this.client.cookie, + "nick" : pseudo, + "content" : message, + "answer_to" : repondA } - - return XMLDocument } PageMinichat.prototype.envoyerMessage = function(pseudo, message) @@ -152,7 +131,7 @@ PageMinichat.prototype.envoyerMessage = function(pseudo, message) if (tags != null) { for(var i = 0; i < tags.length; i++) - repondA.push(/\{(.*?)\}>/.exec(tags[i])[1]) + repondA.push(parseInt(/\{(.*?)\}>/.exec(tags[i])[1], 36)) message = message.replace(this.regexMessageTagReplace, "") } @@ -163,22 +142,25 @@ PageMinichat.prototype.envoyerMessage = function(pseudo, message) return } - if (!this.client.identifie()) + if (!this.client.authentifie()) if (!this.client.enregistrement()) { this.util.messageDialogue("login impossible") return } - + + ;;; dumpObj(this.getJSONMessage(pseudo, message, repondA)) jQuery.ajax( { url : "request", type: "POST", - data : this.util.xmlVersAction(this.getXMLMessage(pseudo, message, repondA)), - dataType : "xml", + data : this.util.jsonVersAction(this.getJSONMessage(pseudo, message, repondA)), + dataType : "json", success : function(data, textStatus) { - if(jQuery("statut", data.documentElement).text() == "ok") + ;;; dumpObj(data) + + if(data["reply"] == "ok") { jQuery("form input.message").val("") @@ -241,19 +223,19 @@ function Message(id, date, pseudo, contenu) /** * */ -Message.prototype.setRepondA = function(element) +Message.prototype.setRepondA = function(repondAJSON) { - this.repondA = {} - var thisMessage = this - - jQuery("id", element).each ( - function() - { - var reponse = new Reponse(jQuery(this).attr("id"), jQuery(this).attr("pseudo"), jQuery(this).attr("login")) - thisMessage.repondA[reponse.id] = reponse - } - ) + this.repondA = {} + + for(var i = 0; i < repondAJSON.length; i++) + { + thisMessage.repondA[repondAJSON[i]["id"]] = new Reponse( + repondAJSON[i]["id"], + repondAJSON[i]["nick"], + repondAJSON[i]["login"] + ) + } } /** @@ -302,7 +284,7 @@ function Conversation(num, util, formateur) var thisConversation = this this.num = num // peut changer au cours de la vie de la conversation - this.id = Math.random()*100000000000000000 + this.id = Math.random() * 100000000000000000 this.messageOver = null // le message sur lequel se trouve le curseur this.util = util this.formateur = formateur @@ -425,12 +407,12 @@ Conversation.prototype.flush = function(funClickExtract, funClickLienConv) var thisConversation = this var idDernierMessageAffiche = jQuery("#conversations #" + this.getId() + " div:first").attr("id") - if (idDernierMessageAffiche == undefined) idDernierMessageAffiche = "0" + idDernierMessageAffiche = (idDernierMessageAffiche == undefined ? 0 : parseInt(idDernierMessageAffiche, 36)) // construction de l'XHTML des messages var XHTML = "" for (var i = this.messages.length - 1; i >= 0; i--) - if (parseInt(this.messages[i].id, 36) > parseInt(idDernierMessageAffiche, 36)) + if (this.messages[i].id > idDernierMessageAffiche) { var message = this.messages[i] var XHTMLrepondA = "" @@ -439,7 +421,7 @@ Conversation.prototype.flush = function(funClickExtract, funClickLienConv) XHTMLrepondA = "" + XHTMLrepondA + "" XHTML += - "
" + "
>
" + @@ -463,7 +445,7 @@ Conversation.prototype.flush = function(funClickExtract, funClickLienConv) jQuery("#conversations #" + this.getId() + " .message").slice(this.nbMessageMax, nbMessagesAffiche).empty() // Ajoute les événements liés à chaque message - jQuery("#conversations #" + this.getId() + " .message").filter(function(){return parseInt(jQuery(this).attr("id"), 36) > parseInt(idDernierMessageAffiche, 36)}).each( + jQuery("#conversations #" + this.getId() + " .message").filter(function(){return parseInt(jQuery(this).attr("id"), 36) > idDernierMessageAffiche}).each( function() { jQuery(".lienConv", this).click( @@ -471,7 +453,7 @@ Conversation.prototype.flush = function(funClickExtract, funClickLienConv) { // FIXME : ya pas mieux ? var racine = jQuery(event.target).text() - funClickLienConv(racine.substring(1, racine.length - 1)) + funClickLienConv(parseInt(racine.substring(1, racine.length - 1), 36)) return false } ) @@ -487,7 +469,7 @@ Conversation.prototype.flush = function(funClickExtract, funClickLienConv) // extraction d'une conversation if (jQuery(event.target).is(".extraire")) { - funClickExtract(idMess) + funClickExtract(parseInt(idMess, 36)) return } @@ -523,7 +505,7 @@ Conversation.prototype.flush = function(funClickExtract, funClickLienConv) Conversation.prototype.afficherConversation = function(element) { // cherche le message selectionné - var id = jQuery(element).attr("id") + var id = parseInt(jQuery(element).attr("id"), 36) var message = this.messagesParId[id] if (message == undefined) return @@ -534,7 +516,7 @@ Conversation.prototype.afficherConversation = function(element) function() { var jq = jQuery(this) - if (!mess.hasOwnProperty(jq.attr("id"))) + if (!mess.hasOwnProperty(parseInt(jq.attr("id"), 36))) jq.addClass("cache") else jq.removeClass("cache") @@ -568,55 +550,45 @@ function Messages(client, formateur, util) this.idDernierMessage = null // l'id du dernier message connu - // l'objet XMLHttpRequest représentant la connexion d'attente + // l'objet JSONHttpRequest représentant la connexion d'attente this.attenteCourante = null } /** - * Crée un document XML contenant le message demandant un rafraichissement. + * Crée un message JSON contenant le message demandant un rafraichissement. */ -Messages.prototype.getXMLrafraichirMessages = function() -{ - var XMLDocument = this.util.creerDocumentXMLAction() - XMLDocument.documentElement.setAttribute("name", "refreshMessages") - - if (this.client.identifie()) - { - var nodeCookie= XMLDocument.createElement("cookie") - nodeCookie.appendChild(XMLDocument.createTextNode(this.client.cookie)) - XMLDocument.documentElement.appendChild(nodeCookie) +Messages.prototype.getJSONrafraichirMessages = function() +{ + var mess = { + "action" : "wait_event", + "page" : "chat", + "message_count" : conf.nbMessageAffiche, + "main_page" : this.client.pagePrincipale, + "conversations" : this.client.getJSONConversations() } - if (this.idDernierMessage != null) - { - var nodeDernierMessageId = XMLDocument.createElement("dernierMessageId") - nodeDernierMessageId.appendChild(XMLDocument.createTextNode(this.idDernierMessage)) - XMLDocument.documentElement.appendChild(nodeDernierMessageId) - } - - var nodeNombreMessage = XMLDocument.createElement("nombreMessage") - nodeNombreMessage.appendChild(XMLDocument.createTextNode(conf.nbMessageAffiche)) - XMLDocument.documentElement.appendChild(nodeNombreMessage) + if (this.client.cookie != null) mess["cookie"] = this.client.cookie; + if (this.idDernierMessage != null) mess["last_message_id"] = this.idDernierMessage - return XMLDocument; + return mess } /** * Ajoute un ensemble de messages puis les affiches. - * @param elements un tableau d'éléments représentant les messages, voir protocole.txt + * @param elements un tableau d'éléments JSON représentant les messages, voir protocole.txt * @param numConversation le numéro de la conversation auquel appartiennent les messages */ Messages.prototype.ajouterMessages = function(elements, numConversation) { - for (var i = 0; i < elements.length; i++) - this.ajouterMessage(elements[i], numConversation) + for (var i = 0; i < elements["messages"].length; i++) + this.ajouterMessage(elements["messages"][i], numConversation) this.flush(numConversation) } /** * Création d'un nouveau message. * Les message sont données dans l'ordre de leur id. - * @param element un element xml représentant le message + * @param element un element JSON représentant le message * @param numConversation le numéro de la conversation, 0 = principale */ Messages.prototype.ajouterMessage = function(element, numConversation) @@ -624,22 +596,23 @@ Messages.prototype.ajouterMessage = function(element, numConversation) var thisMessages = this // pas d'utilisation de jquery pour des raisons de performance - var id = element.getAttribute("id") - if (this.idDernierMessage == null || parseInt(id, 36) > parseInt(this.idDernierMessage, 36)) + var id = element["id"] + + if (this.idDernierMessage == null || id > this.idDernierMessage) this.idDernierMessage = id var message = new Message( - id, - jQuery("date", element).text(), - jQuery("pseudo", element).text(), - jQuery("contenu", element).text() + id, + element["date"], + element["nick"], + element["content"] ) - message.appartientAuClient = jQuery("proprietaire", element).text() == "true" - message.clientARepondu = jQuery("repondu", element).text() == "true" - message.estUneReponse = jQuery("reponse", element).text() == "true" - message.systeme = jQuery("systeme", element).text() == "true" - message.setRepondA(jQuery("repondA", element)) + message.appartientAuClient = element["owner"] + message.clientARepondu = element["answered"] + message.estUneReponse = element["is_a_reply"] + message.systeme = element["system"] + message.setRepondA(element["answer_to"]) if (this.conversations[numConversation] == null) { @@ -738,7 +711,7 @@ Messages.prototype.flushAll = function() Messages.prototype.flush = function(numConv) { var thisMessages = this - + this.conversations[numConv].flush( // fonction appelée lors de la demande d'extraction d'une conversation function(idMess) @@ -788,52 +761,39 @@ Messages.prototype.rafraichirMessages = function(vider) if (vider) this.idDernierMessage = null - ;;; this.util.xmlVersAction(this.getXMLrafraichirMessages()).action.dump("Client") + dumpObj(this.getJSONrafraichirMessages()) this.attenteCourante = jQuery.ajax({ - type: "POST", - url: "request", - dataType: "xml", - data: this.util.xmlVersAction(this.getXMLrafraichirMessages()), - success: - function(data) - { - ;;; thisMessages.util.serializer.serializeToString(data).dump("Serveur") + type: "POST", + url: "request", + dataType: "json", + data: this.util.jsonVersAction(this.getJSONrafraichirMessages()), + success: + function(data) + { + ;;; dumpObj(data) + + if (vider) + thisMessages.viderMessages() - if (vider) - thisMessages.viderMessages() + // ajoute les messages reçu à leur conversation respective + for (var numConv = 0; numConv < data["conversations"].length; numConv++) + { + thisMessages.ajouterMessages(data["conversations"][numConv], numConv) - // ajoute les messages reçu à leur conversation respective - var numConv = 0 - jQuery("conversation", data.documentElement).each( - function(i) - { - var messages = [] - jQuery("message", this).each( - function(j) - { - // thisMessages.ajouterMessage(this, numConv) - messages.push(this) - } - ) - - thisMessages.ajouterMessages(messages, numConv) - - thisMessages.conversations[numConv].eventsPage( - numConv == 0 ? thisMessages.client.pagePrincipale : thisMessages.client.conversations[numConv - 1].page, - jQuery("autresPages", this).text() != "true" - ) - numConv += 1 - } + // définit les événements liés à la conversation + thisMessages.conversations[numConv].eventsPage( + numConv == 0 ? thisMessages.client.pagePrincipale : thisMessages.client.conversations[numConv - 1].page, + data["conversations"][numConv]["last_page"] ) - - // rappel de la fonction dans 100 ms - setTimeout(function(){ thisMessages.rafraichirMessages() }, 100); - }, - error: - function(XMLHttpRequest, textStatus, errorThrown) - { - setTimeout(function(){ thisMessages.rafraichirMessages() }, 1000); } - } - ) + + // rappel de la fonction dans 100 ms + setTimeout(function(){ thisMessages.rafraichirMessages() }, 100); + }, + error: + function(XMLHttpRequest, textStatus, errorThrown) + { + setTimeout(function(){ thisMessages.rafraichirMessages() }, 1000); + } + }) } diff --git a/js/pageProfile.js b/js/pageProfile.js index 7270c23..4a86aee 100755 --- a/js/pageProfile.js +++ b/js/pageProfile.js @@ -19,7 +19,7 @@ PageProfile.prototype.charger = function() jQuery("#page").html(this.getHTML()) // en fonction du statut - if (this.client.identifie()) + if (this.client.authentifie()) this.chargerProfile() else this.chargerLogin() @@ -89,13 +89,13 @@ return '\ \ \ \ - \ + \ \ \ \ \ ' + - (this.client.identifie() ? '\ + (this.client.authentifie() ? '\ \ \ \ diff --git a/modules/erl/euphorik_minichat.erl b/modules/erl/euphorik_minichat.erl index 92f5922..2e2f406 100755 --- a/modules/erl/euphorik_minichat.erl +++ b/modules/erl/euphorik_minichat.erl @@ -223,7 +223,7 @@ set_profile(Cookie, Login, Password, Pseudo, Email, Css, Page_principale, Conver end end )). - + % Met à jour la date de la dernière connexion d'un utilisateur à maintenant update_date_derniere_connexion(UserId) -> diff --git a/modules/erl/euphorik_minichat_conversation.erl b/modules/erl/euphorik_minichat_conversation.erl index 982c4a3..d264bcc 100755 --- a/modules/erl/euphorik_minichat_conversation.erl +++ b/modules/erl/euphorik_minichat_conversation.erl @@ -151,7 +151,6 @@ conversation_principale(C, Conversations, N, P) -> % on prend en message de plus pour savoir s'il y en a plus que ce que l'on désire CP = reverse(conversation_principale2(C, lists:flatten(map(fun({C2, _, X, _}) -> C2 -- X end, Conversations)), N + 1, (P - 1) * N)), Plus = length(CP) =:= N + 1, - io:format("~p~n", [CP]), { if Plus -> [_| Suivants] = CP, diff --git a/modules/erl/euphorik_protocole.erl b/modules/erl/euphorik_protocole.erl index 4eed84d..ff53a1c 100755 --- a/modules/erl/euphorik_protocole.erl +++ b/modules/erl/euphorik_protocole.erl @@ -1,19 +1,16 @@ % coding: utf-8 -% Ce module gére les différents message envoyé par le client (javascript) via AJAX. -% Par exemple le client peut demander les derniers messages du minichat. -% Les messages sont au format XML, la plus part des fonctions accepte un xmlDocument() et renvoie un string() -% qui est la réponse XML. -% Example XML : http://www.erlang.org/doc/apps/xmerl/xmerl_ug.html. +% Ce module gére les différents messages envoyés par le client (javascript) via AJAX. +% Les messages donnés ainsi que les réponses sont au format JSON. % @author G.Burri -module(euphorik_protocole). -export([ - nouveau_user_login/1, + register/1, login/1, logout/1, profile/1, - refreshMessage/1, - message/1, + wait_event/1, + put_message/1, erreur/1 ]). @@ -21,23 +18,20 @@ -include("../include/euphorik_bd.hrl"). -include("../include/euphorik_defines.hrl"). - + % Une utilisateur s'enregistre avec un tuple {Login, Password}. -register([]) -> - {Login, Password, Login_deja_pris} = case {xmerl_xpath:string("login", Action), xmerl_xpath:string("password", Action)} of - {[#xmlElement{content = [#xmlText{value = L}]}], [#xmlElement{content = [#xmlText{value = P}]}]} -> - {L, P, case euphorik_minichat:user_by_login(L) of {ok, _} -> true; _ -> false end}; - _ -> {[], [], false} - end, - simple_xml_to_string( - if Login_deja_pris-> - xml_reponse_login_pas_ok("Login déjà pris"); - true -> - Cookie = generer_cookie(), - User = euphorik_minichat:nouveau_user(Login, Password, Cookie), - xml_reponse_login_ok(User) - end - ). +register([{login, Login}, {password, Password}]) -> + case euphorik_minichat:user_by_login(Login) of + {ok, _} -> + erreur("Login déjà existant"); + _ -> + User = euphorik_minichat:nouveau_user(Login, Password, generer_cookie()), + json_reponse_login_ok(User) + end; +% Enregistrement sans {Login, Password} +register([]) -> + User = euphorik_minichat:nouveau_user("", generer_cookie()), + json_reponse_login_ok(User). % Un utilisateur se logge (avec un couple {login, mot de passe}) @@ -76,7 +70,7 @@ profile( {email, Email}, {css, Css}, {main_page, Main_page}, - {conversations, {array, Conversations_json}} + {conversations, Conversations_json} ] ) -> % est-ce que les messages auquel on répond existent ? @@ -85,8 +79,9 @@ profile( Message_existe = euphorik_minichat:message_existe(Root), if Message_existe -> [{Root, Page} | Acc]; - true -> - Acc + true -> + Acc + end end, [], Conversations_json @@ -102,130 +97,102 @@ profile( % Renvoie les messages appropriés. -wait_event( - [ - {cookie, Cookie}, - {message_count, Message_count} | Reste - ] -) -> - % Last message id est facultatif - Last_message_id = case lists:keysearch(last_message_id, 1, Reste) of - {Id, _} -> Id; - _ -> 0 - end, - {Main_page, _} = lists:keysearch(main_page, 1, Reste), - {{array, Conversations_json}, _} = lists:keysearch(conversations, 1, Reste), +% last_message id et cookie sont facultatifs +% TODO : erreur : {badmatch,false} +wait_event(Data) -> + Cookie = case lists:keysearch(cookie, 1, Data) of {value, {_, C}} -> C; _ -> inconnu end, + Last_message_id = case lists:keysearch(last_message_id, 1, Data) of {value, {_, Id}} -> Id; _ -> 0 end, + {value, {_, Message_count}} = lists:keysearch(message_count, 1, Data), + Main_page = case lists:keysearch(main_page, 1, Data) of {value, {_, P}} -> P; _ -> 1 end, + {value, {_, {array, Conversations_json}}} = lists:keysearch(conversations, 1, Data), + Conversations = lists:map(fun({struct, [{racine, Racine}, {page, Page}]}) -> {Racine, Page} end, Conversations_json), User = case euphorik_minichat:user_by_cookie(Cookie) of - {ok U} -> U; + {ok, U} -> U; _ -> inconnu end, - {stuct, [ + {struct, [ {reply, "new_message"}, - {conversations, {array, - TODO ... - } - ]} - - % accrochez-vous ca va siouxer ;) - [{reponse, [{name, "refreshMessages"}], - lists:map( - fun({Conv, Plus}) -> - {conversation, [], - [{autresPages, [], [atom_to_list(Plus)]} | - lists:map( - fun({Mess, Repond_a}) -> - Est_proprietaire = User =/= inconnu andalso User#user.id =:= Mess#minichat.auteur_id, - A_repondu_a_message = User =/= inconnu andalso euphorik_minichat:a_repondu_a_message(User#user.id, Mess#minichat.id), - Est_une_reponse_a_user = User =/= inconnu andalso euphorik_minichat:est_une_reponse_a_user(User#user.id, Mess#minichat.id), - User_mess = - if Mess#minichat.auteur_id =:= 0 -> - inconnu; - true -> - {ok, U2} = euphorik_minichat:user_by_id(Mess#minichat.auteur_id), - U2 - end, - {message, [{id, erlang:integer_to_list(Mess#minichat.id, 36)}], - [ - {date, [], [format_date(Mess#minichat.date)]}, - {systeme, [], [atom_to_list(Mess#minichat.auteur_id =:= 0)]}, - {proprietaire, [], [atom_to_list(Est_proprietaire)]}, - {repondu, [], [atom_to_list(A_repondu_a_message)]}, - {reponse, [], [atom_to_list(Est_une_reponse_a_user)]}, - {pseudo, [], [Mess#minichat.pseudo]}, - {login, [], [if User_mess =:= inconnu -> Mess#minichat.pseudo; true -> User_mess#user.login end]}, - {contenu, [], [Mess#minichat.contenu]}, - {repondA, [], xml_repond_a(Repond_a)} - ] - } + {conversations, {array, + % accrochez-vous ca va siouxer ;) + lists:map( + fun({Conv, Plus}) -> + {struct, [ + {last_page, not Plus}, + {messages, {array, + lists:map( + fun({Mess, Repond_a}) -> + Est_proprietaire = User =/= inconnu andalso User#user.id =:= Mess#minichat.auteur_id, + A_repondu_a_message = User =/= inconnu andalso euphorik_minichat:a_repondu_a_message(User#user.id, Mess#minichat.id), + Est_une_reponse_a_user = User =/= inconnu andalso euphorik_minichat:est_une_reponse_a_user(User#user.id, Mess#minichat.id), + % io:format("Repond_a : ~p~n", [Repond_a]), + User_mess = + if Mess#minichat.auteur_id =:= 0 -> + inconnu; + true -> + {ok, U2} = euphorik_minichat:user_by_id(Mess#minichat.auteur_id), + U2 end, - Conv - ) - ] - } - end, - euphorik_minichat_conversation:conversations( - if User =/= inconnu -> User#user.conversations; true -> [] end, - Nb_message, - Dernier_id, - if User =/= inconnu -> User#user.page_principale; true -> 1 end - ) - ) - }]; - _ -> - [{reponse, [{name, "refreshMessages"}], [{erreur, [], ["erreur"]}]}] - end - ). + {struct, [ + {id, Mess#minichat.id}, + {date, format_date(Mess#minichat.date)}, + {system, Mess#minichat.auteur_id =:= 0}, + {owner, Est_proprietaire}, + {answered, A_repondu_a_message}, + {is_a_reply, Est_une_reponse_a_user}, + {nick, Mess#minichat.pseudo}, + {login, if User_mess =:= inconnu -> Mess#minichat.pseudo; true -> User_mess#user.login end}, + {content, Mess#minichat.contenu}, + {answer_to, {array, lists:map( + fun(Id_mess) -> + {ok, M} = euphorik_minichat:message_by_id(Id_mess), + {ok, User_reponse} = euphorik_minichat:user_by_mess(M#minichat.id), + {struct, [{id, M#minichat.id}, {nick, M#minichat.pseudo}, {login, User_reponse#user.login}]} + end, + Repond_a + )}} + ]} + end, + Conv + ) + }} + ]} + end, + euphorik_minichat_conversation:conversations( + Conversations, + Message_count, + Last_message_id, + Main_page + ) + ) + }} + ]}. + - -% Prend une liste de xml text node et en resort un string() -% xmerl : "test & test" devient deux fragments de texte : "test " et "& test", il faut donc rassembler les morceaux... -defragmenter(Text_nodes) -> - lists:foldl(fun(Node, Acc) -> #xmlText{value = V} = Node, Acc ++ V end, [], Text_nodes). - - % Un utilisateur envoie un message -message(Action) -> - simple_xml_to_string( - case { - xmerl_xpath:string("cookie", Action), - xmerl_xpath:string("pseudo", Action), - xmerl_xpath:string("contenu", Action) - } of - { - [#xmlElement{content = [#xmlText{value = Cookie}]}], - [#xmlElement{content = Pseudo_fragments}], - [#xmlElement{content = Contenu_fragments}] - } -> - case euphorik_minichat:user_by_cookie(Cookie) of - {ok, U} -> - Pseudo = defragmenter(Pseudo_fragments), - Contenu = defragmenter(Contenu_fragments), - % met à jour le pseudo du user - euphorik_minichat:update_pseudo_user(U#user.id, Pseudo), - Reponses = case xmerl_xpath:string("reponses", Action) of - [#xmlElement{content = C}] -> - lists:map( - fun (Reponse) -> - #xmlElement{attributes = [#xmlAttribute{name = id, value = Id_reponse}]} = Reponse, - erlang:list_to_integer(Id_reponse, 36) - end - , C); - _ -> [] - end, - Contenu_strip = string:strip(Contenu), - if Contenu_strip =:= [] -> xml_reponse_message(pas_ok); - true -> - case euphorik_minichat:nouveau_message(Contenu, U#user.id, Reponses) of - erreur -> xml_reponse_message(pas_ok); - _ -> xml_reponse_message(ok) - end - end; - _ -> xml_reponse_message(pas_ok) - end; - _ -> - xml_reponse_message(pas_ok) - end - ). +put_message( + [ + {cookie, Cookie}, + {nick, Nick}, + {content, Content}, + {answer_to, {array, Answer_to}} + ] +) -> + case euphorik_minichat:user_by_cookie(Cookie) of + {ok, User} -> + Strip_content = string:strip(Content), + if (Strip_content =:= []) -> + erreur("Message vide"); + true -> + case euphorik_minichat:nouveau_message(Strip_content, User#user.id, Answer_to) of + erreur -> erreur("Impossible d'ajouter un nouveau message"); + _ -> + euphorik_minichat:update_pseudo_user(User#user.id, Nick), + json_reponse_ok() + end + end; + _ -> + erreur("Utilisateur inconnu") + end. % Construit une erreur @@ -237,7 +204,7 @@ erreur(Message) -> ] }. - + % Formatage d'une heure % local_time() -> string format_date(Date) -> @@ -246,16 +213,18 @@ format_date(Date) -> {{Annee, Mois, Jour}, {Heure, Minute, Seconde}} = DateLocal, {{AnneeNow, _, _}, {_, _, _}} = DateNowLocal, Hier = calendar:date_to_gregorian_days(element(1, DateLocal)) =:= calendar:date_to_gregorian_days(element(1, DateNowLocal)) - 1, - if element(1, DateLocal) =:= element(1, DateNowLocal) -> - ""; - Hier -> - "Hier "; - Annee =:= AnneeNow -> - io_lib:format("~2.10.0B/~2.10.0B ", [Jour, Mois]); - true -> - io_lib:format("~2.10.0B/~2.10.0B/~B ", [Jour, Mois, Annee]) - end ++ - io_lib:format("~2.10.0B:~2.10.0B:~2.10.0B", [Heure, Minute, Seconde]). + lists:flatten( + if element(1, DateLocal) =:= element(1, DateNowLocal) -> + ""; + Hier -> + "Hier "; + Annee =:= AnneeNow -> + io_lib:format("~2.10.0B/~2.10.0B ", [Jour, Mois]); + true -> + io_lib:format("~2.10.0B/~2.10.0B/~B ", [Jour, Mois, Annee]) + end ++ + io_lib:format("~2.10.0B:~2.10.0B:~2.10.0B", [Heure, Minute, Seconde]) + ). %%%%%%%%% %%%%%%%%% @@ -263,43 +232,15 @@ format_date(Date) -> json_reponse_ok() -> {struct, [{reply, "ok"}]}. - -% Construit une réponse positive à un login -% si Enregistre vaut true alors cela veut dire que la personne s'est enregistré (elle possède au moins un login et un password) -xml_reponse_login_ok(User) -> - [{reponse, [{name, "login"}], - [ - {statut, [if (User#user.password =/= []) and (User#user.login =/= []) -> "enregistre"; true -> "identifie" end]}, - {cookie, [User#user.cookie]}, - {id, [erlang:integer_to_list(User#user.id, 36)]}, - {pseudo, [User#user.pseudo]}, - {login, [User#user.login]}, - {email, [User#user.email]}, - {css, [User#user.css]}, - {pagePrincipale, [integer_to_list(User#user.page_principale)]} - ] ++ - lists:map( - fun(C) -> - {conversation, - [ - {racine, [erlang:integer_to_list(element(1, C), 36)]}, - {page, [integer_to_list(element(2, C))]} - ] - } - end, - User#user.conversations - ) - }]. - json_reponse_login_ok(User) -> { struct, [ {reply, "login"}, - {status, if (User#user.password =/= []) and (User#user.login =/= []) -> "enregistre"; true -> "identifie" end}, + {status, if (User#user.password =/= []) and (User#user.login =/= []) -> "auth_registered"; true -> "auth_not_registered" end}, {cookie, User#user.cookie}, {id, User#user.id}, - {pseudo, User#user.pseudo}, + {nick, User#user.pseudo}, {login, User#user.login}, {email, User#user.email}, {css, User#user.css}, @@ -321,49 +262,4 @@ json_reponse_login_ok(User) -> }. -% Construit un réponse négative à un login -xml_reponse_login_pas_ok(Message) -> - [{reponse, [{name, "login"}], - [ - {statut, ["erreur"]}, - {information, [Message]} - ] - }]. - - -% Pas utilisé -%~ xml_conversation(Mess_id, Nb) -> - %~ {Mess_id, Conversation} = minichat:conversation(Mess_id, Nb), - %~ xml_conversation(Conversation). -%~ xml_conversation([]) -> []; -%~ xml_conversation(Liste_id) -> - %~ lists:map( - %~ fun({Id, Sous_liste}) -> - %~ {id, [{id, erlang:integer_to_list(Id, 36)}], xml_conversation(Sous_liste)} - %~ end, - %~ Liste_id - %~ ). - - -% Renvoie un element XML representant une liste de messages auquel le message M_id repond -xml_repond_a(Reponses) -> - lists:map( - fun(Id_mess) -> - {ok, M} = euphorik_minichat:message_by_id(Id_mess), - {ok, User} = euphorik_minichat:user_by_mess(Id_mess), - {id, [{id, erlang:integer_to_list(M#minichat.id, 36)}, {pseudo, M#minichat.pseudo}, {login, User#user.login}], []} - end, - Reponses - ). - - -xml_reponse_message(Ok) -> - [ - {reponse, [{name, "message"}], - [ - {statut, [], [case Ok of ok -> "ok"; pas_ok -> "pas ok" end]} - ] - } - ]. - -%%%%%%%%% %%%%%%%%% +%%%%%%%%% %%%%%%%%% diff --git a/modules/erl/euphorik_requests.erl b/modules/erl/euphorik_requests.erl index 42348cf..81dd2e8 100755 --- a/modules/erl/euphorik_requests.erl +++ b/modules/erl/euphorik_requests.erl @@ -49,7 +49,7 @@ traiter_donnees(Contenu) -> % authentification d'un client traiter_action("authentification", JSON) -> - euphorik_protocole:login(JSON)); + euphorik_protocole:login(JSON); % un client s'enregistre (pseudo + password) traiter_action("register", JSON) -> euphorik_protocole:register(JSON); @@ -61,20 +61,5 @@ traiter_action("wait_event", JSON) -> euphorik_protocole:wait_event(JSON); % un utilisateur envoie un message traiter_action("put_message", JSON) -> - euphorik_protocole:message(JSON). - - - - -traiter_action([#xmlAttribute{value="register"}], XML) -> - euphorik_protocole:nouveau_user_login(XML); -traiter_action([#xmlAttribute{value="login"}], XML) -> - euphorik_protocole:login(XML); -traiter_action([#xmlAttribute{value="profile"}], XML) -> - euphorik_protocole:profile(XML); -traiter_action([#xmlAttribute{value="refreshMessages"}], XML) -> - euphorik_protocole:refreshMessage(XML); -% un utilisateur envoie un message -traiter_action([#xmlAttribute{value="message"}], XML) -> - euphorik_protocole:message(XML). + euphorik_protocole:put_message(JSON). \ No newline at end of file -- 2.43.0
login
password
password re