X-Git-Url: http://git.euphorik.ch/?p=euphorik.git;a=blobdiff_plain;f=modules%2Ferl%2Feuphorik_protocole.erl;h=1b0a49bc4cf10bdb268dd6055b64287c87e26abc;hp=c3dfbbe0406a0c1c56233d9a738ec8f64f91d58c;hb=d1e6f8e7c86f1ee75e854266463541ffedb916c9;hpb=7892ce3f365cbb8b6cc7d7c3799e296fc5fff1a5 diff --git a/modules/erl/euphorik_protocole.erl b/modules/erl/euphorik_protocole.erl index c3dfbbe..1b0a49b 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}, {profile_infos, Profile_infos}], IP) -> +register([{login, Login}, {password, Password}, {profile, Profile_json}], 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_from_json(Profile_infos)), + User = euphorik_bd:nouveau_user(Login, Password, generer_cookie(), profile_from_json(Profile_json)), euphorik_bd:update_ip(User#user.id, IP), json_reponse_login_ok(User) end; @@ -58,10 +58,11 @@ register([{login, Login}, {password, Password}, {profile_infos, Profile_infos}], erreur_register_flood() end; % Enregistrement sans {Login, Password} -register([{profile_infos, Profile_infos}], IP) -> +register([{profile, Profile_json}], IP) -> Can_register = euphorik_bd:can_register(IP), if Can_register -> - User = euphorik_bd:nouveau_user("", generer_cookie(), user_from_json(Profile_infos)), + Profile = profile_from_json(Profile_json), + User = euphorik_bd:nouveau_user(generer_cookie(), Profile#profile{pseudo = ""}), euphorik_bd:update_ip(User#user.id, IP), json_reponse_login_ok(User); true -> @@ -115,19 +116,14 @@ profile( {cookie, Cookie}, {login, Login}, {password, Password}, - {profile_infos, Profile_infos} + {profile, Profile_json} ] ) -> - case user_from_json(Profile_infos) of + case profile_from_json(Profile_json) of {erreur, E} -> E; - UserInfos -> - User = UserInfos#user { - cookie = Cookie, - login = Login, - password = Password - }, + Profile -> % TODO : pas très beau, mieux vaut construire un #user - case euphorik_bd:set_profile(User) of + case euphorik_bd:set_profile(Cookie, Login, Password, Profile) of ok -> json_reponse_ok(); login_deja_pris -> @@ -139,7 +135,7 @@ profile( % Construit un #user à partir des données JSON -user_from_json( +profile_from_json( {struct, [ {nick, Pseudo}, @@ -184,7 +180,7 @@ user_from_json( if not Ostentatious_master_valide -> {erreur, Ostentatious_master_str ++ " n'est pas une valeur acceptée pour 'ostentatious_master'"}; true -> - #user{ + #profile{ pseudo = Pseudo, email = Email, css = Css, @@ -254,12 +250,12 @@ wait_event([{page, "admin"}, {last_troll, Last_troll}]) -> {trolls, {array, lists:map( fun(T) -> - {ok, User} = euphorik_bd:user_by_id(T#troll.id_user), + {ok, #user{profile = Profile} = User} = euphorik_bd:user_by_id(T#troll.id_user), {struct, [ {troll_id, T#troll.id}, {content, T#troll.content}, - {author, User#user.pseudo}, + {author, Profile#profile.pseudo}, {author_id, User#user.id} ] } @@ -467,11 +463,11 @@ ban( case euphorik_bd:user_by_id(User_id) of {ok, User1} -> erreur("Il n'est pas possible de s'auto bannir"); - {ok, User2 = #user{ek_master = false}} -> + {ok, #user{ek_master = false, profile = Profile2} = User2} -> euphorik_bd:ban(User2#user.last_ip, Duration), euphorik_bd:nouveau_message_sys(lists:flatten(io_lib:format("''~s~s'' est ~s pour ~s.~s", [ - User2#user.pseudo, + Profile2#profile.pseudo, if User2#user.login =:= [] -> ""; true -> " (" ++ User2#user.login ++ ")" end, if Duration =< 15 -> "kické"; true -> "banni" end, format_minutes(Duration), @@ -498,21 +494,21 @@ slap( ]) -> % controle que l'utilisateur est un admin case euphorik_bd:user_by_cookie(Cookie) of - {ok, User1 = #user{ek_master = true}} -> + {ok, User1 = #user{ek_master = true, profile = Profile1}} -> case euphorik_bd:user_by_id(User_id) of {ok, User1} -> euphorik_bd:nouveau_message_sys(lists:flatten(io_lib:format("~s s'auto slap~s.", [ - User1#user.pseudo, + Profile1#profile.pseudo, if Reason =/= [] -> " - Raison: " ++ Reason; true -> "" end ] ))), json_reponse_ok(); - {ok, User2 = #user{ek_master = false}} -> + {ok, #user{ek_master = false, profile = Profile2}} -> euphorik_bd:nouveau_message_sys(lists:flatten(io_lib:format("~s se fait slaper par ~s.~s", [ - User2#user.pseudo, - User1#user.pseudo, + Profile2#profile.pseudo, + Profile1#profile.pseudo, if Reason =/= [] -> " - Raison: " ++ Reason; true -> "" end ++ "." ] ))), @@ -700,29 +696,33 @@ json_reponse_ok() -> {struct, [{reply, "ok"}]}. -json_reponse_login_ok(User) -> +json_reponse_login_ok(#user{profile = Profile} = User) -> { struct, [ {reply, "login"}, {status, if (User#user.password =/= []) and (User#user.login =/= []) -> "auth_registered"; true -> "auth_not_registered" end}, {cookie, User#user.cookie}, {id, User#user.id}, - {nick, User#user.pseudo}, {login, User#user.login}, - {email, User#user.email}, - {css, User#user.css}, - {chat_order, atom_to_list(User#user.chat_order)}, - {nick_format, atom_to_list(User#user.nick_format)}, - {view_times, User#user.view_times}, - {view_tooltips, User#user.view_tooltips}, - {conversations, {array, lists:map( - fun({Racine, Reduit}) -> - {struct, [{root, Racine}, {minimized, Reduit}]} - end, - User#user.conversations - )}}, {ek_master, User#user.ek_master}, - {ostentatious_master, atom_to_list(User#user.ostentatious_master)} + {profile, {struct, + [ + {nick, Profile#profile.pseudo}, + {email, Profile#profile.email}, + {css, Profile#profile.css}, + {chat_order, atom_to_list(Profile#profile.chat_order)}, + {nick_format, atom_to_list(Profile#profile.nick_format)}, + {view_times, Profile#profile.view_times}, + {view_tooltips, Profile#profile.view_tooltips}, + {conversations, {array, lists:map( + fun({Racine, Reduit}) -> + {struct, [{root, Racine}, {minimized, Reduit}]} + end, + Profile#profile.conversations + )}}, + {ostentatious_master, atom_to_list(Profile#profile.ostentatious_master)} + ] + }} ] }. @@ -734,7 +734,7 @@ json_message(Mess, Repond_a, User) -> Est_proprietaire = User =/= inconnu andalso User#user.id =:= Mess#minichat.auteur_id, A_repondu_a_message = User =/= inconnu andalso euphorik_bd:a_repondu_a_message(User#user.id, Mess#minichat.id), Est_une_reponse_a_user = User =/= inconnu andalso euphorik_bd:est_une_reponse_a_user(User#user.id, Mess#minichat.id), - {ok, User_mess } = euphorik_bd:user_by_id(Mess#minichat.auteur_id), + {ok, #user{profile = Profile_mess} = User_mess } = euphorik_bd:user_by_id(Mess#minichat.auteur_id), {struct, [ {id, Mess#minichat.id}, {user_id, User_mess#user.id}, @@ -756,5 +756,5 @@ json_message(Mess, Repond_a, User) -> Repond_a )}}, {ek_master, User_mess#user.ek_master}, - {ostentatious_master, atom_to_list(User_mess#user.ostentatious_master)} + {ostentatious_master, atom_to_list(Profile_mess#profile.ostentatious_master)} ]}.