X-Git-Url: http://git.euphorik.ch/?a=blobdiff_plain;f=modules%2Ferl%2Feuphorik_protocole.erl;h=8fad0e9e585dded3b355462f7d93a17a0d8650fb;hb=bacec85920574375f4b8df20d6a0457e1fffc658;hp=99eb300fa530e9ee7b6338d11dbf375f3d738b08;hpb=897468be6fa01ab87f38189f2daf266f3289c9fb;p=euphorik.git diff --git a/modules/erl/euphorik_protocole.erl b/modules/erl/euphorik_protocole.erl index 99eb300..8fad0e9 100755 --- a/modules/erl/euphorik_protocole.erl +++ b/modules/erl/euphorik_protocole.erl @@ -1,55 +1,58 @@ % 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. -% 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 -]). +]). + -include_lib("xmerl/include/xmerl.hrl"). -include("../include/euphorik_bd.hrl"). -include("../include/euphorik_defines.hrl"). -% 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 +% 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)). -% Un nouvel utilisateur doit être créé. +% Un nouvel utilisateur doit être créé. +% Obolète : le captcha n'existe plus % Action est un xmlElement(). -nouveau_user_captcha(Action) -> - simple_xml_to_string( - case {xmerl_xpath:string("captchaCrypt", Action), xmerl_xpath:string("captchaInput", Action)} of - {[#xmlElement{content = [#xmlText{value = C1}]}], [#xmlElement{content = [#xmlText{value = C2}]}]} -> - C2_crypt = common:crypt(C2), - if C1 =:= C2_crypt -> - Cookie = generer_cookie(), - User = euphorik_minichat:nouveau_user("Paul", Cookie), - xml_reponse_login_ok(User); - true -> - xml_reponse_login_pas_ok("Captcha incorrect") - end; - _ -> - xml_reponse_login_pas_ok("XML malformé") - end - ). +%~ nouveau_user_captcha(Action) -> + %~ simple_xml_to_string( + %~ case {xmerl_xpath:string("captchaCrypt", Action), xmerl_xpath:string("captchaInput", Action)} of + %~ {[#xmlElement{content = [#xmlText{value = C1}]}], [#xmlElement{content = [#xmlText{value = C2}]}]} -> + %~ C2_crypt = common:crypt(C2), + %~ if C1 =:= C2_crypt -> + %~ Cookie = generer_cookie(), + %~ User = euphorik_minichat:nouveau_user("Paul", Cookie), + %~ xml_reponse_login_ok(User); + %~ true -> + %~ xml_reponse_login_pas_ok("Captcha incorrect") + %~ end; + %~ _ -> + %~ xml_reponse_login_pas_ok("XML malformé") + %~ end + %~ ). -% Une utilisateur s'enregistre avec un tuple {Login, Password}. +% Une utilisateur s'enregistre avec un tuple {Login, Password}. +% @spec nouveau_user_login(xmerl:xmlElement()) -> string() nouveau_user_login(Action) -> {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}]}]} -> @@ -109,7 +112,16 @@ profile(Action) -> Pseudo = case xmerl_xpath:string("pseudo", Action) of [#xmlElement{content = [#xmlText{value = P2}]}] -> P2; _ -> Login end, Email = case xmerl_xpath:string("email", Action) of [#xmlElement{content = [#xmlText{value = E}]}] -> E; _ -> undefined end, Css = case xmerl_xpath:string("css", Action) of [#xmlElement{content = [#xmlText{value = C}]}] -> C; _ -> undefined end, - case euphorik_minichat:set_profile(Cookie, Login, Password, Pseudo, Email, Css) of + Page_principale = case xmerl_xpath:string("pagePrincipale", Action) of [#xmlElement{content = [#xmlText{value = P3}]}] -> list_to_integer(P3); _ -> undefined end, + Conversations = lists:map( + fun(Conv) -> + [#xmlElement{content = [#xmlText{value = Id_racine_str}]}] = xmerl_xpath:string("racine", Conv), + [#xmlElement{content = [#xmlText{value = Page_conv_str}]}] = xmerl_xpath:string("page", Conv), + {erlang:list_to_integer(Id_racine_str, 36), list_to_integer(Page_conv_str)} + end, + xmerl_xpath:string("conversation", Action) + ), + case euphorik_minichat:set_profile(Cookie, Login, Password, Pseudo, Email, Css, Page_principale, Conversations) of ok -> xml_reponse_profile_ok(); login_deja_pris -> @@ -149,16 +161,15 @@ refreshMessage(Action) -> _ -> inconnu end, % extraction des conversations en [{id, page}, ..] - Conversations = lists:map( - fun(Conv) -> - [#xmlElement{content = [#xmlText{value = Id_racine_str}]}] = xmerl_xpath:string("racine", Conv), - [#xmlElement{content = [#xmlText{value = Page_conv_str}]}] = xmerl_xpath:string("page", Conv), - {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]), + % Obsolète : obtenu depuis la table 'user' + %~ Conversations = lists:map( + %~ fun(Conv) -> + %~ [#xmlElement{content = [#xmlText{value = Id_racine_str}]}] = xmerl_xpath:string("racine", Conv), + %~ [#xmlElement{content = [#xmlText{value = Page_conv_str}]}] = xmerl_xpath:string("page", Conv), + %~ {erlang:list_to_integer(Id_racine_str, 36), erlang:list_to_integer(Page_conv_str)} + %~ end, + %~ xmerl_xpath:string("conversation", Action) + %~ ), % accrochez-vous ca va siouxer ;) [{reponse, [{name, "refreshMessages"}], lists:map( @@ -195,8 +206,8 @@ refreshMessage(Action) -> ) ] } - end, - Poulpe + end, + euphorik_minichat_conversation:conversations(User#user.conversations, Nb_message, Dernier_id, Page) ) }]; _ -> @@ -278,7 +289,6 @@ format_date(Date) -> %%%%%%%%% %%%%%%%%% simple_xml_to_string(XML) -> - io:format("~p~n", [XML]), lists:flatten(xmerl:export_simple(XML, xmerl_xml, [{prolog, ["\n"]}])). @@ -293,8 +303,20 @@ xml_reponse_login_ok(User) -> {pseudo, [User#user.pseudo]}, {login, [User#user.login]}, {email, [User#user.email]}, - {css, [User#user.css]} - ] + {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 + ) }]. @@ -359,14 +381,16 @@ xml_reponse_message(Ok) -> ] } ]. - -xml_reponse_generation_captcha(Chemin, Captcha) -> - [ - {reponse, [{name, "generationCaptcha"}], - [ - {chemin, [], [Chemin]}, - {captchaCrypt, [], [Captcha]} - ] - } - ]. + + +% Obsolète +%~ xml_reponse_generation_captcha(Chemin, Captcha) -> + %~ [ + %~ {reponse, [{name, "generationCaptcha"}], + %~ [ + %~ {chemin, [], [Chemin]}, + %~ {captchaCrypt, [], [Captcha]} + %~ ] + %~ } + %~ ]. %%%%%%%%% %%%%%%%%%