Compare commits
No commits in common. "5b73df899939708029d8adc0c90e0f21f79fa00c" and "ea339a10248ca1a72e5f644415cff1a022e95c91" have entirely different histories.
5b73df8999
...
ea339a1024
|
@ -19,6 +19,8 @@
|
||||||
-export([bootstrap/3, start/2, stop/1]).
|
-export([bootstrap/3, start/2, stop/1]).
|
||||||
|
|
||||||
start(_Type, StartArgs) ->
|
start(_Type, StartArgs) ->
|
||||||
|
crypto:rand_seed(),
|
||||||
|
|
||||||
dudeswave_backend_supervisor:start_link(StartArgs).
|
dudeswave_backend_supervisor:start_link(StartArgs).
|
||||||
|
|
||||||
stop(_State) -> ok.
|
stop(_State) -> ok.
|
||||||
|
|
|
@ -5,6 +5,6 @@
|
||||||
dudeswave_users_supervisor,
|
dudeswave_users_supervisor,
|
||||||
dudeswave_users_auth,dudeswave_users_user]},
|
dudeswave_users_auth,dudeswave_users_user]},
|
||||||
{registered,[]},
|
{registered,[]},
|
||||||
{applications,[kernel,stdlib,erts,storage,crypto]},
|
{applications,[kernel,stdlib,erts]},
|
||||||
{mod,{dudeswave_users_app,[]}},
|
{mod,{dudeswave_users_app,[]}},
|
||||||
{start_phases,[]}]}.
|
{start_phases,[]}]}.
|
||||||
|
|
|
@ -8,7 +8,6 @@ ERLFLAGS= -I ../../
|
||||||
OBJS= dudeswave_web.beam dudeswave_web_app.beam
|
OBJS= dudeswave_web.beam dudeswave_web_app.beam
|
||||||
OBJS+= dudeswave_web_supervisor.beam dudeswave_web_handler.beam
|
OBJS+= dudeswave_web_supervisor.beam dudeswave_web_handler.beam
|
||||||
OBJS+= dudeswave_web_user_handler.beam dudeswave_web_common.beam
|
OBJS+= dudeswave_web_user_handler.beam dudeswave_web_common.beam
|
||||||
OBJS+= dudeswave_web_auth_handler.beam
|
|
||||||
|
|
||||||
all: ${OBJS}
|
all: ${OBJS}
|
||||||
|
|
||||||
|
|
|
@ -13,7 +13,7 @@
|
||||||
% ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
% ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||||
% OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
% OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
%
|
%
|
||||||
-module(dudeswave_web_auth_handler).
|
-module(dudeswave_auth_handler).
|
||||||
-moduledoc """
|
-moduledoc """
|
||||||
JSON API to authenticate users.
|
JSON API to authenticate users.
|
||||||
|
|
||||||
|
@ -94,10 +94,9 @@ forbidden(Req, State) ->
|
||||||
<<"POST">> ->
|
<<"POST">> ->
|
||||||
{false, Req, State};
|
{false, Req, State};
|
||||||
_ ->
|
_ ->
|
||||||
{User, Cookie} = dudeswave_web_common:auth_cookies(Req),
|
{User, Auth} = dudeswave_web_common:auth_cookies(Req),
|
||||||
Host = cowboy_req:host(Req),
|
|
||||||
|
|
||||||
case dudeswave_backend:auth(cookie, User, Host, Cookie) of
|
case dudeswave_backend:auth(cookie, User, Cookie) of
|
||||||
{error, service_unavailable} -> exit(service_unavailable);
|
{error, service_unavailable} -> exit(service_unavailable);
|
||||||
true -> {false, Req, State};
|
true -> {false, Req, State};
|
||||||
false -> {true, Req, State}
|
false -> {true, Req, State}
|
||||||
|
@ -114,9 +113,8 @@ content_types_accepted(Req, State) ->
|
||||||
|
|
||||||
resource_exists(Req, State) ->
|
resource_exists(Req, State) ->
|
||||||
{User, _} = dudeswave_web_common:auth_cookies(Req),
|
{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};
|
{false, Req, State};
|
||||||
{error, Reason} ->
|
{error, Reason} ->
|
||||||
|
@ -138,9 +136,8 @@ allow_missing_post(Req, State) -> {false, Req, State}.
|
||||||
|
|
||||||
delete_resource(Req, State) ->
|
delete_resource(Req, State) ->
|
||||||
{User, Auth} = dudeswave_web_common:auth_cookies(Req),
|
{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 ->
|
ok ->
|
||||||
{true, invalidate_cookies(Req), State};
|
{true, invalidate_cookies(Req), State};
|
||||||
{error, _} ->
|
{error, _} ->
|
||||||
|
@ -155,9 +152,8 @@ delete_completed(Req, State) -> {false, Req, State}.
|
||||||
|
|
||||||
login(Req, State) ->
|
login(Req, State) ->
|
||||||
{User, Pass, Req0} = read_login_data(Req),
|
{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, Cookie, Validity} ->
|
||||||
{true, set_auth_cookies(Req, User, Cookie, Validity), State};
|
{true, set_auth_cookies(Req, User, Cookie, Validity), State};
|
||||||
false ->
|
false ->
|
||||||
|
|
|
@ -139,9 +139,8 @@ forbidden(Req, State) ->
|
||||||
{false, Req, State};
|
{false, Req, State};
|
||||||
_ ->
|
_ ->
|
||||||
{User, Auth} = dudeswave_web_common:auth_cookies(Req),
|
{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};
|
{error, service_unavailable} -> {true, Req, State};
|
||||||
true -> {false, Req, State};
|
true -> {false, Req, State};
|
||||||
false -> {true, Req, State}
|
false -> {true, Req, State}
|
||||||
|
@ -170,9 +169,8 @@ content_types_accepted(Req, State) ->
|
||||||
|
|
||||||
resource_exists(Req, State) ->
|
resource_exists(Req, State) ->
|
||||||
{User, _} = dudeswave_web_common:auth_cookies(Req),
|
{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};
|
{false, Req, State};
|
||||||
{error, _} ->
|
{error, _} ->
|
||||||
|
@ -197,9 +195,8 @@ allow_missing_post(Req, State) -> {false, Req, State}.
|
||||||
|
|
||||||
delete_resource(Req, State) ->
|
delete_resource(Req, State) ->
|
||||||
{User, _} = dudeswave_web_common:auth_cookies(Req),
|
{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};
|
ok -> {true, Req, State};
|
||||||
{error, _} -> {false, Req, State}
|
{error, _} -> {false, Req, State}
|
||||||
end.
|
end.
|
||||||
|
@ -212,9 +209,8 @@ delete_completed(Req, State) -> {true, Req, State}.
|
||||||
|
|
||||||
create_user(Req, State) ->
|
create_user(Req, State) ->
|
||||||
{User, Pass, Email, Req0} = read_new_user_data(Req),
|
{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, []};
|
ok -> {true, Req0, []};
|
||||||
{error, _} -> {false, Req0, State}
|
{error, _} -> {false, Req0, State}
|
||||||
end.
|
end.
|
||||||
|
@ -222,9 +218,8 @@ create_user(Req, State) ->
|
||||||
modify_user(Req, State) ->
|
modify_user(Req, State) ->
|
||||||
{User, _} = dudeswave_web_common:auth_cookies(Req),
|
{User, _} = dudeswave_web_common:auth_cookies(Req),
|
||||||
{Email, Desc, Name, Req0} = read_update_user_data(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, []};
|
ok -> {true, Req0, []};
|
||||||
{error, _} -> {false, Req0, State}
|
{error, _} -> {false, Req0, State}
|
||||||
end.
|
end.
|
||||||
|
|
Loading…
Reference in New Issue