diff --git a/dudeswave/src/dudeswave_auth.erl b/dudeswave/src/dudeswave_auth.erl index 7e98142..4333fae 100644 --- a/dudeswave/src/dudeswave_auth.erl +++ b/dudeswave/src/dudeswave_auth.erl @@ -59,7 +59,7 @@ authenticate(User, {cookie, Cookie}) -> {ok, [R]} -> CurTime = calendar:now_to_universal_time(erlang:timestamp()), CookieTime = R#object.value, - CookieUser = lists:keyfind(user, 1, R#object.metadata), + {user, CookieUser} = proplists:lookup(user, R#object.metadata), if CookieTime >= CurTime -> @@ -83,11 +83,14 @@ authenticate(User, {password, Password}) -> erlang:system_time(seconds) + ?DEFVALIDITY * 86400 end, - {ok, Hash} = lists:keyfind(hash, 1, R#object.metadata), - {ok, Salt} = lists:keyfind(salt, 1, R#object.metadata), + {hash, Hash} = proplists:lookup(hash, R#object.metadata), + {salt, Salt} = proplists:lookup(salt, R#object.metadata), + {approved, Appr} = proplists:lookup(approved, R#object.metadata), + Auth = crypto:hash(sha256, <>), if + Appr =/= true -> false; Auth =:= Hash -> Cookie = base64:encode(rand:bytes(64)), case storage:write(?COOKIESBUCK, <>, @@ -123,7 +126,7 @@ Invalidate and delete `Cookie` associated with `User` from the system. logout(User, Cookie) -> case storage:read(?COOKIESBUCK, Cookie) of {ok, [R]} -> - {user, User} = lists:keyfind(user, 1, R#object.metadata), + {user, User} = proplists:lookup(user, R#object.metadata), storage:delete(?COOKIESBUCK, Cookie); {ok, []} -> {error, not_found}; @@ -171,8 +174,7 @@ Spec: The `User` is created, and stored in the application's users bucket `Password` is salted and hashed with SHA256 before being stored. -The new user is saved with a metadata `status` of `waiting_confirmation`, -based on the application settings, the confirmation method may vary. +The new user is saved with a metadata `approved` of `false`, """. -spec new(User, Password, Email) -> ok | {error, Reason} when User :: binary(), @@ -185,7 +187,7 @@ new(User, Password, Email) -> Hash = crypto:hash(sha256, <>), Data = #{<<"email">> => Email}, - Metadata = [{salt, Salt}, {hash, Hash}, {status, waiting_confirmation}], + Metadata = [{salt, Salt}, {hash, Hash}, {approved, false}], storage:write(?USERSBUCK, User, Data, Metadata).