From c775190e1b4d07777486e37bb21e61bb7f3ee690 Mon Sep 17 00:00:00 2001 From: Alexander Sulfrian Date: Fri, 15 Oct 2010 14:17:03 +0200 Subject: check on login, if user is not logged in --- server/cldb.erl | 23 ++++++++++++++--------- server/dispatcher.erl | 6 ++++-- 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) -> -- cgit v1.2.3