Refactored to use ngResource and login persistence