Move the cookie parameter as value.
parent
318ab0d301
commit
6acd5e3a5a
|
@ -55,11 +55,13 @@ authenticate(User, Cookie, Bucket) ->
|
|||
case storage:read(Bucket, Cookie) of
|
||||
{ok, [R]} ->
|
||||
CurTime = calendar:now_to_universal_time(erlang:timestamp()),
|
||||
CookieTime = lists:keyfind(until, 1, R#object.metadata),
|
||||
CookieTime = R#object.value,
|
||||
CookieUser = lists:keyfind(user, 1, R#object.metadata),
|
||||
|
||||
if
|
||||
CookieTime >= CurTime ->
|
||||
if
|
||||
User =:= R#object.value -> true;
|
||||
User =:= CookieUser -> true;
|
||||
true -> false
|
||||
end;
|
||||
true -> false
|
||||
|
@ -118,7 +120,7 @@ authenticate(User, Password, Cookies, Bucket) ->
|
|||
if
|
||||
Auth =:= Hash ->
|
||||
Cookie = base64:encode(rand:bytes(64)),
|
||||
case storage:write(Cookies, <<Cookie/binary>>, User, [{until, Validity}]) of
|
||||
case storage:write(Cookies, <<Cookie/binary>>, Validity, [{user, User}]) of
|
||||
ok -> {true, Cookie, Validity};
|
||||
{error, Reason} -> {error, Reason}
|
||||
end;
|
||||
|
|
Loading…
Reference in New Issue