/**\r
* Représente l'utilisateur du site.\r
*/\r
-euphorik.Client = function(util) {\r
+euphorik.Client = function(util, communication) {\r
this.util = util;\r
+ this.communication = communication;\r
\r
this.cookie = null;\r
this.regexCookie = /^cookie=([^;]*)/;\r
}\r
};\r
\r
-euphorik.Client.prototype.getJSONLogin = function(login, password) {\r
- return {\r
- "header" : { "action" : "authentification", "version" : euphorik.conf.versionProtocole },\r
- "login" : login,\r
- "password" : password\r
- };\r
-};\r
-\r
-euphorik.Client.prototype.getJSONLoginCookie = function() {\r
- return {\r
- "header" : { "action" : "authentification", "version" : euphorik.conf.versionProtocole },\r
- "cookie" : this.cookie\r
- };\r
-}; \r
-\r
-/**\r
- * le couple (login, password) est facultatif. S'il n'est pas fournit alors il ne sera pas possible\r
- * de s'autentifier avec (login, password).\r
- */\r
-euphorik.Client.prototype.getJSONEnregistrement = function(login, password) {\r
- var mess = {\r
- "header" : { "action" : "register","version" : euphorik.conf.versionProtocole }\r
- };\r
- \r
- if (login && password) {\r
- mess.login = login;\r
- mess.password = password;\r
- }\r
- \r
- mess.profile = this.getJSONProfileInfos();\r
- \r
- return mess;\r
-};\r
-\r
euphorik.Client.prototype.getJSONConversations = function() {\r
var conversations = [];\r
this.conversations.each(function(i, conv) {\r
\r
euphorik.Client.prototype.getJSONProfile = function() {\r
return {\r
- "header" : { "action" : "set_profile", "version" : euphorik.conf.versionProtocole },\r
"cookie" : this.cookie,\r
"login" : this.login,\r
"password" : this.password,\r
if (!this.cookie) {\r
return false;\r
}\r
- return this.connexion(this.getJSONLoginCookie());\r
+ return this.connexion("authentification", { "cookie" : this.cookie });\r
};\r
\r
euphorik.Client.prototype.connexionLogin = function(login, password) {\r
- return this.connexion(this.getJSONLogin(login, password));\r
+ return this.connexion("authentification", {"login" : login, "password" : password });\r
};\r
\r
euphorik.Client.prototype.enregistrement = function(login, password) { \r
}\r
return false;\r
} else {\r
- return this.connexion(this.getJSONEnregistrement(login, password));\r
+ return this.connexion("register", this.getJSONEnregistrement(login, password));\r
}\r
};\r
\r
+/**\r
+ * le couple (login, password) est facultatif. S'il n'est pas fournit alors il ne sera pas possible\r
+ * de s'autentifier avec (login, password).\r
+ */\r
+euphorik.Client.prototype.getJSONEnregistrement = function(login, password) {\r
+ var mess = {};\r
+ \r
+ if (login && password) {\r
+ mess.login = login;\r
+ mess.password = password;\r
+ }\r
+ \r
+ mess.profile = this.getJSONProfileInfos();\r
+ \r
+ return mess;\r
+};\r
+\r
/**\r
* Connexion. Réalisée de manière synchrone.\r
*/\r
-euphorik.Client.prototype.connexion = function(messageJson) {\r
+euphorik.Client.prototype.connexion = function(action, messageJson) {\r
var thisClient = this;\r
- jQuery.ajax({\r
- async: false,\r
- type: "POST",\r
- url: "request",\r
- dataType: "json",\r
- data: this.util.jsonVersAction(messageJson),\r
- success:\r
- function(data){\r
- if (data.reply === "error") {\r
- thisClient.util.messageDialogue(data.error_message);\r
- // suppression du cookie actuel, cas où le cookie du client ne permet pas une authentification\r
- thisClient.delCookie();\r
- } else {\r
- thisClient.chargerDonnees(data);\r
- }\r
- }\r
- });\r
+ \r
+ this.communication.requete(\r
+ action,\r
+ messageJson,\r
+ function(data) {\r
+ thisClient.chargerDonnees(data);\r
+ },\r
+ function(data) {\r
+ thisClient.util.messageDialogue(data.error_message);\r
+ thisClient.delCookie(); // suppression du cookie actuel, cas où le cookie du client ne permet pas une authentification\r
+ },\r
+ false\r
+ );\r
return this.authentifie();\r
};\r
\r
\r
var thisClient = this;\r
var ok = true;\r
- jQuery.ajax({\r
- async: async,\r
- type: "POST",\r
- url: "request",\r
- dataType: "json",\r
- data: this.util.jsonVersAction(this.getJSONProfile()),\r
- success:\r
- function(data) {\r
- if (data.reply === "error") {\r
- thisClient.util.messageDialogue(data.error_message);\r
- ok = false;\r
- } else {\r
- thisClient.majBulle();\r
- }\r
- }\r
- });\r
+ \r
+ this.communication.requete(\r
+ "set_profile",\r
+ this.getJSONProfile(),\r
+ function(data) {\r
+ thisClient.majBulle(); \r
+ },\r
+ function(data) {\r
+ thisClient.util.messageDialogue(data.error_message);\r
+ ok = false;\r
+ },\r
+ async\r
+ );\r
\r
return ok;\r
};\r
\r
euphorik.Client.prototype.slap = function(userId, raison) {\r
var thisClient = this;\r
- \r
- jQuery.ajax({\r
- type: "POST",\r
- url: "request",\r
- dataType: "json",\r
- data: this.util.jsonVersAction({\r
- "header" : { "action" : "slap", "version" : euphorik.conf.versionProtocole },\r
- "cookie" : thisClient.cookie,\r
- "user_id" : userId,\r
- "reason" : raison\r
- }),\r
- success: \r
- function(data) {\r
- if (data.reply === "error") {\r
- thisClient.util.messageDialogue(data.error_message);\r
- }\r
- }\r
- });\r
+ this.communication.requete("slap", { "cookie" : thisClient.cookie, "user_id" : userId, "reason" : raison });\r
};\r
\r
-euphorik.Client.prototype.ban = function(userId, raison, minutes)\r
-{\r
+euphorik.Client.prototype.ban = function(userId, raison, minutes) {\r
var thisClient = this;\r
\r
// par défaut un ban correspond à 3 jours\r
minutes = minutes || euphorik.conf.tempsBan;\r
- \r
- jQuery.ajax({\r
- type: "POST",\r
- url: "request",\r
- dataType: "json",\r
- data: this.util.jsonVersAction({\r
- "header" : { "action" : "ban", "version" : euphorik.conf.versionProtocole },\r
- "cookie" : thisClient.cookie,\r
- "duration" : minutes,\r
- "user_id" : userId,\r
- "reason" : raison\r
- }),\r
- success: \r
- function(data) {\r
- if (data.reply === "error") {\r
- thisClient.util.messageDialogue(data.error_message);\r
- }\r
- }\r
- });\r
+ this.communication.requete("ban", { "cookie" : thisClient.cookie, "duration" : minutes, "user_id" : userId, "reason" : raison });\r
};\r
\r
euphorik.Client.prototype.kick = function(userId, raison) {\r