当前位置: 首页>>代码示例>>C#>>正文


C# SendCodeViewModel类代码示例

本文整理汇总了C#中SendCodeViewModel的典型用法代码示例。如果您正苦于以下问题:C# SendCodeViewModel类的具体用法?C# SendCodeViewModel怎么用?C# SendCodeViewModel使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


SendCodeViewModel类属于命名空间,在下文中一共展示了SendCodeViewModel类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: SendCode

        public async Task<IActionResult> SendCode(SendCodeViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return View();
            }

            var user = await _signInManager.GetTwoFactorAuthenticationUserAsync();
            if (user == null)
            {
                return View("Error");
            }

            // Generate the token and send it
            var code = await _userManager.GenerateTwoFactorTokenAsync(user, model.SelectedProvider);
            if (string.IsNullOrWhiteSpace(code))
            {
                return View("Error");
            }

            var message = "Your security code is: " + code;
            if (model.SelectedProvider == "Email")
            {
                await _emailSender.SendEmailAsync(await _userManager.GetEmailAsync(user), "Security Code", message);
            }
            else if (model.SelectedProvider == "Phone")
            {
                await _smsSender.SendSmsAsync(await _userManager.GetPhoneNumberAsync(user), message);
            }

            return RedirectToAction(nameof(VerifyCode), new { Provider = model.SelectedProvider, ReturnUrl = model.ReturnUrl, RememberMe = model.RememberMe });
        }
开发者ID:usedflax,项目名称:flaxbox,代码行数:32,代码来源:AccountController.cs

示例2: SendCode

        public async Task<ActionResult> SendCode(SendCodeViewModel model)
        {
            if (!this.ModelState.IsValid)
            {
                return this.View();
            }

            // Generate the token and send it
            if (!await this.SignInManager.SendTwoFactorCodeAsync(model.SelectedProvider))
            {
                return this.View("Error");
            }
            return this.RedirectToAction(
                "VerifyCode",
                new { Provider = model.SelectedProvider, model.ReturnUrl, model.RememberMe });
        }
开发者ID:ASP-MVC,项目名称:Twitter-Like,代码行数:16,代码来源:AccountController.cs

示例3: SendCodePostReturnsRedirectToActionResult

        public async Task SendCodePostReturnsRedirectToActionResult()
        {
            var model = new SendCodeViewModel { SelectedProvider = string.Empty, ReturnUrl = "ReturnUrl", RememberMe = true };

            var routeValues = new Dictionary<string, object>
            {
                ["Provider"] = model.SelectedProvider,
                ["ReturnUrl"] = model.ReturnUrl,
                ["RememberMe"] = model.RememberMe
            };

            var userManager = CreateUserManagerMock();
            var signInManager = CreateSignInManagerMock(userManager);

            signInManager.Setup(x => x.GetTwoFactorAuthenticationUserAsync()).ReturnsAsync(new ApplicationUser());
            userManager.Setup(x => x.GenerateTwoFactorTokenAsync(It.IsAny<ApplicationUser>(), It.IsAny<string>())).ReturnsAsync("token");

            var sut = new AdminController(userManager.Object, signInManager.Object, null, null, null);
            var result = await sut.SendCode(model) as RedirectToActionResult;

            Assert.Equal(result.ActionName, nameof(AdminController.VerifyCode));
            Assert.Equal(result.RouteValues, routeValues);
        }
开发者ID:mheggeseth,项目名称:allReady,代码行数:23,代码来源:AdminControllerTests.cs

示例4: SendCode

        public async Task<ActionResult> SendCode(SendCodeViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return View();
            }

            // Создание и отправка маркера
            if (!await SignInManager.SendTwoFactorCodeAsync(model.SelectedProvider))
            {
                return View("Error");
            }
            return RedirectToAction("VerifyCode", new { Provider = model.SelectedProvider, ReturnUrl = model.ReturnUrl, RememberMe = model.RememberMe });
        }
开发者ID:akhroponiuk,项目名称:NewFolder,代码行数:14,代码来源:AccountController.cs

示例5: SendCodePostInvokesGenerateTwoFactorTokenAsyncWithCorrectUserAndTokenProvider

        public async Task SendCodePostInvokesGenerateTwoFactorTokenAsyncWithCorrectUserAndTokenProvider()
        {
            var applicationUser = new ApplicationUser();
            var model = new SendCodeViewModel { SelectedProvider = "Email" };

            var userManager = CreateUserManagerMock();

            var signInManager = CreateSignInManagerMock(userManager);
            signInManager.Setup(x => x.GetTwoFactorAuthenticationUserAsync()).ReturnsAsync(applicationUser);

            var sut = new AdminController(userManager.Object, signInManager.Object, null, null, null);
            await sut.SendCode(model);

            userManager.Verify(x => x.GenerateTwoFactorTokenAsync(applicationUser, model.SelectedProvider), Times.Once);
        }
开发者ID:mheggeseth,项目名称:allReady,代码行数:15,代码来源:AdminControllerTests.cs

