有各種不同的地方,你可以做this.Say你正在做的事情一樣來註冊用戶
var user = new ApplicationUser { UserName = model.RegisterEmail.ToLower(), Email = model.RegisterEmail.ToLower(), PhoneNumber = model.RegisterPhoneNumber, EmailConfirmed = true, PhoneNumberConfirmed = true };
var addUserResult = await UserManager.CreateAsync(user, model.RegisterPassword);
if (!addUserResult.Succeeded)
{
ApplicationUser user = await UserManager.FindByEmailAsync(model.RegisterEmail.ToLower());
if(!user.EmailConfirmed)
{
var code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id);
//Send the new link
//return the error message accordingly.
}
}
您可以登錄
ApplicationUser user = await UserManager.FindAsync(model.UserName.ToLower(), model.Password);
if(user != null && !user.EmailConfirmed)
{
var code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id);
//Send the new link
//return the error message accordingly.
}
或在做samething如果您正在使用SigninManager(這是從默認的MVC模板)
var result = await SignInManager.PasswordSignInAsync(model.Email, model.Password, model.RememberMe, shouldLockout: false);
switch (result)
{
case SignInStatus.Success:
return RedirectToLocal(returnUrl);
case SignInStatus.LockedOut:
return View("Lockout");
case SignInStatus.RequiresVerification:
//redirecting to a different page
return RedirectToAction("SendCode", new { ReturnUrl = returnUrl, RememberMe = model.RememberMe });
case SignInStatus.Failure:
default:
ModelState.AddModelError("", "Invalid login attempt.");
return View(model);
}
希望這有助於。
這是可能的重複 http://stackoverflow.com/questions/27152612/email-token-expiring-after-15-mins-asp-identity-2-0-api – GauravKP
@GauravKP這裏的問題是完全的不同。操作系統詢問如何更改到期時間,我在詢問如何避免用戶無法註冊並且無法註冊的情況,因爲他已經在系統中,但因爲過期而沒有確認他的電子郵件。 – user3378165
要處理此類死鎖,您必須提供重新發送確認鏈接(提供的電子郵件和密碼經過驗證)的選項以及新的令牌。正如你所說的,你可以改變到期時間,但我們不應該讓它太長。另請注意,實時發送電子郵件也可能會失敗 – GauravKP