Bugfixes.

* ts_api:list_timelines/2 was looking for keys as atoms instead of lists (strings).
* Exported the ts_json:decode_datetime/1 function (needed by ts_api module).
* Fixed a crash case when trying to check the credentials of a non-existent user.
This commit is contained in:
Jonathan Bernard 2013-09-15 00:33:02 +00:00
parent 38dc560686
commit 1e05258381
3 changed files with 14 additions and 11 deletions

View File

@ -272,14 +272,14 @@ list_timelines(YArg, Username) ->
QueryData = yaws_api:parse_query(YArg),
% read or default the Start
Start = case lists:keyfind(start, 1, QueryData) of
{start, StartVal} -> list_to_integer(StartVal);
Start = case lists:keyfind("start", 1, QueryData) of
{"start", StartVal} -> list_to_integer(StartVal);
false -> 0
end,
% read or default the Length
Length = case lists:keyfind(length, 1, QueryData) of
{length, LengthVal} ->
{"length", LengthVal} ->
erlang:min(list_to_integer(LengthVal), 50);
false -> 50
end,
@ -351,21 +351,21 @@ list_entries(YArg, Username, TimelineId) ->
% look for the start date; default to the beginning of the timeline
StartDate = case lists:keyfind("startDate", 1, QueryData) of
% TODO: error handling if the date is badly formatted
{startDate, StartDateVal} -> ts_json:decode_date(StartDateVal);
{"startDate", StartDateVal} -> ts_json:decode_datetime(StartDateVal);
false -> Timeline#ts_timeline.created
end,
% look for end date; default to right now
EndDate = case lists:keyfind("endDate", 1, QueryData) of
% TODO: error handling if the date is badly formatted
{endDate, EndDateVal} -> ts_json:decode_date(EndDateVal);
{"endDate", EndDateVal} -> ts_json:decode_datetime(EndDateVal);
false -> calendar:now_to_universal_time(erlang:now())
end,
% read sort order and list entries
Entries = case lists:keyfind("order", 1, QueryData) of
% descending sort order
{order, "desc"} -> ts_entry:list_desc(
{"order", "desc"} -> ts_entry:list_desc(
{Username, TimelineId}, StartDate, EndDate);
% ascending order--{other, asc}--and default

View File

@ -1,7 +1,8 @@
-module(ts_json).
-export([encode_record/2, record_to_ejson/2,
ejson_to_record/2, ejson_to_record/3,
ejson_to_record_strict/2, ejson_to_record_strict/3]).
ejson_to_record_strict/2, ejson_to_record_strict/3,
decode_datetime/1]).
-include("ts_db_records.hrl").

View File

@ -74,7 +74,9 @@ generate_salt() -> crypto:rand_bytes(36).
hash_pwd(Password, Salt) -> crypto:sha(Password ++ Salt).
check_credentials(Username, Password) ->
User = lookup(Username),
HashedInput = hash_pwd(Password, User#ts_user.pwd_salt),
HashedInput == User#ts_user.pwd.
case lookup(Username) of
no_record -> false;
User ->
HashedInput = hash_pwd(Password, User#ts_user.pwd_salt),
HashedInput == User#ts_user.pwd
end.