aboutsummaryrefslogtreecommitdiffstats
path: root/client
diff options
context:
space:
mode:
authorAlexander Sulfrian <alexander@sulfrian.net>2010-10-14 17:37:18 +0200
committerAlexander Sulfrian <alexander@sulfrian.net>2010-10-14 17:37:18 +0200
commitab13a717fe4e443c233694c69573deb11dbdf453 (patch)
tree44256fdf5b08dd67afd618913f2fc153df3dd247 /client
parent3ab5da8355e114953c154114aa4c0c36b719e92e (diff)
downloaderlang-ab13a717fe4e443c233694c69573deb11dbdf453.tar.gz
erlang-ab13a717fe4e443c233694c69573deb11dbdf453.tar.xz
erlang-ab13a717fe4e443c233694c69573deb11dbdf453.zip
changed user database from dict to mnesia (modules: cldb)
Diffstat (limited to 'client')
-rw-r--r--client/client.erl36
1 files changed, 30 insertions, 6 deletions
diff --git a/client/client.erl b/client/client.erl
index 0e2fada..f500fe1 100644
--- a/client/client.erl
+++ b/client/client.erl
@@ -1,5 +1,5 @@
-module(client).
--export([register/3, login/3, list/0, handle/2, getVotes/0, vote/2, devote/2]).
+-export([register/2, register/3, login/3, list/0, handle/2, getVotes/0, vote/2, devote/2]).
checkLogin(Value) ->
%% check if user meets the requirements to be locked in or not by
@@ -17,13 +17,34 @@ buildNode(Server) ->
rpc(Server, Function, Params) ->
rpc:call(buildNode(Server), client, Function, Params).
-register(Server, Name, Password) ->
- rpc(Server, register, [self(), {Name, Password}]),
+wait_for_reply() ->
receive
{_, Msg} ->
- Msg
+ Msg;
+ Why -> Why
+ after 3000 ->
+ {error, timeout}
+ end.
+
+register(Name, Password) ->
+ try checkLogin(true) of
+ _ ->
+ server:rpc(cli, {register, Name, Password})
+ catch
+ {error, login_state} ->
+ {error, not_logged_in}
end.
+register(Server, Name, Password) ->
+ try checkLogin(false) of
+ _ ->
+ rpc(Server, register, [self(), {Name, Password}])
+ catch
+ {error, login_state} ->
+ {error, logged_in}
+ end,
+ wait_for_reply().
+
login(Server, Name, Password) ->
code:purge(server),
code:load_abs("../common/server"),
@@ -33,12 +54,14 @@ login(Server, Name, Password) ->
rpc(Server, login, [self(), {node(), Name, Password}]),
receive
{ok, {ok, {logged_in, Pid}}} ->
- register(cli, Pid),
+ erlang:register(cli, Pid),
{ok, logged_in};
{_, Msg} ->
Msg;
Msg ->
Msg
+ after 3000 ->
+ {error, timeout}
end
catch
{error, login_state} ->
@@ -71,7 +94,8 @@ handle({vote, Artist, Title}, Server) ->
send_to_server({vote, Artist, Title}, Server);
handle({devote, Artist, Title}, Server) ->
send_to_server({devote, Artist, Title}, Server);
-
+handle({register, Name, Password}, Server) ->
+ send_to_server({register, Name, Password}, Server);
handle({change_state, NewState}, _) ->
{{ok}, NewState};