nouveau_user(Cookie, Profile) ->\r
F = fun() ->\r
Id = nouvel_id(user),\r
- User = #user{id = Id, cookie = Cookie, date_creation = now(), date_derniere_connexion = now(), profile = Profile},\r
+ User = #user{id = Id, cookie = Cookie, date_creation = erlang:timestamp(), date_derniere_connexion = erlang:timestamp(), profile = Profile},\r
mnesia:write(User),\r
User\r
end,\r
nouveau_user(Login, Password, Cookie, Profile) ->\r
F = fun() ->\r
Id = nouvel_id(user),\r
- User = #user{id = Id, cookie = Cookie, login = Login, password = Password, date_creation = now(), date_derniere_connexion = now(), profile = Profile#profile{pseudo = Login}},\r
+ User = #user{id = Id, cookie = Cookie, login = Login, password = Password, date_creation = erlang:timestamp(), date_derniere_connexion = erlang:timestamp(), profile = Profile#profile{pseudo = Login}},\r
mnesia:write(User),\r
User\r
end,\r
fun() ->\r
case mnesia:wread({user, User_id}) of\r
[User] ->\r
- mnesia:write(User#user{date_derniere_connexion = now()});\r
+ mnesia:write(User#user{date_derniere_connexion = erlang:timestamp()});\r
_ ->\r
mnesia:abort("update_date_derniere_connexion: User inconnu")\r
end\r
case mnesia:wread({user, Auteur_id}) of\r
[#user{profile = Profile} = Auteur] ->\r
% comparaison entre la date du dernier poste et maintenant (gestion du flood)\r
- Now = now(),\r
+ Now = erlang:timestamp(),\r
Delta = euphorik_common:delta_date_ms(Auteur#user.date_derniere_connexion, Now),\r
Nouvel_indice_flood = Auteur#user.indice_flood + if Delta =< ?DUREE_SPAM -> 2; true -> -1 end,\r
Auteur_maj = Auteur#user{\r
resultat_transaction(mnesia:transaction(\r
fun() ->\r
Id = nouvel_id(minichat),\r
- mnesia:write(#minichat{id = Id, auteur_id = 0, date = now(), pseudo = Profile#profile.pseudo, contenu = Mess, racine_id = Id}),\r
+ mnesia:write(#minichat{id = Id, auteur_id = 0, date = erlang:timestamp(), pseudo = Profile#profile.pseudo, contenu = Mess, racine_id = Id}),\r
Id\r
end\r
)).\r
list_ban() ->\r
resultat_transaction(mnesia:transaction(\r
fun() ->\r
- Now = now(),\r
+ Now = erlang:timestamp(),\r
e(qlc:keysort(1, q([\r
{\r
IP#ip_table.ip,\r
fun() ->\r
case mnesia:wread({ip_table, IP}) of\r
[IP_tuple] ->\r
- mnesia:write(IP_tuple#ip_table{ban = now(), ban_duration = Duration});\r
+ mnesia:write(IP_tuple#ip_table{ban = erlang:timestamp(), ban_duration = Duration});\r
_ ->\r
- mnesia:write(#ip_table{ip = IP, ban = now(), ban_duration = Duration})\r
+ mnesia:write(#ip_table{ip = IP, ban = erlang:timestamp(), ban_duration = Duration})\r
end\r
end\r
).\r
]), [{tmpdir, ?KEY_SORT_TEMP_DIR}]) of\r
[{Ban, Ban_duration}] ->\r
Echeance = date_plus_minutes(Ban, Ban_duration),\r
- Now = now(),\r
+ Now = erlang:timestamp(),\r
if Echeance < Now -> % l'échéance est passée\r
false;\r
true ->\r
)).\r
\r
\r
-% Ban est une date tel que retourner par now().\r
+% Ban est une date tel que retourner par erlang:timestamp().\r
% Ban_duration est un temps en minutes.\r
% retourne une date.\r
date_plus_minutes(Ban, Ban_duration) ->\r
fun() ->\r
case e(q([I || I <- mnesia:table(ip_table), I#ip_table.ip =:= IP]), [{tmpdir, ?KEY_SORT_TEMP_DIR}]) of\r
[] ->\r
- mnesia:write(#ip_table{ip = IP, date_last_try_register = now()}),\r
+ mnesia:write(#ip_table{ip = IP, date_last_try_register = erlang:timestamp()}),\r
true;\r
[T] ->\r
- Delta = euphorik_common:delta_date_ms(T#ip_table.date_last_try_register, now()),\r
+ Delta = euphorik_common:delta_date_ms(T#ip_table.date_last_try_register, erlang:timestamp()),\r
if T#ip_table.nb_try_register =:= ?NB_MAX_FLOOD_REGISTER, Delta < ?TEMPS_BAN_FLOOD_REGISTER ->\r
false;\r
true ->\r
mnesia:write(T#ip_table{\r
ip = IP,\r
- date_last_try_register = now(),\r
+ date_last_try_register = erlang:timestamp(),\r
nb_try_register = T#ip_table.nb_try_register + if Delta < ?TEMPS_FLOOD_REGISTER -> 1; T#ip_table.nb_try_register > 0 -> -1; true -> 0 end\r
}),\r
true\r
\r
\r
% Une utilisateur s'enregistre avec un tuple {Login, Password}.\r
-register([{login, Login}, {password, Password}, {profile, Profile_json}], IP) ->\r
+register([{"login", Login}, {"password", Password}, {"profile", Profile_json}], IP) ->\r
Can_register = euphorik_bd:can_register(IP),\r
if Can_register ->\r
case euphorik_bd:user_by_login(Login) of\r
erreur_register_flood()\r
end;\r
% Enregistrement sans {Login, Password}\r
-register([{profile, Profile_json}], IP) ->\r
+register([{"profile", Profile_json}], IP) ->\r
Can_register = euphorik_bd:can_register(IP),\r
if Can_register ->\r
Profile = profile_from_json(Profile_json),\r
\r
\r
% Un utilisateur se logge (avec un couple {login, mot de passe})\r
-login([{login, Login}, {password, Password}], IP) ->\r
+login([{"login", Login}, {"password", Password}], IP) ->\r
case euphorik_bd:user_by_login_password(Login, Password) of\r
{ok, User} ->\r
loginUser(User, IP);\r
erreur(30)\r
end;\r
% Un utilisateur se logge (avec un cookie)\r
-login([{cookie, Cookie}], IP) ->\r
+login([{"cookie", Cookie}], IP) ->\r
case euphorik_bd:user_by_cookie(Cookie) of\r
{ok, User} ->\r
loginUser(User, IP);\r
\r
% Renvoie un string() représentant un cookie en base 36. Il y a 10^32 possibillités.\r
generer_cookie() ->\r
- {A1, A2, A3} = now(),\r
+ {A1, A2, A3} = erlang:timestamp(),\r
random:seed(A1, A2, A3),\r
erlang:integer_to_list(random:uniform(trunc(math:pow(10, 32))), 36).\r
\r
% Modification du profile.\r
profile(\r
[\r
- {cookie, Cookie},\r
- {login, Login},\r
- {password, Password},\r
- {profile, Profile_json}\r
+ {"cookie", Cookie},\r
+ {"login", Login},\r
+ {"password", Password},\r
+ {"profile", Profile_json}\r
]\r
) ->\r
case profile_from_json(Profile_json) of\r
profile_from_json(\r
{struct,\r
[\r
- {nick, Pseudo},\r
- {email, Email},\r
- {css, Css},\r
- {chat_order, Chat_order_str},\r
- {nick_format, Nick_format_str},\r
- {view_times, View_times},\r
- {view_tooltips, View_tooltips},\r
- {conversations, {array, Conversations_json}},\r
- {ostentatious_master, Ostentatious_master_str}\r
+ {"nick", Pseudo},\r
+ {"email", Email},\r
+ {"css", Css},\r
+ {"chat_order", Chat_order_str},\r
+ {"nick_format", Nick_format_str},\r
+ {"view_times", View_times},\r
+ {"view_tooltips", View_tooltips},\r
+ {"conversations", {array, Conversations_json}},\r
+ {"ostentatious_master", Ostentatious_master_str}\r
]\r
}\r
) ->\r
% décomposition de la strucure JSON\r
Conversations = lists:foldr(\r
- fun({struct, [{root, Racine}, {minimized, Reduit}]}, A) ->\r
+ fun({struct, [{"root", Racine}, {"minimized", Reduit}]}, A) ->\r
% virage des messages qui n'existent pas\r
Message_exite = euphorik_bd:message_existe(Racine),\r
if Message_exite ->\r
\r
% Attend un événement pour la page "Chat"\r
% last_message id et cookie sont facultatifs\r
-wait_event([{page, "chat"} | Data]) ->\r
+wait_event([{"page", "chat"} | Data]) ->\r
% traitement des inputs\r
- Cookie = case lists:keysearch(cookie, 1, Data) of {value, {_, C}} -> C; _ -> inconnu end,\r
- Last_message_id = case lists:keysearch(last_message_id, 1, Data) of {value, {_, Id}} -> Id; _ -> 0 end,\r
- {value, {_, Message_count}} = lists:keysearch(message_count, 1, Data),\r
- Main_page = case lists:keysearch(main_page, 1, Data) of {value, {_, P}} -> P; _ -> 1 end,\r
- {value, {_, {array, Conversations_json}}} = lists:keysearch(conversations, 1, Data),\r
+ Cookie = case lists:keysearch("cookie", 1, Data) of {value, {_, C}} -> C; _ -> inconnu end,\r
+ Last_message_id = case lists:keysearch("last_message_id", 1, Data) of {value, {_, Id}} -> Id; _ -> 0 end,\r
+ {value, {_, Message_count}} = lists:keysearch("message_count", 1, Data),\r
+ Main_page = case lists:keysearch("main_page", 1, Data) of {value, {_, P}} -> P; _ -> 1 end,\r
+ {value, {_, {array, Conversations_json}}} = lists:keysearch("conversations", 1, Data),\r
Racines_conversations = lists:map(\r
- fun({struct, [{root, Racine}, {page, Page} | Reste]}) ->\r
- Last_mess_conv = case Reste of [{last_message_id, L}] -> L; _ -> 0 end,\r
+ fun({struct, [{"root", Racine}, {"page", Page} | Reste]}) ->\r
+ Last_mess_conv = case Reste of [{"last_message_id", L}] -> L; _ -> 0 end,\r
{Racine, Page, Last_mess_conv}\r
end,\r
Conversations_json\r
R\r
end;\r
% Attend un événement pour la page "Admin"\r
-wait_event([{page, "admin"}]) ->\r
+wait_event([{"page", "admin"}]) ->\r
case wait_event_page_admin() of\r
banned_ips_refresh ->\r
{struct,\r
[\r
- {reply, "banned_ips_refresh"}\r
+ {"reply", "banned_ips_refresh"}\r
]\r
};\r
_ ->\r
Conversations ->\r
% Accrochez-vous ca va siouxer ;).\r
{struct, [\r
- {reply, "new_messages"},\r
- {conversations, {array,\r
+ {"reply", "new_messages"},\r
+ {"conversations", {array,\r
lists:map(\r
fun({Racine, {Conv, Plus}}) ->\r
{struct, [\r
- {last_page, not Plus},\r
- {first, % le premier message de la conversation\r
+ {"last_page", not Plus},\r
+ {"first", % le premier message de la conversation\r
if Racine =:= undefined orelse Conv =:= [] ->\r
null;\r
true ->\r
% Answer_to est une liste d'id (int)\r
put_message(\r
[\r
- {cookie, Cookie},\r
- {nick, Nick},\r
- {content, Content},\r
- {answer_to, {array, Answer_to}}\r
+ {"cookie", Cookie},\r
+ {"nick", Nick},\r
+ {"content", Content},\r
+ {"answer_to", {array, Answer_to}}\r
]\r
) ->\r
case euphorik_bd:user_by_cookie(Cookie) of\r
% bannissement d'un utilisateur (son ip est bannie)\r
ban(\r
[\r
- {cookie, Cookie},\r
- {duration, Duration},\r
- {user_id, User_id},\r
- {reason, Reason}\r
+ {"cookie", Cookie},\r
+ {"duration", Duration},\r
+ {"user_id", User_id},\r
+ {"reason", Reason}\r
]) ->\r
% controle que l'utilisateur est un admin\r
case euphorik_bd:user_by_cookie(Cookie) of\r
% slapage d'un user (avertissement)\r
slap(\r
[\r
- {cookie, Cookie},\r
- {user_id, User_id},\r
- {reason, Reason}\r
+ {"cookie", Cookie},\r
+ {"user_id", User_id},\r
+ {"reason", Reason}\r
]) ->\r
% controle que l'utilisateur est un admin\r
case euphorik_bd:user_by_cookie(Cookie) of\r
\r
unban_ip(\r
[\r
- {cookie, Cookie},\r
- {ip, IP}\r
+ {"cookie", Cookie},\r
+ {"ip", IP}\r
]\r
) ->\r
case euphorik_bd:user_by_cookie(Cookie) of\r
\r
list_banned_ips(\r
[\r
- {cookie, Cookie}\r
+ {"cookie", Cookie}\r
]\r
) ->\r
case euphorik_bd:user_by_cookie(Cookie) of\r
{\r
struct,\r
[\r
- {reply, "list_banned_ips"},\r
- {list, {array, lists:map(\r
+ {"reply", "list_banned_ips"},\r
+ {"list", {array, lists:map(\r
fun({IP, T, Users}) ->\r
{struct,\r
[\r
- {ip, euphorik_common:serialize_ip(IP)},\r
- {remaining_time, format_minutes(T)},\r
- {users, {array, lists:map(\r
+ {"ip", euphorik_common:serialize_ip(IP)},\r
+ {"remaining_time", format_minutes(T)},\r
+ {"users", {array, lists:map(\r
fun({Pseudo, Login}) ->\r
{struct,\r
[\r
- {nick, Pseudo},\r
- {login, Login}\r
+ {"nick", Pseudo},\r
+ {"login", Login}\r
]\r
}\r
end,\r
erreur_json(Num, Mess) ->\r
{\r
struct, [\r
- {reply, "error"},\r
- {no, Num},\r
- {error_message, Mess}\r
+ {"reply", "error"},\r
+ {"no", Num},\r
+ {"error_message", Mess}\r
]\r
}.\r
\r
\r
\r
json_reponse_ok() ->\r
- {struct, [{reply, "ok"}]}.\r
+ {struct, [{"reply", "ok"}]}.\r
\r
\r
json_reponse_login_ok(#user{profile = Profile} = User) ->\r
{\r
struct, [\r
- {reply, "login"},\r
- {status, if (User#user.password =/= []) and (User#user.login =/= []) -> "auth_registered"; true -> "auth_not_registered" end},\r
- {cookie, User#user.cookie},\r
- {id, User#user.id},\r
- {login, User#user.login},\r
- {ek_master, User#user.ek_master},\r
- {profile, {struct,\r
+ {"reply", "login"},\r
+ {"status", if (User#user.password =/= []) and (User#user.login =/= []) -> "auth_registered"; true -> "auth_not_registered" end},\r
+ {"cookie", User#user.cookie},\r
+ {"id", User#user.id},\r
+ {"login", User#user.login},\r
+ {"ek_master", User#user.ek_master},\r
+ {"profile", {struct,\r
[\r
- {nick, Profile#profile.pseudo},\r
- {email, Profile#profile.email},\r
- {css, Profile#profile.css},\r
- {chat_order, atom_to_list(Profile#profile.chat_order)},\r
- {nick_format, atom_to_list(Profile#profile.nick_format)},\r
- {view_times, Profile#profile.view_times},\r
- {view_tooltips, Profile#profile.view_tooltips},\r
- {conversations, {array, lists:map(\r
+ {"nick", Profile#profile.pseudo},\r
+ {"email", Profile#profile.email},\r
+ {"css", Profile#profile.css},\r
+ {"chat_order", atom_to_list(Profile#profile.chat_order)},\r
+ {"nick_format", atom_to_list(Profile#profile.nick_format)},\r
+ {"view_times", Profile#profile.view_times},\r
+ {"view_tooltips", Profile#profile.view_tooltips},\r
+ {"conversations", {array, lists:map(\r
fun({Racine, Reduit}) ->\r
- {struct, [{root, Racine}, {minimized, Reduit}]}\r
+ {struct, [{"root", Racine}, {"minimized", Reduit}]}\r
end,\r
Profile#profile.conversations\r
)}},\r
- {ostentatious_master, atom_to_list(Profile#profile.ostentatious_master)}\r
+ {"ostentatious_master", atom_to_list(Profile#profile.ostentatious_master)}\r
]\r
}}\r
]\r
Est_une_reponse_a_user = User =/= inconnu andalso euphorik_bd:est_une_reponse_a_user(User#user.id, Mess#minichat.id),\r
{ok, #user{profile = Profile_mess} = User_mess } = euphorik_bd:user_by_id(Mess#minichat.auteur_id),\r
{struct, [\r
- {id, Mess#minichat.id},\r
- {user_id, User_mess#user.id},\r
- {date, case Mess#minichat.date of undefined -> "?"; _ -> format_date(Mess#minichat.date) end},\r
- {system, Mess#minichat.auteur_id =:= 0},\r
- {owner, Est_proprietaire},\r
- {answered, A_repondu_a_message},\r
- {is_a_reply, Est_une_reponse_a_user},\r
- {nick, Mess#minichat.pseudo},\r
- {login, User_mess#user.login},\r
- {content, Mess#minichat.contenu},\r
- {root, Mess#minichat.racine_id},\r
- {answer_to, {array, lists:map(\r
+ {"id", Mess#minichat.id},\r
+ {"user_id", User_mess#user.id},\r
+ {"date", case Mess#minichat.date of undefined -> "?"; _ -> format_date(Mess#minichat.date) end},\r
+ {"system", Mess#minichat.auteur_id =:= 0},\r
+ {"owner", Est_proprietaire},\r
+ {"answered", A_repondu_a_message},\r
+ {"is_a_reply", Est_une_reponse_a_user},\r
+ {"nick", Mess#minichat.pseudo},\r
+ {"login", User_mess#user.login},\r
+ {"content", Mess#minichat.contenu},\r
+ {"root", Mess#minichat.racine_id},\r
+ {"answer_to", {array, lists:map(\r
fun(Id_mess) ->\r
{ok, M} = euphorik_bd:message_by_id(Id_mess),\r
{ok, User_reponse} = euphorik_bd:user_by_mess(M#minichat.id),\r
- {struct, [{id, M#minichat.id}, {nick, M#minichat.pseudo}, {login, User_reponse#user.login}]}\r
+ {struct, [{"id", M#minichat.id}, {"nick", M#minichat.pseudo}, {"login", User_reponse#user.login}]}\r
end,\r
Repond_a\r
)}},\r
- {ek_master, User_mess#user.ek_master},\r
- {ostentatious_master, atom_to_list(Profile_mess#profile.ostentatious_master)}\r
+ {"ek_master", User_mess#user.ek_master},\r
+ {"ostentatious_master", atom_to_list(Profile_mess#profile.ostentatious_master)}\r
]}.\r