Skip to content

Commit

Permalink
UpdateAddPhoneNumberActionMethod
Browse files Browse the repository at this point in the history
  • Loading branch information
sidsharma27 committed Jul 1, 2016
1 parent f732474 commit 7830bd4
Showing 1 changed file with 19 additions and 9 deletions.
28 changes: 19 additions & 9 deletions Nexmo2FADemo/Controllers/ManageController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,25 +109,35 @@ public ActionResult AddPhoneNumber()
//
// POST: /Manage/AddPhoneNumber
[HttpPost]
[AllowAnonymous]
[ValidateAntiForgeryToken]
public async Task<ActionResult> AddPhoneNumber(AddPhoneNumberViewModel model)
{
if (!ModelState.IsValid)
{
return View(model);
}
// Generate the token and send it
var code = await UserManager.GenerateChangePhoneNumberTokenAsync(User.Identity.GetUserId(), model.Number);
if (UserManager.SmsService != null)
var db = new ApplicationDbContext();
if (db.Users.FirstOrDefault(u => u.PhoneNumber == model.Number) == null)
{
var message = new IdentityMessage
// Generate the token and send it
var code = await UserManager.GenerateChangePhoneNumberTokenAsync((string)Session["UserID"], model.Number);
if (UserManager.SmsService != null)
{
Destination = model.Number,
Body = "Your security code is: " + code
};
await UserManager.SmsService.SendAsync(message);
var message = new IdentityMessage
{
Destination = model.Number,
Body = "Your security code is: " + code
};
await UserManager.SmsService.SendAsync(message);
}
return RedirectToAction("VerifyPhoneNumber", new { PhoneNumber = model.Number });
}
else
{
ModelState.AddModelError("", "The provided phone number is associated with another account.");
return View();
}
return RedirectToAction("VerifyPhoneNumber", new { PhoneNumber = model.Number });
}

//
Expand Down

0 comments on commit 7830bd4

Please sign in to comment.