Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- // POST: /Account/ForgotPassword
- [HttpPost]
- [AllowAnonymous]
- [ValidateAntiForgeryToken]
- public async Task<ActionResult> ForgotPassword(ForgotPasswordViewModel model)
- {
- if (ModelState.IsValid)
- {
- var user = await UserManager.FindByNameAsync(model.Email);
- // if (user == null || !(await UserManager.IsEmailConfirmedAsync(user.Id)))
- if( user == null )
- {
- ModelState.AddModelError("","El correo es invalido");
- // Don't reveal that the user does not exist or is not confirmed
- return View("ForgotPasswordConfirmation");
- }
- // For more information on how to enable account confirmation and password reset please visit https://go.microsoft.com/fwlink/?LinkID=320771
- // Send an email with this link
- string code = await UserManager.GeneratePasswordResetTokenAsync(user.Id);
- var callbackUrl = Url.Action("ResetPassword", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme);
- await UserManager.SendEmailAsync(user.Id, "Reset Password", "Please reset your password by clicking <a href="" + callbackUrl + "">here</a>");
- return RedirectToAction("ForgotPasswordConfirmation", "Account");
- }
- // If we got this far, something failed, redisplay form
- return View(model);
- }
- public class EmailService : IIdentityMessageService
- {
- public Task SendAsync(IdentityMessage message)
- {
- // Credentials:
- var envia = "correo@hotmail.com";
- var user = "correo@hotmail.com";
- var pass = "contraseña";
- System.Net.NetworkCredential credentials = new System.Net.NetworkCredential( user, pass );
- SmtpClient client = new SmtpClient()
- {
- Host = "smtp.live.com",
- DeliveryMethod = SmtpDeliveryMethod.Network,
- UseDefaultCredentials = false,
- Port = 25,
- EnableSsl = true,
- Credentials = credentials
- };
- var mail = new MailMessage(envia, message.Destination);
- mail.Subject = message.Subject;
- mail.Body = message.Body;
- mail.IsBodyHtml = true;
- return client.SendMailAsync(mail);
- }
- }
Add Comment
Please, Sign In to add comment