aboutsummaryrefslogtreecommitdiffstats
path: root/server/cldb.erl
blob: 6f6f4d2478411d94c76c80c3ab7077c6cf76b0f4 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
% The clientdatabase

-module(cldb).
-export([init/0]).
-record(user, {name, passwd, votes, rights}).

init() ->
    mnesia:create_schema([node()]),
    mnesia:start(),
    mnesia:create_table(user, [{attributes, record_info(fields, user)}]),
    io:format("Userdb up and running \n").
    
ask(User, Pwd) ->
    F = fun() ->
                mnesia:match_object({user, User, Pwd, '_'})
        end,
    mnesia:transaction(F).
    
                
    
login(User, Pwd) ->
    {_, Reason} = ask(User, Pwd),
    Reason.

register(User, Pwd, Root) ->
    F = fun() ->
                mnesia:write(#user{name = User, passwd = Pwd, votes = 5, rights = Root})
        end,
    {_, Reason} = mnesia:transaction(F),
    Reason.