[api] use sensor id to determine the corresponding hash key

This commit is contained in:
Bart Van Der Meerssche 2011-03-27 11:19:58 +00:00
parent bd6762399b
commit b157a5dc72
2 changed files with 3 additions and 3 deletions

View File

@ -31,7 +31,7 @@ ensure_started(App) ->
mysql_prepare() ->
mysql:prepare(permissions, <<"SELECT permissions FROM logger_tokens WHERE meter = ? AND token = ?">>),
mysql:prepare(device_key, <<"SELECT sha FROM logger_devices WHERE device = ?">>).
mysql:prepare(device_key, <<"SELECT sha FROM (logger_devices ld INNER JOIN logger_meters lm ON ld.device = lm.device) WHERE lm.meter = ?">>).
%% @spec start_link() -> {ok,Pid::pid()}
%% @doc Starts the app for inclusion in a supervisor tree

View File

@ -90,8 +90,8 @@ is_authorized(ReqData, State) ->
'GET' -> is_auth_GET(ReqData, State)
end.
is_auth_POST(ReqData, #state{device = Device, digest = ClientDigest} = State) ->
{data, Result} = mysql:execute(pool, device_key, [Device]),
is_auth_POST(ReqData, #state{rrdSensor = Sensor, digest = ClientDigest} = State) ->
{data, Result} = mysql:execute(pool, device_key, [Sensor]),
[[Key]] = mysql:get_result_rows(Result),
Data = wrq:req_body(ReqData),
<<X:160/big-unsigned-integer>> = crypto:sha_mac(Key, Data),