示例6: SendCodePostSendsSendSecurityCodeSmsWithCorrectDataWhenSelectedProviderIsPhone

        public async Task SendCodePostSendsSendSecurityCodeSmsWithCorrectDataWhenSelectedProviderIsPhone()
        {
            const string token = "token";
            const string usersPhoneNumber = "usersPhoneNumber";

            var applicationUser = new ApplicationUser();
            var model = new SendCodeViewModel { SelectedProvider = "Phone" };

            var userManager = CreateUserManagerMock();
            var signInManager = CreateSignInManagerMock(userManager);
            var mediator = new Mock<IMediator>();

            userManager.Setup(x => x.GenerateTwoFactorTokenAsync(It.IsAny<ApplicationUser>(), It.IsAny<string>())).ReturnsAsync(token);
            userManager.Setup(x => x.GetPhoneNumberAsync(applicationUser)).ReturnsAsync(usersPhoneNumber);
            signInManager.Setup(x => x.GetTwoFactorAuthenticationUserAsync()).ReturnsAsync(applicationUser);

            var sut = new AdminController(userManager.Object, signInManager.Object, mediator.Object, null, null);
            await sut.SendCode(model);

            mediator.Verify(x => x.SendAsync(It.Is<SendSecurityCodeSms>(y => y.PhoneNumber == usersPhoneNumber && y.Token == token)));
        }
开发者ID:mheggeseth,项目名称:allReady,代码行数:21,代码来源:AdminControllerTests.cs

示例7: SendCode

        public async Task<ActionResult> SendCode(SendCodeViewModel model)
        {
            // Generate the token and send it
            if (!ModelState.IsValid)
            {
                return View();
            }

            if (!await SignInHelper.SendTwoFactorCode(model.SelectedProvider))
            {
                return View("Error");
            }
            return RedirectToAction("VerifyCode", new { Provider = model.SelectedProvider, ReturnUrl = model.ReturnUrl });
        }
开发者ID:rajeshwarn,项目名称:MasterKeyAuthentication,代码行数:14,代码来源:AccountController.cs

示例8: SendCode

        public async Task<IActionResult> SendCode(SendCodeViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return View();
            }
            
            var user = await _signInManager.GetTwoFactorAuthenticationUserAsync();
            if (user == null)
            {
                return View("Error");
            }
            
            // Generate the token and send it
            var token = await _userManager.GenerateTwoFactorTokenAsync(user, model.SelectedProvider);
            if (string.IsNullOrWhiteSpace(token))
            {
                return View("Error");
            }
            
            if (model.SelectedProvider == "Email")
            {
                await _mediator.SendAsync(new SendSecurityCodeEmail { Email = await _userManager.GetEmailAsync(user), Token = token });
            }
            else if (model.SelectedProvider == "Phone")
            {
                await _mediator.SendAsync(new SendAccountSecurityTokenSms { PhoneNumber = await _userManager.GetPhoneNumberAsync(user), Token = token });
            }

            return RedirectToAction(nameof(VerifyCode), new { Provider = model.SelectedProvider, model.ReturnUrl, model.RememberMe });
        }
开发者ID:nicolastarzia,项目名称:allReady,代码行数:31,代码来源:AdminController.cs

示例9: SendCode

        public async Task<ActionResult> SendCode(string returnUrl, bool rememberMe)
        {
            var userId = await this.SignInManager.GetVerifiedUserIdAsync();

            if (userId == null)
            {
                return this.View("Error");
            }

            var userFactors = await this.UserManager.GetValidTwoFactorProvidersAsync(userId);

            var factorOptions = userFactors.Select(purpose => new SelectListItem
            {
                Text = purpose,
                Value = purpose
            });

            var model = new SendCodeViewModel
            {
                Providers = factorOptions.ToList(),
                ReturnUrl = returnUrl,
                RememberMe = rememberMe
            };

            return this.View(model);
        }
开发者ID:csyntax,项目名称:BlogSystem,代码行数:26,代码来源:AccountController.cs

示例10: SendCode

        public async Task<ActionResult> SendCode(SendCodeViewModel model)
        {
            try
            {

          
            if (!ModelState.IsValid)
            {
                return View();
            }

            // Generate the token and send it
            if (!await SignInManager.SendTwoFactorCodeAsync(model.SelectedProvider))
            {
                return View("Error");
            }
            return RedirectToAction("VerifyCode", new { Provider = model.SelectedProvider, ReturnUrl = model.ReturnUrl, RememberMe = model.RememberMe });

            }
            catch (ValidationException ex)
            {
                throw (ex);
            }
            catch (Exception ex)
            {

                CommonTools.ErrorReporting(ex);
                return new HttpStatusCodeResult(System.Net.HttpStatusCode.InternalServerError);
            }
        }
开发者ID:angaratosurion,项目名称:BlackOwl,代码行数:30,代码来源:AccountController.cs


注:本文中的SendCodeViewModel类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。