diff options
Diffstat (limited to '')
-rw-r--r-- | server/cldb.erl | 23 | ||||
-rw-r--r-- | 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) -> |