refactor user login logic