aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlexander Sulfrian <alexander@sulfrian.net>2010-10-15 14:17:03 +0200
committerAlexander Sulfrian <alexander@sulfrian.net>2010-10-15 14:17:03 +0200
commitc775190e1b4d07777486e37bb21e61bb7f3ee690 (patch)
tree9f7a26516e3f879bbd8dffb7869838b08f62a017
parentd607a6d9528eac5d853817340585cfad11bc9dba (diff)
downloaderlang-c775190e1b4d07777486e37bb21e61bb7f3ee690.tar.gz
erlang-c775190e1b4d07777486e37bb21e61bb7f3ee690.tar.xz
erlang-c775190e1b4d07777486e37bb21e61bb7f3ee690.zip
check on login, if user is not logged in
-rw-r--r--server/cldb.erl23
-rw-r--r--server/dispatcher.erl6
2 files changed, 18 insertions, 11 deletions
diff --git a/server/cldb.erl b/server/cldb.erl
index b0a7a79..d81755f 100644
--- a/server/cldb.erl
+++ b/server/cldb.erl
@@ -56,15 +56,20 @@ all() ->
login(User, Pwd) when is_list(User) and is_list(Pwd) ->
case find(User, Pwd) of
{atomic, [UserRow|_]} ->
- NewUserRow = UserRow#user{logged_in = true},
- F = fun() ->
- mnesia:write(NewUserRow)
- end,
- case mnesia:transaction(F) of
- {atomic, ok} ->
- {ok, NewUserRow};
- {atomic, Why} ->
- {error, Why}
+ %% check if user is not already logged in
+ case UserRow#user.logged_in of
+ false ->
+ NewUserRow = UserRow#user{logged_in = true},
+ F = fun() ->
+ mnesia:write(NewUserRow)
+ end,
+ case mnesia:transaction(F) of
+ {atomic, ok} ->
+ {ok, NewUserRow};
+ {atomic, Why} ->
+ {error, Why}
+ end;
+ _ -> {error, allready_logged_in}
end;
_-> {error}
diff --git a/server/dispatcher.erl b/server/dispatcher.erl
index 08b19ec..b5d8aba 100644
--- a/server/dispatcher.erl
+++ b/server/dispatcher.erl
@@ -61,8 +61,10 @@ handle({login, {Node, User, Password}}, State) ->
Why ->
{{error, {unable_to_login, Why}}, State}
end;
- Why ->
- {{error, {user_or_password_invalid, Why}}, State}
+ {error, Why} ->
+ {{error, Why}, State};
+ _ ->
+ {{error, user_or_password_invalid}, State}
end;
handle({'EXIT', From, _}, State) ->