Or this. Pattern matching is way faster than propiststs:get_value/2 AFAIK.
On Friday, February 19, 2016 at 9:50:12 PM UTC-2, Kai Janson wrote:
>
> Hi Bill,
>
> First off, yes the code is butt-ugly.
>
> On that note; you can make it nicer:
>
> [_, _, {<<"redirect">>,Location}] = Req:post_params()
>>
>> {redirect, Location, WardBoss:login_cookies()}
>>
>>
> Pardon my horrible copy/paste
>
> —Kai
>
>
>
>
> On Feb 19, 2016, at 18:41, Bill Norman <[email protected] <javascript:>>
> 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] <javascript:>.
> 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/02f68890-e21f-4ac5-8def-c71af84a81cd%40googlegroups.com
>
> <https://groups.google.com/d/msgid/chicagoboss/02f68890-e21f-4ac5-8def-c71af84a81cd%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> 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/35cbeeaf-d6d8-482c-ad54-4738ad54fcc8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.