public async Task <CustomerInfoModel.TwoFactorAuthenticationModel> Handle(GetTwoFactorAuthentication request, CancellationToken cancellationToken)
        {
            var secretkey = Guid.NewGuid().ToString();
            var setupInfo = await _twoFactorAuthenticationService.GenerateCodeSetup(secretkey, request.Customer, request.Language, _customerSetting.TwoFactorAuthenticationType);

            var model = new CustomerInfoModel.TwoFactorAuthenticationModel
            {
                CustomValues = setupInfo.CustomValues,
                SecretKey    = secretkey,
                TwoFactorAuthenticationType = _customerSetting.TwoFactorAuthenticationType
            };

            if (_customerSetting.TwoFactorAuthenticationType == TwoFactorAuthenticationType.EmailVerification)
            {
                await _messageProviderService.SendCustomerEmailTokenValidationMessage(request.Customer, request.Store, request.Customer.Id);
            }

            return(model);
        }
        public async Task <IActionResult> TwoFactorAuthorization([FromServices] ITwoFactorAuthenticationService twoFactorAuthenticationService)
        {
            if (!_customerSettings.TwoFactorAuthenticationEnabled)
            {
                return(RedirectToRoute("AdminLogin"));
            }

            var username = HttpContext.Session.GetString("AdminRequiresTwoFactor");

            if (string.IsNullOrEmpty(username))
            {
                return(RedirectToRoute("AdminLogin"));
            }

            var customer = _customerSettings.UsernamesEnabled ? await _customerService.GetCustomerByUsername(username) : await _customerService.GetCustomerByEmail(username);

            if (customer == null)
            {
                return(RedirectToRoute("AdminLogin"));
            }

            if (!customer.GetUserFieldFromEntity <bool>(SystemCustomerFieldNames.TwoFactorEnabled))
            {
                return(RedirectToRoute("AdminLogin"));
            }

            if (_customerSettings.TwoFactorAuthenticationType != TwoFactorAuthenticationType.AppVerification)
            {
                await twoFactorAuthenticationService.GenerateCodeSetup("", customer, _workContext.WorkingLanguage, _customerSettings.TwoFactorAuthenticationType);

                if (_customerSettings.TwoFactorAuthenticationType == TwoFactorAuthenticationType.EmailVerification)
                {
                    await _messageProviderService.SendCustomerEmailTokenValidationMessage(customer, _workContext.CurrentStore, _workContext.WorkingLanguage.Id);
                }
            }

            return(View());
        }