refactor login functionality to Api class