Bill,

I think that tutorial is a bit outdated. This one is more current:

http://chicagoboss.org/tutorial.pdf

Why not use a binary instead of a string?
proplists:get_value(<<"redirect">>, Req:post_params())



On Friday, February 19, 2016 at 9:41:46 PM UTC-2, Bill Norman wrote:
>
> BTW, I am using the current CB master for OTP 18, and running erlang 18.1.
>
>
> On Friday, February 19, 2016 at 6:35:41 PM UTC-5, Bill Norman 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:
>>
>>
>>    1. login('POST', []) ->
>>    2.     Name = Req:post_param("name"),
>>    3.     case boss_db:find(ward_boss, [{name, Name}], [{limit,1}]) of
>>    4.         [WardBoss] ->
>>    5.             case WardBoss:check_password(Req:post_param("password")) of
>>    6.                 true ->
>>    7.                     {redirect, proplists:get_value("redirect",
>>    8.                         Req:post_params(), "/"), 
>> WardBoss:login_cookies()};
>>    9.                 false ->
>>    10.                     {ok, [{error, "Bad name/password combination"}]}
>>    11.             end;
>>    12.         [] ->
>>    13.             {ok, [{error, "No Ward Boss named " ++ Name}]}
>>    14.     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/99230b74-af84-4a79-b109-f4caf1fd0906%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to