• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# SendCodeViewModel类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了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;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# SendOptions类代码示例发布时间:2022-05-24
下一篇:
C# Semaphore类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap