add logout function(and fix login flow control), #1