Rather than pulling Req:post_params() then running a
proplist:get_value() against it, you can do:

Req:post_param(redirect) or Req:post_param("redirect") to get the string value.

Or Req:post_param(<<"redirect">>) to get the same value as a binary.

SimpleBridge 2.0 is Type-In-Type-Out in almost all cases, though
Req:params() returns just the full list of internally stored params
(which are stored as binary).

Unless you need the full list of params to work with, It's usually
preferable to just do Req:post_param/1 or Req:query_param/1.

Or alternatively, sbw:post_param(redirect, Req). This method will help
with dialyzer checks.

-Jesse

On Fri, Feb 19, 2016 at 5:52 PM, Graeme Defty <[email protected]> wrote:
> Hi Bill,
>
> Yes, you are quite right. We now have to deal in binaries.
>
> You should just be able to put:
>
>   proplists:get_value(<<"redirect">>, Req:post_params(), "/"),
>
> Regards,
>
> Graeme
>
>
>
> On 20 February 2016 at 06:35, Bill Norman <[email protected]> wrote:
>>
>> Hello,
>>
>> I am currently going through the 'Evening with Chicago Boss tutorial.
>>
>> I am following instructions for handling user authentication and have
>> implemented this code fragment in the
>> controller/evening_user_controller.erl:
>>
>> login('POST', []) ->
>>     Name = Req:post_param("name"),
>>     case boss_db:find(ward_boss, [{name, Name}], [{limit,1}]) of
>>         [WardBoss] ->
>>             case WardBoss:check_password(Req:post_param("password")) of
>>                 true ->
>>                     {redirect, proplists:get_value("redirect",
>>                         Req:post_params(), "/"),
>> WardBoss:login_cookies()};
>>                 false ->
>>                     {ok, [{error, "Bad name/password combination"}]}
>>             end;
>>         [] ->
>>             {ok, [{error, "No Ward Boss named " ++ Name}]}
>>     end.
>>
>> My issue is that the value of the redirect (lines 7 & 8) calculates to the
>> default value "/" in proplists:get_value/3.
>>
>> The return value of Req:post_params() is:
>> [{<<"name">>,<<"Bathhouse John">>},
>>               {<<"password">>,<<"password">>},
>>               {<<"redirect">>,<<"http://localhost:8001/voter/list";>>}]
>>
>> so querying this list with proplists:get_value("redirect",
>> Req:post_params()) returns undefined.
>>
>> I modified the code to:
>> binary_to_list(proplists:get_value(list_to_binary("redirect"),
>> Req:post_params()))
>>
>> This works but it is awfully ugly.
>>
>> Is there a helper method in Chicago Boss or a more elegant erlang
>> conversion term
>> I could use to handle the binary tuples returned by Req:get_params()?
>>
>> What has changed since this tutorial was written? Has the output of
>> Req:get_params()
>> changed?
>>
>> Thanks
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "ChicagoBoss" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to [email protected].
>> Visit this group at https://groups.google.com/group/chicagoboss.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/chicagoboss/83ae8c3e-2668-4745-9d11-4519af0c21ed%40googlegroups.com.
>> For more options, visit https://groups.google.com/d/optout.
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "ChicagoBoss" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> Visit this group at https://groups.google.com/group/chicagoboss.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/chicagoboss/CAKF5fiB4TzJSyqg%3DyL%2BSO9RTg_i8hONJN4QHkSQJeKwH%2Bxu8YA%40mail.gmail.com.
>
> For more options, visit https://groups.google.com/d/optout.



-- 
Jesse Gumm
Owner, Sigma Star Systems
414.940.4866 || sigma-star.com || @jessegumm

-- 
You received this message because you are subscribed to the Google Groups 
"ChicagoBoss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
Visit this group at https://groups.google.com/group/chicagoboss.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/chicagoboss/CAPTXyXe3wMwHq3m8qmr1Vt57TU0%2BgSGb-a5AwjVKiPnvy8jqHg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to