These are chat archives for synrc/n2o

23rd
Feb 2017
Sébastien Saint-Sevin
@seb3s
Feb 23 2017 17:37
Hi
I need to ask the user for his confirmation on a postback event before really doing a suppression
I'm using bootbox to ask for confirm, and its requires a javascript postback to trigger the user action
right now I'm handling it this way
event(Event = {ask_delete_contact, Id_contact}) -> 
    ?wire_io(["bootbox.confirm('", ?TXT("Are you sure ?") ,"', function(result) 
        {if (result) { api_confirm_dialog({action: 'delete_contact', id:'", Id_contact, "'}); }});"]);
I'm using an api_event for javascript to call back erlang server when user confirms
my question : right now, the id is sent in clear to the client side, how can I use some pickle functions to encrypt it so it can not be abused ?
Sébastien Saint-Sevin
@seb3s
Feb 23 2017 17:42
Note: wire_io is just
-define(wire_io(Term), wf:wire(iolist_to_binary(Term))).
Subsidiary question : is there a better way for doing this ?
Sébastien Saint-Sevin
@seb3s
Feb 23 2017 19:57
OK, here is what I'm ending with
event(Event = {ask_delete_contact, Id_contact}) -> 
    wf:info(?MODULE, "Event: ~p~n", [Event]),
    Element = <<"bootbox">>,
    Postback = {delete_contact, Id_contact},
    Source = [],
    Data = action_event:data(Element, Source),
    %% wf_event:new(Postback, Element, Delegate, Name, Data, Source, Validation)
    Postback_bin = wf_event:new(Postback, Element, ?MODULE, event, Data, Source, []),
    ?wire_io(["bootbox.confirm('", ?js_esc(?TXT("Are you sure ?")) ,"', function(result) 
        {if (result) {", Postback_bin, "}});"]);
no more need for api_event, the bootbox callback directly calls the erlang side as a normal postback, plus the data is pickled.