Refacture user registering and login