Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- [HttpPost]
- [AllowAnonymous]
- public async Task<ActionResult> VerifyCode(string pin)
- {
- string userId = await SignInManager.GetVerifiedUserIdAsync().WithCurrentCulture();
- if (userId == null || String.IsNullOrEmpty(pin))
- {
- return View("Error");
- }
- var user = await UserManager.FindByIdAsync(userId);
- if (await UserManager.VerifyTwoFactorTokenAsync(user.Id, "EmailCode", pin))
- {
- await SignInManager.SignInAsync(user, false, false);
- return RedirectToAction("Index", "Dashboards");
- }
- else
- {
- ModelState.AddModelError("", "Invalid code");
- }
- return View();
- }
- // Enables the application to temporarily store user information when they are verifying the second factor in the two-factor authentication process.
- app.UseTwoFactorSignInCookie(DefaultAuthenticationTypes.TwoFactorCookie, TimeSpan.FromMinutes(10));
- // Enables the application to remember the second login verification factor such as phone or email.
- // 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.
- // This is similar to the RememberMe option when you log in.
- app.UseTwoFactorRememberBrowserCookie(DefaultAuthenticationTypes.TwoFactorRememberBrowserCookie);
- manager.RegisterTwoFactorProvider("EmailCode", new EmailTokenProvider<ApplicationUser>
- {
- Subject = "Security Code",
- BodyFormat = "Your security code is {0}"
- });
- manager.EmailService = new EmailService();
- //manager.SmsService = new SmsService();
- var dataProtectionProvider = options.DataProtectionProvider;
- if (dataProtectionProvider != null)
- {
- manager.UserTokenProvider =
- new DataProtectorTokenProvider<ApplicationUser>(dataProtectionProvider.Create("ASP.NET Identity"));
- }
- return manager;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement