% coding: utf-8
-% Ce module gére les différents message envoyé par le client (javascript)
+% 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.\r
-% Example XML : http://www.erlang.org/doc/apps/xmerl/xmerl_ug.html
-% Auteur : G.Burri
-% Date : 29.10.2007
+% Example XML : http://www.erlang.org/doc/apps/xmerl/xmerl_ug.html.
+% @author G.Burri
-module(euphorik_protocole).
-export([
- generation_captcha/1,
- nouveau_user_captcha/1,
+ %generation_captcha/1, Obsolète
+ %nouveau_user_captcha/1, Obsolète
nouveau_user_login/1,
login/1,
logout/1,
profile/1,
refreshMessage/1,
message/1
-]).
+]).\r
+
-include_lib("xmerl/include/xmerl.hrl").
-include("../include/euphorik_bd.hrl").\r
-include("../include/euphorik_defines.hrl").\r
-% Génère un nouveau captchat dans ?DOSSIER_CAPTCHA
-generation_captcha(_) ->
- {Mot_crypt, Nom_fichier} = captcha:create(5, ?DOSSIER_CAPTCHA),
- simple_xml_to_string(xml_reponse_generation_captcha(?DOSSIER_CAPTCHA_RELATIF "/" ++ Nom_fichier, Mot_crypt)).
+% Génère un nouveau captchat dans ?DOSSIER_CAPTCHA\r
+% Obsolète
+%~ generation_captcha(_) ->
+ %~ {Mot_crypt, Nom_fichier} = captcha:create(5, ?DOSSIER_CAPTCHA),
+ %~ simple_xml_to_string(xml_reponse_generation_captcha(?DOSSIER_CAPTCHA_RELATIF "/" ++ Nom_fichier, Mot_crypt)).
\r
-% Un nouvel utilisateur doit être créé.
+% Un nouvel utilisateur doit être créé.\r
+% Obolète : le captcha n'existe plus
% Action est un xmlElement().
-nouveau_user_captcha(Action) ->
- simple_xml_to_string(\r
- case {xmerl_xpath:string("captchaCrypt", Action), xmerl_xpath:string("captchaInput", Action)} of\r
- {[#xmlElement{content = [#xmlText{value = C1}]}], [#xmlElement{content = [#xmlText{value = C2}]}]} ->\r
- C2_crypt = common:crypt(C2),\r
- if C1 =:= C2_crypt ->\r
- Cookie = generer_cookie(),\r
- User = euphorik_minichat:nouveau_user("Paul", Cookie),\r
- xml_reponse_login_ok(User);\r
- true ->
- xml_reponse_login_pas_ok("Captcha incorrect")\r
- end;
- _ ->
- xml_reponse_login_pas_ok("XML malformé")\r
- end
- ).
+%~ nouveau_user_captcha(Action) ->
+ %~ simple_xml_to_string(\r
+ %~ case {xmerl_xpath:string("captchaCrypt", Action), xmerl_xpath:string("captchaInput", Action)} of\r
+ %~ {[#xmlElement{content = [#xmlText{value = C1}]}], [#xmlElement{content = [#xmlText{value = C2}]}]} ->\r
+ %~ C2_crypt = common:crypt(C2),\r
+ %~ if C1 =:= C2_crypt ->\r
+ %~ Cookie = generer_cookie(),\r
+ %~ User = euphorik_minichat:nouveau_user("Paul", Cookie),\r
+ %~ xml_reponse_login_ok(User);\r
+ %~ true ->
+ %~ xml_reponse_login_pas_ok("Captcha incorrect")\r
+ %~ end;
+ %~ _ ->
+ %~ xml_reponse_login_pas_ok("XML malformé")\r
+ %~ end
+ %~ ).
-% Une utilisateur s'enregistre avec un tuple {Login, Password}.
+% Une utilisateur s'enregistre avec un tuple {Login, Password}.\r
+% @spec nouveau_user_login(xmerl:xmlElement()) -> string()
nouveau_user_login(Action) ->\r
{Login, Password, Login_deja_pris} = case {xmerl_xpath:string("login", Action), xmerl_xpath:string("password", Action)} of\r
{[#xmlElement{content = [#xmlText{value = L}]}], [#xmlElement{content = [#xmlText{value = P}]}]} ->\r
{erlang:list_to_integer(Id_racine_str, 36), erlang:list_to_integer(Page_conv_str)}
end,
xmerl_xpath:string("conversation", Action)
- ),
- Poulpe = euphorik_minichat_conversation:conversations(Conversations, Nb_message, Dernier_id, Page),
- io:format("Poulpe = ~p~n", [Poulpe]),\r
+ ),\r
% accrochez-vous ca va siouxer ;)
[{reponse, [{name, "refreshMessages"}],\r
lists:map(\r
)
]
}\r
- end,
- Poulpe\r
+ end,
+ euphorik_minichat_conversation:conversations(Conversations, Nb_message, Dernier_id, Page)\r
)
}];
_ ->
%%%%%%%%% <Réponses XML> %%%%%%%%%
simple_xml_to_string(XML) ->
- io:format("~p~n", [XML]),
lists:flatten(xmerl:export_simple(XML, xmerl_xml, [{prolog, ["<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n"]}])).
]\r
}\r
].
-
-xml_reponse_generation_captcha(Chemin, Captcha) ->
- [
- {reponse, [{name, "generationCaptcha"}],
- [
- {chemin, [], [Chemin]},
- {captchaCrypt, [], [Captcha]}
- ]
- }
- ].
+\r
+\r
+% Obsolète
+%~ xml_reponse_generation_captcha(Chemin, Captcha) ->
+ %~ [
+ %~ {reponse, [{name, "generationCaptcha"}],
+ %~ [
+ %~ {chemin, [], [Chemin]},
+ %~ {captchaCrypt, [], [Captcha]}
+ %~ ]
+ %~ }
+ %~ ].
%%%%%%%%% </réponses XML> %%%%%%%%%