aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarco Ziener <mziener@lavabit.com>2010-10-15 10:27:31 +0200
committerMarco Ziener <mziener@lavabit.com>2010-10-15 10:27:31 +0200
commit7b384b413741a90828a946c7e527f8b2847a17d5 (patch)
treed2e0e4baab682ca46e266ccfd24c24cb733325bd
parente64206c54ce24d2346215c61cc7997b2009e446e (diff)
downloaderlang-7b384b413741a90828a946c7e527f8b2847a17d5.tar.gz
erlang-7b384b413741a90828a946c7e527f8b2847a17d5.tar.xz
erlang-7b384b413741a90828a946c7e527f8b2847a17d5.zip
Comments
-rw-r--r--server/cldb.erl7
1 files changed, 7 insertions, 0 deletions
diff --git a/server/cldb.erl b/server/cldb.erl
index e6f414e..1d4aba0 100644
--- a/server/cldb.erl
+++ b/server/cldb.erl
@@ -4,12 +4,14 @@
-export([init/0, all/0, find/1, login/2, dec_vote/1, inc_vote/1, register/3, check_rights/1, update_votes/0, logout/1, set_client_pid/2, get_votes/1]).
-record(user, {name, passwd, votes, logged_in, pid, rights}).
+%% The initialisations of the mnesia database
init() ->
mnesia:create_schema([node()]),
mnesia:start(),
mnesia:create_table(user, [{attributes, record_info(fields, user)}]),
io:format("Userdb up and running \n").
+%% The basic search operations on the database
find(User) when is_list(User) ->
find(User, '_');
find(User) ->
@@ -39,6 +41,8 @@ find_user_by_pid(Pid) ->
_ -> {error}
end.
+%% Retrieve all the entrys
+
all() ->
F = fun() ->
mnesia:match_object({user, '_', '_', '_', '_', '_', '_'})
@@ -48,6 +52,7 @@ all() ->
_ -> {error}
end.
+%% Perform the login operation of a user into the database.
login(User, Pwd) when is_list(User) and is_list(Pwd) ->
case find(User, Pwd) of
{atomic, [UserRow|_]} ->
@@ -68,6 +73,7 @@ login(User, Pwd) when is_list(User) and is_list(Pwd) ->
login(_, _) ->
{error}.
+%% Inorder to log out the client after his process died.
set_client_pid(User, Pid) ->
case find(User) of
{atomic, [UserRow|_]} ->
@@ -85,6 +91,7 @@ set_client_pid(User, Pid) ->
{error, user_not_found}
end.
+%% Changing the database to log out a user by PID
logout(Pid) ->
case find_user_by_pid(Pid) of
{atomic, [UserRow|_]} ->