ASP.NET MVC email registration confirmation
je utilise le projet par défaut asp.net mvc
et je veux configurer le confirmation d'Email
mais après la confirmation je peux pas se connecter
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
|
[HttpPost]
[AllowAnonymous]
[ValidateAntiForgeryToken]
public async Task<ActionResult> Register(RegisterViewModel model)
{
if (ModelState.IsValid)
{
var user = new ApplicationUser { UserName = model.Email, Email = model.Email };
var result = await UserManager.CreateAsync(user, model.Password);
if (result.Succeeded)
{
// Comment the following line to prevent log in until the user is confirmed.
// await SignInManager.SignInAsync(user, isPersistent:false, rememberBrowser:false);
string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id);
var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme);
await UserManager.SendEmailAsync(user.Id, "Currency Protector - Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>");
ViewBag.Message = "Check your email and confirm your account, you must be confirmed "
+ "before you can log in.";
return View("Info");
}
AddErrors(result);
}
// If we got this far, something failed, redisplay form
return View(model);
} |
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
|
public class EmailService : IIdentityMessageService
{
public Task SendAsync(IdentityMessage message)
{
MailMessage mail = new MailMessage();
mail.From = new MailAddress("XXX@gmail.com");
mail.To.Add(message.Destination);
mail.Subject = message.Subject;
mail.Body = message.Body;
mail.IsBodyHtml = true;
SmtpClient smtp = new SmtpClient("smtp.gmail.com", 587);
smtp.EnableSsl = true;
smtp.Credentials = new NetworkCredential("XXX@gmail.com", "PASS");
return smtp.SendMailAsync(mail);
} |
la confirmation est bien fait mais pour quoi je peut se connecter