diff options
Diffstat (limited to 'server/cldb.erl')
-rw-r--r-- | server/cldb.erl | 23 |
1 files changed, 14 insertions, 9 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} |