Rather than redirect, replay?

25 views
Skip to first unread message

Bryan Hunt

unread,
Jun 8, 2015, 3:38:29 PM6/8/15
to chica...@googlegroups.com


Hi,


I'm working away on my first Chicagoboss demo application, and I'm trying to implement an identification, authorization, access workflow.


I started by implementing a controller_filter:


-module(training_filter). -export([before_filter/2]). before_filter(_FilterConfig, RequestContext) -> SessionId = proplists:get_value(session_id, RequestContext), %% Request = proplists:get_value(request, RequestContext), lager:log(info, self(), " before filter invoked", []), Action = proplists:get_value(action, RequestContext), case boss_session:get_session_data(SessionId, username) of undefined when Action == "login" -> {ok, RequestContext}; undefined -> lager:log(error, self(), " failed to grab user from session/RequestContext ~p", [RequestContext]), boss_session:set_session_data(SessionId, original_request_context, RequestContext), {redirect, "/login"} end.

I then implemented a (laughably) trivial login module:


-module(training_security_controller, [Req, SessionID]). -compile(export_all). login('POST', []) -> User = Req:post_param("username"), Password = Req:post_param("password"), lager:log(info, self(), "~p ~p", [User, Password]), case Password of "foo" -> boss_session:set_session_data(SessionID, username, User), OriginalRequestContext = boss_session:get_session_data(SessionID, original_request_context), %but I really want to replay the original request {redirect, "/"} ; _ -> boss_flash:add(SessionID, notice, "Login", "Bad credentials, try again!"), {ok, login} end ; login('GET', []) -> boss_flash:add(SessionID, notice, "Login", "Enter your password!"), {ok, login}.

What I would like to do is call the originally requested controller, with the OriginalRequestContext taken from the session, and let it handle the return/output.

Is such a thing possible ? I've done some digging but can't find any relevant examples.


Thanks,


Bryan

can2nac

unread,
Jun 9, 2015, 2:27:11 PM6/9/15
to chica...@googlegroups.com

Bryan Hunt

unread,
Jun 10, 2015, 8:11:48 AM6/10/15
to chica...@googlegroups.com
Thanks can2nac.

I also found out about the (very useful) 'action_other' response from the docs page.

In my simple case I used it like so:

{action_other, [{controller, "base"}, {action, "index"}]} ;

I will read over the like you provided.

B



Reply all
Reply to author
Forward
0 new messages