From 11fe8f6d268a9b1c0a773294cc7d70ffdb6afb30 Mon Sep 17 00:00:00 2001 From: Greg Burri Date: Sat, 26 Jul 2008 18:21:26 +0000 Subject: [PATCH] =?utf8?q?FIX=20probl=C3=A8me=20de=20gestion=20du=20profil?= =?utf8?q?e,=20apr=C3=A8s=20ouverture=20d'une=20conversation=20puis=20enre?= =?utf8?q?gistrement=20la=20conversation=20n'=C3=A9tait=20pas=20gard=C3=A9?= =?utf8?q?e=20FIX=20autres...?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- doc/protocole3.txt | 31 ++++---- js/client.js | 14 +++- js/pageMinichat/conversation.js | 1 - js/pageMinichat/message.js | 4 +- js/pageProfile.js | 1 + js/pageRegister.js | 113 +++++++++++++++-------------- modules/erl/euphorik_bd.erl | 80 +++++++++----------- modules/erl/euphorik_protocole.erl | 103 +++++++++++++++++--------- modules/include/euphorik_bd.hrl | 2 +- styles/1/euphorik.css | 4 + 10 files changed, 195 insertions(+), 158 deletions(-) diff --git a/doc/protocole3.txt b/doc/protocole3.txt index 55e2115..c8642ab 100644 --- a/doc/protocole3.txt +++ b/doc/protocole3.txt @@ -55,9 +55,10 @@ Le mot de passe est hashé en md5. c -> s { - "header" : {action : "authentification", version : 3}, + "header" : {action : "register", version : 3}, "login" : "paul", - "password" : "IJKJDHHSAD9081238" + "password" : "IJKJDHHSAD9081238", + "profile_infos" : { .. } // voir } ou { @@ -74,16 +75,7 @@ ou 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", + "status" : "auth_registered" | "auth_not_registered", "cookie" : "LKJDLAKSJBFLKASN", "id" : 193, "nick" : "Paul", @@ -109,12 +101,8 @@ c -> s === Profile === -c -> s + { - "header" : {action : "set_profile", version : 3}, - "cookie" : "LKJDLAKSJBFLKASN", - "login" : "paul49", - "password" : "IJKJDHHSAD9081238", "nick" : "Paul", "email" : "paul@pierre.com", "css" : "css/3/euphorik.css", @@ -125,6 +113,15 @@ c -> s "conversations" : [{"root" : 3, "minimized" : true}, "ostentatious_master" : "invisible" | "light" | "heavy" } + +c -> s + { + "header" : {action : "set_profile", version : 3}, + "cookie" : "LKJDLAKSJBFLKASN", + "login" : "paul49", + "password" : "IJKJDHHSAD9081238", + "profile_infos" : + } s -> c diff --git a/js/client.js b/js/client.js index d7240a6..73622a4 100644 --- a/js/client.js +++ b/js/client.js @@ -180,13 +180,17 @@ euphorik.Client.prototype.getJSONLoginCookie = function() { * de s'autentifier avec (login, password). */ euphorik.Client.prototype.getJSONEnregistrement = function(login, password) { - var mess = { "header" : { "action" : "register", "version" : euphorik.conf.versionProtocole } }; + var mess = { + "header" : { "action" : "register","version" : euphorik.conf.versionProtocole } + }; if (login && password) { mess.login = login; mess.password = password; } + mess.profile_infos = this.getJSONProfileInfos(); + return mess; }; @@ -204,6 +208,12 @@ euphorik.Client.prototype.getJSONProfile = function() { "cookie" : this.cookie, "login" : this.login, "password" : this.password, + "profile_infos" : this.getJSONProfileInfos() + }; +}; + +euphorik.Client.prototype.getJSONProfileInfos = function() { + return { "nick" : this.pseudo, "email" : this.email, "css" : this.css, @@ -302,7 +312,7 @@ euphorik.Client.prototype.enregistrement = function(login, password) { }; /** - * Connexion. Réalisé de manière synchrone. + * Connexion. Réalisée de manière synchrone. */ euphorik.Client.prototype.connexion = function(messageJson) { var thisClient = this; diff --git a/js/pageMinichat/conversation.js b/js/pageMinichat/conversation.js index 3948629..238976b 100644 --- a/js/pageMinichat/conversation.js +++ b/js/pageMinichat/conversation.js @@ -238,7 +238,6 @@ euphorik.Conversation.prototype.flush = function() { var thisConversation = this; var reverse = this.client.chatOrder === "reverse"; - // est-ce que le prochain message est pair ? (permet d'alterner le style des messages) var messagePair = (this.idDernierMessageAffiche === 0 ? true : ($("#" + this.getId() + " .messages div:" + (reverse ? "first" : "last")).attr("class").search("messagePair") === -1) ); diff --git a/js/pageMinichat/message.js b/js/pageMinichat/message.js index 67ba7e6..a3d4d32 100644 --- a/js/pageMinichat/message.js +++ b/js/pageMinichat/message.js @@ -111,7 +111,9 @@ euphorik.Message.prototype.getConversation = function(messages) { * Aucun callback n'est affecté. */ euphorik.Message.prototype.XHTML = function(messagePair, pre) { - messagePair = messagePair || true; + if (messagePair === undefined) { + messagePair = true; + } pre = pre || ""; thisMessage = this; diff --git a/js/pageProfile.js b/js/pageProfile.js index fa7235b..b272400 100755 --- a/js/pageProfile.js +++ b/js/pageProfile.js @@ -113,6 +113,7 @@ euphorik.PageProfile.prototype.getHTML = function() { ' ' + ' login' + ' ' + + (this.client.authentifie() ? '' : ' (sensible à la casse)') + ' ' + ' ' + ' password' + diff --git a/js/pageRegister.js b/js/pageRegister.js index b422f5d..f1abd70 100755 --- a/js/pageRegister.js +++ b/js/pageRegister.js @@ -14,64 +14,65 @@ // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License -// along with Euphorik. If not, see . - -euphorik.PageRegister = function(client, formateur, util) { - this.nom = "register"; - - this.client = client; - this.formateur = formateur; - this.util = util; -}; - -euphorik.PageRegister.prototype.contenu = function() { - return '
' + - ' ' + - ' ' + - ' ' + - ' ' + - ' ' + - ' ' + - ' ' + - ' ' + - ' ' + - ' ' + - ' ' + - ' ' + - ' ' + - ' ' + - ' ' + - ' ' + - '
login
password
password re
' + - '
' + - '
'; -}; - -euphorik.PageRegister.prototype.charger = function() { - $("#page form#register").submit(function(){ return false; }); - - var thisPage = this; - - $("#page form#register button").click( +// along with Euphorik. If not, see . + +euphorik.PageRegister = function(client, formateur, util) { + this.nom = "register"; + + this.client = client; + this.formateur = formateur; + this.util = util; +}; + +euphorik.PageRegister.prototype.contenu = function() { + return '
' + + ' ' + + ' ' + + ' ' + + ' ' + + ' ' + + ' ' + + ' ' + + ' ' + + ' ' + + ' ' + + ' ' + + ' ' + + ' ' + + ' ' + + ' ' + + ' ' + + ' ' + + '
login(sensible à la casse)
password
password re
' + + '
' + + '
'; +}; + +euphorik.PageRegister.prototype.charger = function() { + $("#page form#register").submit(function(){ return false; }); + + var thisPage = this; + + $("#page form#register button").click( function() { if ($("#page form#register input.captcha").val() !== "") { return; } - - var login = $("#page form#register input.login").val().trim(); - var password = $("#page form#register input.password").val(); - var passwordRe = $("#page form#register input.passwordRe").val(); - - if (login === "") { - thisPage.util.messageDialogue("Le login ne doit pas être vide"); - } else if (password === "" && passwordRe === "") { - thisPage.util.messageDialogue("Un mot de passe est obligatoire"); - } else if (password !== passwordRe) { - thisPage.util.messageDialogue("Les mots de passes ne correspondent pas"); - } else if(thisPage.client.enregistrement(login, thisPage.util.md5(password))) { - thisPage.util.messageDialogue("Enregistrement réussi"); - thisPage.pages.afficherPage("minichat"); - } - } - ); + + var login = $("#page form#register input.login").val().trim(); + var password = $("#page form#register input.password").val(); + var passwordRe = $("#page form#register input.passwordRe").val(); + + if (login === "") { + thisPage.util.messageDialogue("Le login ne doit pas être vide"); + } else if (password === "" && passwordRe === "") { + thisPage.util.messageDialogue("Un mot de passe est obligatoire"); + } else if (password !== passwordRe) { + thisPage.util.messageDialogue("Les mots de passes ne correspondent pas"); + } else if(thisPage.client.enregistrement(login, thisPage.util.md5(password))) { + thisPage.util.messageDialogue("Enregistrement réussi"); + thisPage.pages.afficherPage("minichat"); + } + } + ); }; diff --git a/modules/erl/euphorik_bd.erl b/modules/erl/euphorik_bd.erl index 0539910..f5fa258 100755 --- a/modules/erl/euphorik_bd.erl +++ b/modules/erl/euphorik_bd.erl @@ -25,9 +25,9 @@ -module(euphorik_bd). -export([ % users : - nouveau_user/2, nouveau_user/3, - set_profile/12, + nouveau_user/4, + set_profile/1, update_date_derniere_connexion/1, update_ip/2, update_pseudo_user/2, @@ -90,10 +90,11 @@ % Ajoute un nouveau user et le renvoie -nouveau_user(Pseudo, Cookie) -> +% User_infos représente le profile de l'utilisateur, il est possibe qu'il soit vide +nouveau_user(Pseudo, Cookie, User_infos) -> F = fun() -> Id = nouvel_id(user), - User = #user{id = Id, cookie = Cookie, pseudo = Pseudo, date_creation = now(), date_derniere_connexion = now()}, + User = User_infos#user{id = Id, cookie = Cookie, pseudo = Pseudo, date_creation = now(), date_derniere_connexion = now()}, mnesia:write(User), User end, @@ -101,55 +102,40 @@ nouveau_user(Pseudo, Cookie) -> % Ajoute un nouveau user et le renvoie -nouveau_user(Login, Password, Cookie) -> +% User_infos représente le profile de l'utilisateur, il est possibe qu'il soit vide +nouveau_user(Login, Password, Cookie, User_infos) -> F = fun() -> Id = nouvel_id(user), - User = #user{id = Id, cookie = Cookie, pseudo = Login, login = Login, password = Password, date_creation = now(), date_derniere_connexion = now()}, + User = User_infos#user{id = Id, cookie = Cookie, pseudo = Login, login = Login, password = Password, date_creation = now(), date_derniere_connexion = now()}, mnesia:write(User), User end, resultat_transaction(mnesia:transaction(F)). + - -% Mise à par Cookie les autres peuvent être undefined ce qui veut dire qu'ils ne seront pas modifié. -% Conversation est de type [{int(), bool()}] où l'entier est la racine, le booléen indique si la conversation est réduite ou non -% Ostentatious_master peut valoir invisible, light ou heavy -set_profile(Cookie, Login, Password, Pseudo, Email, Css, Chat_order, Nick_format, View_times, View_tooltips, Conversations, Ostentatious_master) -> - if Nick_format =:= nick; Nick_format =:= login; Nick_format =:= nick_login, - Ostentatious_master =:= invisible; Ostentatious_master =:= light; Ostentatious_master =:= heavy -> - resultat_transaction(mnesia:transaction( - fun() -> - case user_by_cookie(Cookie) of - {ok, User} -> - case user_by_login(Login) of - {ok, U} when Login =/= [], U#user.id =/= User#user.id -> - login_deja_pris; - _ -> - User_modifie = User#user{ - % TODO : pourquoi ne pas tester avec la valeur "undefined" plutôt qu'avec "is_list" ? - % TODO : validation plus strict des données (pas de page négative dans les conv par exemple) - login = if is_list(Login) -> Login; true -> User#user.login end, - password = if is_list(Password) andalso Password =/= [] -> Password; true -> User#user.password end, - pseudo = if is_list(Pseudo) -> Pseudo; true -> User#user.pseudo end, - email = if is_list(Email) -> Email; true -> User#user.email end, - css = if is_list(Css) -> Css; true -> User#user.css end, - chat_order = Chat_order, - nick_format = Nick_format, - view_times = View_times, - view_tooltips = View_tooltips, - conversations = if is_list(Conversations) -> Conversations; true -> User#user.conversations end, - ostentatious_master = Ostentatious_master - }, - mnesia:write(User_modifie), - ok - end; - _ -> erreur - end - end - )); - true -> - erreur - end. +% Définit les données d'une utilisateur. +set_profile(User) -> + resultat_transaction(mnesia:transaction( + fun() -> + case user_by_cookie(User#user.cookie) of + {ok, User_existant} -> + case user_by_login(User#user.login) of + {ok, U} when User#user.login =/= [], U#user.id =/= User_existant#user.id -> + login_deja_pris; + _ -> + mnesia:write( + User#user{ + id = User_existant#user.id, + login = if User_existant#user.login =:= [] -> User#user.login; true -> User_existant#user.login end, % on ne peut pas changer de login sauf si on en a pas ! + password = if User#user.password =:= [] -> User_existant#user.password; true -> User#user.password end + } + ), + ok + end; + _ -> erreur + end + end + )). % Met à jour la date de la dernière connexion d'un utilisateur à maintenant @@ -163,7 +149,7 @@ update_date_derniere_connexion(User_id) -> mnesia:abort("update_date_derniere_connexion: User inconnu") end end - ). + ). % Met à jour l'ip d'un user diff --git a/modules/erl/euphorik_protocole.erl b/modules/erl/euphorik_protocole.erl index d8bfa89..c3dfbbe 100755 --- a/modules/erl/euphorik_protocole.erl +++ b/modules/erl/euphorik_protocole.erl @@ -43,14 +43,14 @@ % Une utilisateur s'enregistre avec un tuple {Login, Password}. -register([{login, Login}, {password, Password}], IP) -> +register([{login, Login}, {password, Password}, {profile_infos, Profile_infos}], IP) -> Can_register = euphorik_bd:can_register(IP), if Can_register -> case euphorik_bd:user_by_login(Login) of {ok, _} -> erreur("Login déjà existant"); _ -> - User = euphorik_bd:nouveau_user(Login, Password, generer_cookie()), + User = euphorik_bd:nouveau_user(Login, Password, generer_cookie(), user_from_json(Profile_infos)), euphorik_bd:update_ip(User#user.id, IP), json_reponse_login_ok(User) end; @@ -58,10 +58,10 @@ register([{login, Login}, {password, Password}], IP) -> erreur_register_flood() end; % Enregistrement sans {Login, Password} -register([], IP) -> +register([{profile_infos, Profile_infos}], IP) -> Can_register = euphorik_bd:can_register(IP), if Can_register -> - User = euphorik_bd:nouveau_user("", generer_cookie()), + User = euphorik_bd:nouveau_user("", generer_cookie(), user_from_json(Profile_infos)), euphorik_bd:update_ip(User#user.id, IP), json_reponse_login_ok(User); true -> @@ -115,16 +115,44 @@ profile( {cookie, Cookie}, {login, Login}, {password, Password}, - {nick, Pseudo}, - {email, Email}, - {css, Css}, - {chat_order, Chat_order_str}, - {nick_format, Nick_format_str}, - {view_times, View_times}, - {view_tooltips, View_tooltips}, - {conversations, {array, Conversations_json}}, - {ostentatious_master, Ostentatious_master} + {profile_infos, Profile_infos} ] +) -> + case user_from_json(Profile_infos) of + {erreur, E} -> E; + UserInfos -> + User = UserInfos#user { + cookie = Cookie, + login = Login, + password = Password + }, + % TODO : pas très beau, mieux vaut construire un #user + case euphorik_bd:set_profile(User) of + ok -> + json_reponse_ok(); + login_deja_pris -> + erreur("Login déjà pris"); + _ -> + erreur("Impossible de mettre à jour le profile") + end + end. + + +% Construit un #user à partir des données JSON +user_from_json( + {struct, + [ + {nick, Pseudo}, + {email, Email}, + {css, Css}, + {chat_order, Chat_order_str}, + {nick_format, Nick_format_str}, + {view_times, View_times}, + {view_tooltips, View_tooltips}, + {conversations, {array, Conversations_json}}, + {ostentatious_master, Ostentatious_master_str} + ] + } ) -> % décomposition de la strucure JSON Conversations = lists:foldr( @@ -140,26 +168,35 @@ profile( [], Conversations_json ), - % TODO : pas très beau, mieux vaut construire un #user - case euphorik_bd:set_profile( - Cookie, - Login, - Password, - Pseudo, - Email, - Css, - list_to_atom(Chat_order_str), - list_to_atom(Nick_format_str), - View_times, - View_tooltips, - Conversations, - list_to_atom(Ostentatious_master)) of - ok -> - json_reponse_ok(); - login_deja_pris -> - erreur("Login déjà pris"); - _ -> - erreur("Impossible de mettre à jour le profile") + % vérification des données JSON + Chat_order = list_to_atom(Chat_order_str), + Chat_order_valide = lists:any(fun(E) -> E =:= Chat_order end, [reverse, chrono]), + if not Chat_order_valide -> + {erreur, Chat_order_str ++ " n'est pas une valeur acceptée pour 'chat_order'"}; + true -> + Nick_format = list_to_atom(Nick_format_str), + Nick_format_valide = lists:any(fun(E) -> E =:= Nick_format end, [nick, login, nick_login]), + if not Nick_format_valide -> + {erreur, Nick_format_str ++ " n'est pas une valeur acceptée pour 'nick_format'"}; + true -> + Ostentatious_master = list_to_atom(Ostentatious_master_str), + Ostentatious_master_valide = lists:any(fun(E) -> E =:= Ostentatious_master end, [invisible, light, heavy]), + if not Ostentatious_master_valide -> + {erreur, Ostentatious_master_str ++ " n'est pas une valeur acceptée pour 'ostentatious_master'"}; + true -> + #user{ + pseudo = Pseudo, + email = Email, + css = Css, + chat_order = Chat_order, + nick_format = Nick_format, + view_times = View_times, + view_tooltips = View_tooltips, + conversations = Conversations, + ostentatious_master = Ostentatious_master + } + end + end end. diff --git a/modules/include/euphorik_bd.hrl b/modules/include/euphorik_bd.hrl index 053c046..038dae8 100755 --- a/modules/include/euphorik_bd.hrl +++ b/modules/include/euphorik_bd.hrl @@ -64,9 +64,9 @@ { id, cookie, % string() - pseudo = [], % string() login = [], % string() password = [], % string() (md5) + pseudo = [], % string() email = [], % string() date_creation, % erlang:now() date_derniere_connexion, % erlang:now(), est mis à jour lors de n'importe quelle activitée (envoie de message par exemple) diff --git a/styles/1/euphorik.css b/styles/1/euphorik.css index 0383346..76cce82 100755 --- a/styles/1/euphorik.css +++ b/styles/1/euphorik.css @@ -17,6 +17,10 @@ body { background-color: #f6dfc2; } +td { + padding-right: 4px +} + #container { height: auto; margin: 0px; -- 2.43.0