Updated che back-end to use the new multi-host calls.

The listeners update will come later.
main
absc 2024-09-15 13:44:10 +00:00
parent b1c4ab8e16
commit ea339a1024
1 changed files with 30 additions and 30 deletions

View File

@ -24,8 +24,8 @@
-export([init/1, handle_call/3, handle_cast/2, terminate/2]). -export([init/1, handle_call/3, handle_cast/2, terminate/2]).
% Public API exports % Public API exports
-export([auth/3, logout/2, user_details/1, new_user/3, -export([auth/4, logout/3, user_details/2, new_user/4,
update_user/4, delete_user/1]). update_user/5, delete_user/2]).
% %
% Startup functions % Startup functions
@ -47,33 +47,33 @@ init([]) ->
% Users management % Users management
% %
auth(cookie, User, Cookie) -> auth(cookie, User, Host, Cookie) ->
gen_server:call({local, ?MODULE}, {cookie, User, Cookie}); gen_server:call({local, ?MODULE}, {cookie, User, Host, Cookie});
auth(password, User, Password) -> auth(password, User, Host, Password) ->
gen_server:call({local, ?MODULE}, {password, User, Password}). gen_server:call({local, ?MODULE}, {password, User, Host, Password}).
logout(User, Cookie) -> logout(User, Host, Cookie) ->
gen_server:call({local, ?MODULE}, {logout, User, Cookie}). gen_server:call({local, ?MODULE}, {logout, User, Host, Cookie}).
user_details(User) -> user_details(User, Host) ->
gen_server:call({local, ?MODULE}, {user_details, User}). gen_server:call({local, ?MODULE}, {user_details, User, Host}).
new_user(User, Password, Email) -> new_user(User, Host, Password, Email) ->
gen_server:call({local, ?MODULE}, {new_user, User, Password, Email}). gen_server:call({local, ?MODULE}, {new_user, User, Host, Password, Email}).
update_user(User, Name, Email, Desc) -> update_user(User, Host, Name, Email, Desc) ->
gen_server:call({local, ?MODULE}, {update_user, User, Name, Email, Desc}). gen_server:call({local, ?MODULE}, {update_user, User, Host, Name, Email, Desc}).
delete_user(User) -> delete_user(User, Host) ->
gen_server:call({local, ?MODULE}, {delete_user, User}). gen_server:call({local, ?MODULE}, {delete_user, User, Host}).
% %
% Callbacks % Callbacks
% %
handle_call({cookie, User, Cookie}, _From, State) -> handle_call({cookie, User, Host, Cookie}, _From, State) ->
case dudeswave_users:authenticate(cookie, User, Cookie) of case dudeswave_users:authenticate(cookie, User, Host, Cookie) of
true -> true ->
{reply, true, State}; {reply, true, State};
false -> false ->
@ -82,8 +82,8 @@ handle_call({cookie, User, Cookie}, _From, State) ->
{reply, {error, Reason}, State} {reply, {error, Reason}, State}
end; end;
handle_call({password, User, Password}, _From, State) -> handle_call({password, User, Host, Password}, _From, State) ->
case dudeswave_users:authenticate(password, User, Password) of case dudeswave_users:authenticate(password, User, Host, Password) of
{true, Cookie, Validity} -> {true, Cookie, Validity} ->
{reply, {true, Cookie, Validity}, State}; {reply, {true, Cookie, Validity}, State};
false -> false ->
@ -92,33 +92,33 @@ handle_call({password, User, Password}, _From, State) ->
{reply, {error, Reason}, State} {reply, {error, Reason}, State}
end; end;
handle_call({logout, User, Cookie}, _From, State) -> handle_call({logout, User, Host, Cookie}, _From, State) ->
case dudeswave_users:logout(User, Cookie) of case dudeswave_users:logout(User, Host, Cookie) of
ok -> {reply, ok, State}; ok -> {reply, ok, State};
{error, Reason} -> {reply, {error, Reason}, State} {error, Reason} -> {reply, {error, Reason}, State}
end; end;
handle_call({user_details, User}, _From, State) -> handle_call({user_details, User, Host}, _From, State) ->
case dudeswave_users:details(User) of case dudeswave_users:details(User, Host) of
{error, not_found} -> {reply, not_found, State}; {error, not_found} -> {reply, not_found, State};
{error, Reason} -> {reply, {error, Reason}, State}; {error, Reason} -> {reply, {error, Reason}, State};
Val -> {reply, Val, State} Val -> {reply, Val, State}
end; end;
handle_call({new_user, User, Password, Email}, _From, State) -> handle_call({new_user, User, Host, Password, Email}, _From, State) ->
case dudeswave_users:new(User, Password, Email) of case dudeswave_users:new(User, Host, Password, Email) of
ok -> {reply, ok, State}; ok -> {reply, ok, State};
{error, Reason} -> {reply, {error, Reason}, State} {error, Reason} -> {reply, {error, Reason}, State}
end; end;
handle_call({update_user, User, Name, Email, Desc}, _From, State) -> handle_call({update_user, User, Host, Name, Email, Desc}, _From, State) ->
case dudeswave_users:update(User, Name, Email, Desc) of case dudeswave_users:update(User, Host, Name, Email, Desc) of
ok -> {reply, ok, State}; ok -> {reply, ok, State};
{error, Reason} -> {reply, {error, Reason}, State} {error, Reason} -> {reply, {error, Reason}, State}
end; end;
handle_call({delete_user, User}, _From, State) -> handle_call({delete_user, User, Host}, _From, State) ->
case dudeswave_users:delete(User) of case dudeswave_users:delete(User, Host) of
ok -> {reply, ok, State}; ok -> {reply, ok, State};
{error, Reason} -> {reply, {error, Reason}, State} {error, Reason} -> {reply, {error, Reason}, State}
end. end.