Moved login logic to the controller