本文整理汇总了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 });
}
示例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 });
}
示例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);
}
示例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 });
}
示例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);
}
示例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)));
}
示例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 });
}
示例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 });
}
示例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);
}
示例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);
}
}