Refactoring login and logout

Refactoring login and logout