From 6054521e117539d2a5d16f08a6b107e13c9dc370 Mon Sep 17 00:00:00 2001 From: Marco Ziener Date: Thu, 14 Oct 2010 15:47:04 +0200 Subject: Cleaned --- server/cldb.erl | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'server/cldb.erl') diff --git a/server/cldb.erl b/server/cldb.erl index 0f9f407..9aad688 100644 --- a/server/cldb.erl +++ b/server/cldb.erl @@ -10,3 +10,14 @@ init() -> mnesia:create_table(track, [{attributes, record_info(fields, track)}]), io:format("Userdb up and running \n"). + +ask(User, Pwd) -> + F = fun() -> + mnesia:match_object({user, User, Pwd, _}), + end, + + + +login(User, Pwd) -> + {_, Reason} = ask(User, Pwd), + Reason. -- cgit v1.2.3 From be34a99dbb4e516d7592d6a19d0c662b6d81ab17 Mon Sep 17 00:00:00 2001 From: Marco Ziener Date: Thu, 14 Oct 2010 15:52:57 +0200 Subject: Blub --- server/cldb.erl | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) (limited to 'server/cldb.erl') diff --git a/server/cldb.erl b/server/cldb.erl index 9aad688..6f6f4d2 100644 --- a/server/cldb.erl +++ b/server/cldb.erl @@ -2,22 +2,31 @@ -module(cldb). -export([init/0]). --record(user, {name, passwd, votes}). +-record(user, {name, passwd, votes, rights}). init() -> mnesia:create_schema([node()]), mnesia:start(), - mnesia:create_table(track, [{attributes, record_info(fields, track)}]), + 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, _}), + 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. + + -- cgit v1.2.3 From d4974ca3ef2f4e664a78912837989762997d14dd Mon Sep 17 00:00:00 2001 From: Marco Ziener Date: Thu, 14 Oct 2010 16:03:19 +0200 Subject: Finished --- server/cldb.erl | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'server/cldb.erl') diff --git a/server/cldb.erl b/server/cldb.erl index 6f6f4d2..3886685 100644 --- a/server/cldb.erl +++ b/server/cldb.erl @@ -29,4 +29,22 @@ register(User, Pwd, Root) -> {_, Reason} = mnesia:transaction(F), Reason. +decVote(User, Pwd) -> + F = fun() -> + [Head|_] = ask(User, Pwd), + Votes = Head#user.votes - 1, + New = Head#user{votes = Votes}, + mnesia:write(New) + end, + mnesia:transaction(F). + +incVote(User, Pwd) -> + F = fun() -> + [Head|_] = ask(User, Pwd), + Votes = Head#user.votes + 1, + New = Head#user{votes = Votes}, + mnesia:write(New) + end, + mnesia:transaction(F). + -- cgit v1.2.3 From cfa125e96062c4ccabc155f68c36bc8bcf754b61 Mon Sep 17 00:00:00 2001 From: Marco Ziener Date: Thu, 14 Oct 2010 16:04:26 +0200 Subject: ... --- server/cldb.erl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'server/cldb.erl') diff --git a/server/cldb.erl b/server/cldb.erl index 3886685..176576c 100644 --- a/server/cldb.erl +++ b/server/cldb.erl @@ -1,7 +1,7 @@ % The clientdatabase -module(cldb). --export([init/0]). +-export([init/0, ask/2, login/2, decVote/2, incVote/2, register/3]). -record(user, {name, passwd, votes, rights}). init() -> -- cgit v1.2.3 From bde55a9f9456b7ab38b8ae35a3dc65cf4044aabe Mon Sep 17 00:00:00 2001 From: Marco Ziener Date: Thu, 14 Oct 2010 16:14:18 +0200 Subject: Rights Check --- server/cldb.erl | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'server/cldb.erl') diff --git a/server/cldb.erl b/server/cldb.erl index 176576c..982aafc 100644 --- a/server/cldb.erl +++ b/server/cldb.erl @@ -1,7 +1,7 @@ % The clientdatabase -module(cldb). --export([init/0, ask/2, login/2, decVote/2, incVote/2, register/3]). +-export([init/0, ask/2, login/2, decVote/2, incVote/2, register/3, check_rights/2]). -record(user, {name, passwd, votes, rights}). init() -> @@ -47,4 +47,7 @@ incVote(User, Pwd) -> end, mnesia:transaction(F). +check_rights(User, Name) -> + {_, _, Rights} = ask(User, Name), + Rights. -- cgit v1.2.3