本文整理汇总了C#中VerifyPhoneNumberViewModel类的典型用法代码示例。如果您正苦于以下问题:C# VerifyPhoneNumberViewModel类的具体用法?C# VerifyPhoneNumberViewModel怎么用?C# VerifyPhoneNumberViewModel使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
VerifyPhoneNumberViewModel类属于命名空间,在下文中一共展示了VerifyPhoneNumberViewModel类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: VerifyPhoneNumber
public async Task<IActionResult> VerifyPhoneNumber(VerifyPhoneNumberViewModel model)
{
if (!ModelState.IsValid)
{
return View(model);
}
var user = await GetCurrentUserAsync();
if (user != null)
{
var result = await _userManager.ChangePhoneNumberAsync(user, model.PhoneNumber, model.Code);
if (result.Succeeded)
{
await _signInManager.SignInAsync(user, isPersistent: false);
return RedirectToAction(nameof(Index), new { Message = ManageMessageId.AddPhoneSuccess });
}
}
// If we got this far, something failed, redisplay the form
ModelState.AddModelError(string.Empty, "Failed to verify phone number");
return View(model);
}
示例2: VerifyPhoneNumber
public async Task<ActionResult> VerifyPhoneNumber(VerifyPhoneNumberViewModel model)
{
if (!ModelState.IsValid)
{
return View(model);
}
var result = await UserManager.ChangePhoneNumberAsync(User.Identity.GetUserId(), model.PhoneNumber, model.Code);
if (result.Succeeded)
{
var user = await UserManager.FindByIdAsync(User.Identity.GetUserId());
if (user != null)
{
await SignInManager.SignInAsync(user, isPersistent: false, rememberBrowser: false);
}
return RedirectToAction("Index", new { Message = ManageMessageId.AddPhoneSuccess });
}
// If we got this far, something failed, redisplay form
ModelState.AddModelError("", "Failed to verify phone");
return View(model);
}
示例3: VerifyPhoneNumber
public async Task<ActionResult> VerifyPhoneNumber(VerifyPhoneNumberViewModel model)
{
if (!this.ModelState.IsValid)
{
return this.View(model);
}
var result = await this.UserManager.ChangePhoneNumberAsync(this.User.Identity.GetUserId(), model.PhoneNumber, model.Code);
if (result.Succeeded)
{
var user = await this.UserManager.FindByIdAsync(this.User.Identity.GetUserId());
if (user != null)
{
await this.SignInManager.SignInAsync(user, isPersistent: false, rememberBrowser: false);
}
return this.RedirectToAction("Index", new { Message = ManageMessageId.AddPhoneSuccess });
}
this.ModelState.AddModelError(string.Empty, "Failed to verify phone");
return this.View(model);
}
示例4: VerifyPhoneNumber
public async Task<ActionResult> VerifyPhoneNumber(VerifyPhoneNumberViewModel model)
{
if (!ModelState.IsValid)
{
return View(model);
}
var result = await UserManager.ChangePhoneNumberAsync(User.Identity.GetUserId(), model.PhoneNumber, model.Code);
if (result.Succeeded)
{
var user = await UserManager.FindByIdAsync(User.Identity.GetUserId());
if (user != null)
{
await SignInManager.SignInAsync(user, isPersistent: false, rememberBrowser: false);
}
return RedirectToAction("Index", new { Message = ManageMessageId.AddPhoneSuccess });
}
// Si llegamos a este punto, es que se ha producido un error, volvemos a mostrar el formulario
ModelState.AddModelError("", "No se ha podido comprobar el teléfono");
return View(model);
}
示例5: VerifyPhoneNumber
public async Task<ActionResult> VerifyPhoneNumber(VerifyPhoneNumberViewModel model)
{
if (!ModelState.IsValid)
{
return View(model);
}
var result = await UserManager.ChangePhoneNumberAsync(User.Identity.GetUserId(), model.PhoneNumber, model.Code);
if (result.Succeeded)
{
var user = await UserManager.FindByIdAsync(User.Identity.GetUserId());
if (user != null)
{
await SignInManager.SignInAsync(user, isPersistent: false, rememberBrowser: false);
}
return RedirectToAction("Index", new { Message = ManageMessageId.AddPhoneSuccess });
}
// Это сообщение означает наличие ошибки; повторное отображение формы
ModelState.AddModelError("", "Не удалось проверить телефон");
return View(model);
}
示例6: VerifyPhoneNumber
public async Task<ActionResult> VerifyPhoneNumber(VerifyPhoneNumberViewModel model)
{
if (!ModelState.IsValid)
{
return View(model);
}
var result = await UserManager.ChangePhoneNumberAsync(User.Identity.GetUserId(), model.PhoneNumber, model.Code);
if (result.Succeeded)
{
var user = await UserManager.FindByIdAsync(User.Identity.GetUserId());
if (user != null)
{
await SignInManager.SignInAsync(user, isPersistent: false, rememberBrowser: false);
}
return RedirectToAction("Index", new { Message = ManageMessageId.AddPhoneSuccess });
}
// 如果我们进行到这一步时某个地方出错,则重新显示表单
ModelState.AddModelError("", "无法验证电话号码");
return View(model);
}
示例7: VerifyPhoneNumber
public async Task<ActionResult> VerifyPhoneNumber(VerifyPhoneNumberViewModel model)
{
if (!ModelState.IsValid)
{
return View(model);
}
ObjectId userId = User.Identity.GetUserId2<ObjectId>();
IdentityResult result = await _userManager.ChangePhoneNumberAsync(userId
, model.PhoneNumber, model.Code);
if (result.Succeeded)
{
var user = await _userManager.FindByIdAsync(User.Identity.GetUserId2<ObjectId>());
if (user != null)
{
await SignInAsync(user, isPersistent: false);
}
return RedirectToAction("Index", new { Message = ManageMessageId.AddPhoneSuccess });
}
// If we got this far, something failed, redisplay form
string errorMessage = IdentityResourceHelper.Load(IdentitySettings.IdentityResource, "ManageController_VerifyPhoneNumber_Error");
ModelState.AddModelError("", errorMessage);
return View(model);
}
示例8: VerifyPhoneNumber
public void VerifyPhoneNumber(
VerifyPhoneNumberViewModel model,
ModelMethodContext context)
{
if (!context.ModelState.IsValid) return;
var userId = _context.User.Identity.GetUserId();
var result = _userManager.ChangePhoneNumber(
userId, model.PhoneNumber, model.Code);
if (result.Succeeded)
{
var user = _userManager.FindById(userId);
if (user != null)
{
SignIn(user, false);
RedirectToManager(ManageMessageId.AddPhoneSuccess);
}
}
else
{
context.ModelState.AddModelError("", "Invalid verification code");
}
}
示例9: VerifyPhoneNumber
public async Task<ActionResult> VerifyPhoneNumber(VerifyPhoneNumberViewModel model)
{
if (!ModelState.IsValid)
{
return View(model);
}
//The ChangePhoneNumberAsync method checks the posted security code.
//If the code is correct, the phone number is added to the PhoneNumber field of the AspNetUsers table.
var result = await UserManager.ChangePhoneNumberAsync(User.Identity.GetUserId(), model.PhoneNumber, model.Code);
//If that call is successful, the SignInAsync method is called:
if (result.Succeeded)
{
var user = await UserManager.FindByIdAsync(User.Identity.GetUserId());
if (user != null)
{
//The isPersistent parameter sets whether the authentication session is persisted across multiple requests.
//When you change your security profile, a new security stamp is generated and stored in the SecurityStamp field of the AspNetUsers table.
//Note, the SecurityStamp field is different from the security cookie.
//The security cookie is not stored in the AspNetUsers table (or anywhere else in the Identity DB).
//The security cookie token is self-signed using DPAPI and is created with the UserId, SecurityStamp and expiration time information.
//The cookie middleware checks the cookie on each request.
//The SecurityStampValidator method in the Startup class hits the DB and checks security stamp periodically, as specified with the validateInterval.
//This only happens every 30 minutes (in our sample) unless you change your security profile. //
//The 30 minute interval was chosen to minimize trips to the database.
//The SignInAsync method needs to be called when any change is made to the security profile.
//When the security profile changes, the database is updates the SecurityStamp field, and without calling the SignInAsync
//method you would stay logged in only until the next time the OWIN pipeline hits the database (the validateInterval).
//You can test this by changing the SignInAsync method to return immediately, and setting the cookie validateInterval
//property from 30 minutes to 5 seconds:
//private async Task SignInAsync(ApplicationUser user, bool isPersistent)
//{
// // Clear the temporary cookies used for external and two factor sign ins
// AuthenticationManager.SignOut(DefaultAuthenticationTypes.ExternalCookie,
// DefaultAuthenticationTypes.TwoFactorCookie);
// AuthenticationManager.SignIn(new AuthenticationProperties
// {
// IsPersistent = isPersistent
// },
// await user.GenerateUserIdentityAsync(UserManager));
//}
await SignInManager.SignInAsync(user, isPersistent: false, rememberBrowser: false);
}
return RedirectToAction("Index", new { Message = ManageMessageId.AddPhoneSuccess });
}
// If we got this far, something failed, redisplay form
ModelState.AddModelError("", "Failed to verify phone");
return View(model);
}