Moving all model login from the controller to the model.