X-Git-Url: http://git.euphorik.ch/?p=euphorik.git;a=blobdiff_plain;f=js%2Fclient.js;h=e01be9e5c8a8563969f6b6d2c4f08a06d864a64d;hp=93e5dae4d1f2b1d8ad921f7012acac710bc3aa96;hb=15f8b5143c6b9dcfe86eda84c22c31826a7f3d1c;hpb=972919ab7f5651cd721eb6eec75f7150fdeaf347 diff --git a/js/client.js b/js/client.js index 93e5dae..e01be9e 100644 --- a/js/client.js +++ b/js/client.js @@ -161,40 +161,6 @@ euphorik.Client.prototype.supprimerConversation = function(num) { } }; -euphorik.Client.prototype.getJSONLogin = function(login, password) { - return { - "header" : { "action" : "authentification", "version" : euphorik.conf.versionProtocole }, - "login" : login, - "password" : password - }; -}; - -euphorik.Client.prototype.getJSONLoginCookie = function() { - return { - "header" : { "action" : "authentification", "version" : euphorik.conf.versionProtocole }, - "cookie" : this.cookie - }; -}; - -/** - * le couple (login, password) est facultatif. S'il n'est pas fournit alors il ne sera pas possible - * de s'autentifier avec (login, password). - */ -euphorik.Client.prototype.getJSONEnregistrement = function(login, password) { - var mess = { - "header" : { "action" : "register","version" : euphorik.conf.versionProtocole } - }; - - if (login && password) { - mess.login = login; - mess.password = password; - } - - mess.profile = this.getJSONProfileInfos(); - - return mess; -}; - euphorik.Client.prototype.getJSONConversations = function() { var conversations = []; this.conversations.each(function(i, conv) { @@ -205,7 +171,6 @@ euphorik.Client.prototype.getJSONConversations = function() { euphorik.Client.prototype.getJSONProfile = function() { return { - "header" : { "action" : "set_profile", "version" : euphorik.conf.versionProtocole }, "cookie" : this.cookie, "login" : this.login, "password" : this.password, @@ -291,11 +256,11 @@ euphorik.Client.prototype.connexionCookie = function() { if (!this.cookie) { return false; } - return this.connexion(this.getJSONLoginCookie()); + return this.connexion("authentification", { "cookie" : this.cookie }); }; euphorik.Client.prototype.connexionLogin = function(login, password) { - return this.connexion(this.getJSONLogin(login, password)); + return this.connexion("authentification", {"login" : login, "password" : password }); }; euphorik.Client.prototype.enregistrement = function(login, password) { @@ -308,10 +273,27 @@ euphorik.Client.prototype.enregistrement = function(login, password) { } return false; } else { - return this.connexion(this.getJSONEnregistrement(login, password)); + return this.connexion("register", this.getJSONEnregistrement(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). + */ +euphorik.Client.prototype.getJSONEnregistrement = function(login, password) { + var mess = {}; + + if (login && password) { + mess.login = login; + mess.password = password; + } + + mess.profile = this.getJSONProfileInfos(); + + return mess; +}; + /** * Connexion. Réalisée de manière synchrone. */ @@ -324,10 +306,11 @@ euphorik.Client.prototype.connexion = function(action, messageJson) { function(data) { thisClient.chargerDonnees(data); }, - function() { + function(data) { thisClient.util.messageDialogue(data.error_message); thisClient.delCookie(); // suppression du cookie actuel, cas où le cookie du client ne permet pas une authentification - } + }, + false ); return this.authentifie(); }; @@ -389,22 +372,19 @@ euphorik.Client.prototype.flush = function(async) { var thisClient = this; var ok = true; - jQuery.ajax({ - async: async, - type: "POST", - url: "request", - dataType: "json", - data: this.util.jsonVersAction(this.getJSONProfile()), - success: - function(data) { - if (data.reply === "error") { - thisClient.util.messageDialogue(data.error_message); - ok = false; - } else { - thisClient.majBulle(); - } - } - }); + + this.communication.requete( + "set_profile", + this.getJSONProfile(), + function(data) { + thisClient.majBulle(); + }, + function(data) { + thisClient.util.messageDialogue(data.error_message); + ok = false; + }, + async + ); return ok; }; @@ -462,51 +442,15 @@ euphorik.Client.prototype.majLogo = function() { euphorik.Client.prototype.slap = function(userId, raison) { var thisClient = this; - - jQuery.ajax({ - type: "POST", - url: "request", - dataType: "json", - data: this.util.jsonVersAction({ - "header" : { "action" : "slap", "version" : euphorik.conf.versionProtocole }, - "cookie" : thisClient.cookie, - "user_id" : userId, - "reason" : raison - }), - success: - function(data) { - if (data.reply === "error") { - thisClient.util.messageDialogue(data.error_message); - } - } - }); + this.communication.requete("slap", { "cookie" : thisClient.cookie, "user_id" : userId, "reason" : raison }); }; -euphorik.Client.prototype.ban = function(userId, raison, minutes) -{ +euphorik.Client.prototype.ban = function(userId, raison, minutes) { var thisClient = this; // par défaut un ban correspond à 3 jours minutes = minutes || euphorik.conf.tempsBan; - - jQuery.ajax({ - type: "POST", - url: "request", - dataType: "json", - data: this.util.jsonVersAction({ - "header" : { "action" : "ban", "version" : euphorik.conf.versionProtocole }, - "cookie" : thisClient.cookie, - "duration" : minutes, - "user_id" : userId, - "reason" : raison - }), - success: - function(data) { - if (data.reply === "error") { - thisClient.util.messageDialogue(data.error_message); - } - } - }); + this.communication.requete("ban", { "cookie" : thisClient.cookie, "duration" : minutes, "user_id" : userId, "reason" : raison }); }; euphorik.Client.prototype.kick = function(userId, raison) {