Refactor some controller logic and add login controller.