public async Task<ActionResult> VerifyPhoneNumber(VerifyPhoneNumberViewModel model) { var result = await UserManager.ChangePhoneNumberAsync(User.Identity.GetUserId(), model.PhoneNumber, model.Code); if (!result.Succeeded) { var message = result.Errors.Aggregate("验证电话号码失败!", (current, errorMessage) => current + (";" + errorMessage)); return Json(message); } var user = await UserManager.FindByIdAsync(User.Identity.GetUserId()); if (user != null) { await SignInManager.SignInAsync(user, isPersistent: false, rememberBrowser: false); } return Json("验证电话号码成功!"); }
public async Task<ActionResult> AddPhoneNumber(VerifyPhoneNumberViewModel model) { // 生成令牌并发送该令牌 var code = await UserManager.GenerateChangePhoneNumberTokenAsync(User.Identity.GetUserId(), model.PhoneNumber); if (UserManager.SmsService != null) { var message = new IdentityMessage { Destination = model.PhoneNumber, Body = "你的安全代码是: " + code }; await UserManager.SmsService.SendAsync(message); } return Json(new VerifyPhoneNumberViewModel { PhoneNumber = model.PhoneNumber, Code = code }); }