Moved login and registration logic to controller