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 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
|
[HttpPost]
[AllowAnonymous]
[ValidateAntiForgeryToken]
public async Task<ActionResult> Register(RegisterViewModel model)
{
string testmail="";
testmail = UsersContext.Users.Where(m => m.Email == model.Email).SingleOrDefault().Email;
if (ModelState.IsValid)
{
if (!model.Email.Equals(testmail) )
{
var user = new ApplicationUser() { UserName = model.UserName };
user.Email = model.Email;
user.ConfirmedEmail = false;
var result = await UserManager.CreateAsync(user, model.Password);
if (result.Succeeded)
{
System.Net.Mail.MailMessage m = new System.Net.Mail.MailMessage(
new System.Net.Mail.MailAddress("intervalle.technologies@gmail.com", "Gestion des utilisateur "),
new System.Net.Mail.MailAddress(user.Email));
m.Subject = "Comfirmation d'inscription";
m.Body = string.Format("Cher {0}<BR/>Merci pour votre inscription, veuillez cliquez sur le lien pour terminer votre inscription : <a href=\"{1}\" title=\"User Email Confirm\">{1}</a>", user.UserName, Url.Action("ConfirmEmail", "Account", new { Token = user.Id, Email = user.Email }, Request.Url.Scheme));
m.IsBodyHtml = true;
System.Net.Mail.SmtpClient smtp = new System.Net.Mail.SmtpClient("smtp.gmail.com");
smtp.Credentials = new System.Net.NetworkCredential("intervalle.technologies@gmail.com", "intervalletechnologies");
smtp.EnableSsl = true;
smtp.Send(m);
return RedirectToAction("Confirm", "Account", new { Email = user.Email });
}
else
{
AddErrors(result);
}
}
else
Response.Write("email existe deja");
}
// If we got this far, something failed, redisplay form
return View(model);
} |
Partager