Compare commits

..

No commits in common. "5b73df899939708029d8adc0c90e0f21f79fa00c" and "ea339a10248ca1a72e5f644415cff1a022e95c91" have entirely different histories.

5 changed files with 14 additions and 22 deletions

View File

@ -19,6 +19,8 @@
-export([bootstrap/3, start/2, stop/1]).
start(_Type, StartArgs) ->
crypto:rand_seed(),
dudeswave_backend_supervisor:start_link(StartArgs).
stop(_State) -> ok.

View File

@ -5,6 +5,6 @@
dudeswave_users_supervisor,
dudeswave_users_auth,dudeswave_users_user]},
{registered,[]},
{applications,[kernel,stdlib,erts,storage,crypto]},
{applications,[kernel,stdlib,erts]},
{mod,{dudeswave_users_app,[]}},
{start_phases,[]}]}.

View File

@ -8,7 +8,6 @@ ERLFLAGS= -I ../../
OBJS= dudeswave_web.beam dudeswave_web_app.beam
OBJS+= dudeswave_web_supervisor.beam dudeswave_web_handler.beam
OBJS+= dudeswave_web_user_handler.beam dudeswave_web_common.beam
OBJS+= dudeswave_web_auth_handler.beam
all: ${OBJS}

View File

@ -13,7 +13,7 @@
% ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
% OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
%
-module(dudeswave_web_auth_handler).
-module(dudeswave_auth_handler).
-moduledoc """
JSON API to authenticate users.
@ -94,10 +94,9 @@ forbidden(Req, State) ->
<<"POST">> ->
{false, Req, State};
_ ->
{User, Cookie} = dudeswave_web_common:auth_cookies(Req),
Host = cowboy_req:host(Req),
{User, Auth} = dudeswave_web_common:auth_cookies(Req),
case dudeswave_backend:auth(cookie, User, Host, Cookie) of
case dudeswave_backend:auth(cookie, User, Cookie) of
{error, service_unavailable} -> exit(service_unavailable);
true -> {false, Req, State};
false -> {true, Req, State}
@ -114,9 +113,8 @@ content_types_accepted(Req, State) ->
resource_exists(Req, State) ->
{User, _} = dudeswave_web_common:auth_cookies(Req),
Host = cowboy_req:host(Req),
case dudeswave_backend:user_details(User, Host) of
case dudeswave_backend:user_details(User) of
[] ->
{false, Req, State};
{error, Reason} ->
@ -138,9 +136,8 @@ allow_missing_post(Req, State) -> {false, Req, State}.
delete_resource(Req, State) ->
{User, Auth} = dudeswave_web_common:auth_cookies(Req),
Host = cowboy_req:host(Req),
case dudeswave_backend:logout(User, Host, Auth) of
case dudeswave_backend:logout(User, Auth) of
ok ->
{true, invalidate_cookies(Req), State};
{error, _} ->
@ -155,9 +152,8 @@ delete_completed(Req, State) -> {false, Req, State}.
login(Req, State) ->
{User, Pass, Req0} = read_login_data(Req),
Host = cowboy_req:host(Req),
case dudeswave_backend:auth(password, User, Host, Pass) of
case dudeswave_backend:auth(password, User, Pass) of
{true, Cookie, Validity} ->
{true, set_auth_cookies(Req, User, Cookie, Validity), State};
false ->

View File

@ -139,9 +139,8 @@ forbidden(Req, State) ->
{false, Req, State};
_ ->
{User, Auth} = dudeswave_web_common:auth_cookies(Req),
Host = cowboy_req:host(Req),
case dudeswave_backend:auth(cookie, User, Host, Auth) of
case dudeswave_backend:auth(cookie, User, Auth) of
{error, service_unavailable} -> {true, Req, State};
true -> {false, Req, State};
false -> {true, Req, State}
@ -170,9 +169,8 @@ content_types_accepted(Req, State) ->
resource_exists(Req, State) ->
{User, _} = dudeswave_web_common:auth_cookies(Req),
Host = cowboy_req:host(Req),
case dudeswave_backend:user_details(User, Host) of
case dudeswave_backend:user_details(User) of
[] ->
{false, Req, State};
{error, _} ->
@ -197,9 +195,8 @@ allow_missing_post(Req, State) -> {false, Req, State}.
delete_resource(Req, State) ->
{User, _} = dudeswave_web_common:auth_cookies(Req),
Host = cowboy_req:host(Req),
case dudeswave_backend:delete_user(User, Host) of
case dudeswave_backend:delete_user(User) of
ok -> {true, Req, State};
{error, _} -> {false, Req, State}
end.
@ -212,9 +209,8 @@ delete_completed(Req, State) -> {true, Req, State}.
create_user(Req, State) ->
{User, Pass, Email, Req0} = read_new_user_data(Req),
Host = cowboy_req:host(Req),
case dudeswave_backend:new_user(User, Host, Pass, Email) of
case dudeswave_backend:new_user(User, Pass, Email) of
ok -> {true, Req0, []};
{error, _} -> {false, Req0, State}
end.
@ -222,9 +218,8 @@ create_user(Req, State) ->
modify_user(Req, State) ->
{User, _} = dudeswave_web_common:auth_cookies(Req),
{Email, Desc, Name, Req0} = read_update_user_data(Req),
Host = cowboy_req:host(Req),
case dudeswave_backend:update_user(User, Host, Name, Email, Desc) of
case dudeswave_backend:update_user(User, Name, Email, Desc) of
ok -> {true, Req0, []};
{error, _} -> {false, Req0, State}
end.