So I've worked my way through an evening with ChicagoBoss. I am now currently trying to wire up ChicagoBoss with MongoDB to build an app with it (and learn two new technologies I've been eyeing in the process). Unfortunately I seem to have hit a snag. Specifically, after a user is created, the password does not appear to be what it was set to. Please note that with the exception of configuration code, all code comes directly from the Chicago Boss tutorials.
boss.config - re Databases:
{db_host, "localhost"},
{db_port, 27017},
{db_adapter, mongodb},
login function
login('POST', []) ->
Name = Req:post_param("name"),
case boss_db:find(user, [{name, Name}]) of
[User] ->
case User:check_password(Req:post_param("password")) of
true ->
{redirect, proplists:get_value("redirect",
Req:post_params(), "/"), User:login_cookies()};
false ->
{ok, [{error, "Bad name/password combination"}]}
end;
[] ->
{ok, [{error, "No User named " ++ Name}]}
end.
Then - after creating a user from the admin interface and using
hash_for(Name, Password) ->
Salt = mochihex:to_hex(erlang:md5(Name)),
hash_password(Password, Salt).
to generate a hash, the following two things happen:
1) The user is created but not id-ed as user-1, but rather as usr-51970a2a3e01c027d4000001.
Why is that? I thought ChicagoBoss followed the rails convention of autoincrementing numeric indices?
2) Even though the password that was passed into hash_for is used, the user can never login.
3) After the Chicago Boss server is restarted the newly created database objects are retained - so mongo is at least saving something correctly.
Can anyone shed any light on whats going on here? How is MongoDB trying to save the user? What is the correct method for wiring up Chicago Boss with MongoDB, does boss_db not handle MongoDB natively?
The tutorial all of this is trying to use as a jump off point is:
https://github.com/evanmiller/ChicagoBoss/wiki/An-Evening-With-Chicago-Boss