sample_auth.erl 960 B

12345678910111213141516171819202122232425
  1. -module(sample_auth).
  2. -include_lib("n2o/include/n2o.hrl").
  3. -compile(export_all).
  4. info({init, <<>>}, Req, State = #cx{session = Session}) ->
  5. {'Token', Token} = n2o_session:authenticate([], Session),
  6. #cx{params = _ClientId} = get(context),
  7. kvs:put({config, Token, State}),
  8. io:format("Token Saved: ~p~n",[Token]),
  9. n2o_nitro:info({init, Token}, Req, State);
  10. % test protocol
  11. info({load, <<>>}, Req, State = #cx{session = _Session}) ->
  12. #cx{params = ClientId} = get(context),
  13. M = "list of previous messages",
  14. n2o:send_reply(ClientId, 2, iolist_to_binary([<<"actions/1/index/">>,ClientId]), M),
  15. {reply, {binary, term_to_binary(<<>>)}, Req, State};
  16. info({message, _Text} = M, Req, State = #cx{session = _Session}) ->
  17. #cx{params = ClientId} = get(context),
  18. n2o:send_reply(ClientId, 2, <<"room/global">>, M),
  19. {reply, {binary, term_to_binary(<<>>)}, Req, State};
  20. info(Message,Req,State) -> {unknown,Message,Req,State}.