diff options
author | Jakob Pfender <jpfender@zedat.fu-berlin.de> | 2010-10-15 10:27:44 +0200 |
---|---|---|
committer | Jakob Pfender <jpfender@zedat.fu-berlin.de> | 2010-10-15 10:27:44 +0200 |
commit | 2c713d8c5983063bd6c52379d18b27254c2a023b (patch) | |
tree | 4ab81e3b65a8fb95ffc6ac6418e8f6ecb2ed3fb6 | |
parent | 0ab2e2a0a98304b28f326d3bad1ceb9a96d60402 (diff) | |
parent | 359418e0b7be058dfe728b5f881e3cda488fdc2c (diff) | |
download | erlang-2c713d8c5983063bd6c52379d18b27254c2a023b.tar.gz erlang-2c713d8c5983063bd6c52379d18b27254c2a023b.tar.xz erlang-2c713d8c5983063bd6c52379d18b27254c2a023b.zip |
Merge branch 'master' of ssh://git.animux.de/erlang
Diffstat (limited to '')
-rw-r--r-- | server/cldb.erl | 7 |
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|_]} -> |