Refactor login and register controllers