Skip to content

Commit

Permalink
Allow to restart a session by supplying a z_sid in the query args. Th…
Browse files Browse the repository at this point in the history
…is is needed for callbacks from flash.
  • Loading branch information
mworrell committed Jun 26, 2011
1 parent 08c0e75 commit 671882b
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
2 changes: 2 additions & 0 deletions src/models/m_session.erl
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@

%% @doc Fetch the value for the key from a model source
%% @spec m_find_value(Key, Source, Context) -> term()
m_find_value(session_id, #m{value=undefined}, Context) ->
z_context:get(session_id, Context);
m_find_value(Key, #m{value=undefined}, Context) ->
z_context:get_session(Key, Context).

Expand Down
1 change: 1 addition & 0 deletions src/support/z_context.erl
Original file line number Diff line number Diff line change
Expand Up @@ -582,6 +582,7 @@ get_q_all_noz(Context) ->
is_zotonic_arg("postback") -> true;
is_zotonic_arg("triggervalue") -> true;
is_zotonic_arg("z_trigger_id") -> true;
is_zotonic_arg("z_sid") -> true;
is_zotonic_arg("z_pageid") -> true;
is_zotonic_arg("z_v") -> true;
is_zotonic_arg("z_msg") -> true;
Expand Down
22 changes: 18 additions & 4 deletions src/support/z_session_manager.erl
Original file line number Diff line number Diff line change
Expand Up @@ -253,9 +253,9 @@ ensure_session1(S, P, Context, State) when S == undefined orelse P == error ->
Context4 = z_notifier:foldl(session_init_fold, Context3, Context3),
{Pid, Context4, State1}
end;
ensure_session1(_SessionId, Pid, Context, State) ->
ensure_session1(SessionId, Pid, Context, State) ->
z_session:keepalive(Context#context.page_pid, Pid),
Context1 = Context#context{session_pid = Pid},
Context1 = Context#context{session_pid = Pid, props=[{session_id, SessionId}|Context#context.props]},
{Pid, Context1, State}.


Expand Down Expand Up @@ -351,7 +351,21 @@ spawn_session(PersistId, Context) ->
%% @doc fetch the session id from the request, return 'undefined' when not found
get_session_id(Context) ->
ReqData = z_context:get_reqdata(Context),
wrq:get_cookie_value(?SESSION_COOKIE, ReqData).
case wrq:get_cookie_value(?SESSION_COOKIE, ReqData) of
undefined ->
% Check the z_sid query args
case wrq:get_qs_value("z_sid", ReqData) of
undefined ->
case dict:find(z_sid, wrq:path_info(ReqData)) of
{ok, SessionId} -> SessionId;
error -> undefined
end;
SessionId ->
SessionId
end;
SessionId ->
SessionId
end.

%% @spec set_session_id(SessionId::string(), Context::#context{}) -> #context{}
%% @doc Save the session id in a cookie on the user agent
Expand All @@ -364,7 +378,7 @@ set_session_id(SessionId, Context) ->
{domain, z_context:cookie_domain(Context)}
]),
RD1 = wrq:merge_resp_headers([Hdr], RD),
z_context:set(set_session_id, true, z_context:set_reqdata(RD1, Context)).
z_context:set([{set_session_id, true}, {session_id, SessionId}], z_context:set_reqdata(RD1, Context)).


%% @spec clear_session_id(Context::#context{}) -> #context{}
Expand Down

0 comments on commit 671882b

Please sign in to comment.