Handling all the login/logout cases.