Refactored two_factor_authenticatable hook