Advertisement
Guest User

Untitled

a guest
Mar 20th, 2019
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.00 KB | None | 0 0
  1. [HttpPost]
  2. [AllowAnonymous]
  3. public async Task<ActionResult> VerifyCode(string pin)
  4. {
  5. string userId = await SignInManager.GetVerifiedUserIdAsync().WithCurrentCulture();
  6.  
  7. if (userId == null || String.IsNullOrEmpty(pin))
  8. {
  9. return View("Error");
  10. }
  11.  
  12. var user = await UserManager.FindByIdAsync(userId);
  13.  
  14. if (await UserManager.VerifyTwoFactorTokenAsync(user.Id, "EmailCode", pin))
  15. {
  16. await SignInManager.SignInAsync(user, false, false);
  17. return RedirectToAction("Index", "Dashboards");
  18. }
  19. else
  20. {
  21. ModelState.AddModelError("", "Invalid code");
  22. }
  23.  
  24. return View();
  25. }
  26.  
  27. // Enables the application to temporarily store user information when they are verifying the second factor in the two-factor authentication process.
  28. app.UseTwoFactorSignInCookie(DefaultAuthenticationTypes.TwoFactorCookie, TimeSpan.FromMinutes(10));
  29.  
  30. // Enables the application to remember the second login verification factor such as phone or email.
  31. // Once you check this option, your second step of verification during the login process will be remembered on the device where you logged in from.
  32. // This is similar to the RememberMe option when you log in.
  33. app.UseTwoFactorRememberBrowserCookie(DefaultAuthenticationTypes.TwoFactorRememberBrowserCookie);
  34.  
  35. manager.RegisterTwoFactorProvider("EmailCode", new EmailTokenProvider<ApplicationUser>
  36. {
  37. Subject = "Security Code",
  38. BodyFormat = "Your security code is {0}"
  39. });
  40.  
  41. manager.EmailService = new EmailService();
  42. //manager.SmsService = new SmsService();
  43. var dataProtectionProvider = options.DataProtectionProvider;
  44. if (dataProtectionProvider != null)
  45. {
  46. manager.UserTokenProvider =
  47. new DataProtectorTokenProvider<ApplicationUser>(dataProtectionProvider.Create("ASP.NET Identity"));
  48. }
  49.  
  50. return manager;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement