Exemplo n.º 1
0
        public async Task<ActionResult> ForgotPassword(ForgotPasswordViewModelMyOwn model)
        {
            if (ModelState.IsValid)
            {
                var user = await UserManager.FindByNameAsync(model.UserName);
                if (user == null || !(await UserManager.IsEmailConfirmedAsync(user.Id)))
                {
                    // 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 http://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);
        }
Exemplo n.º 2
-1
        public ActionResult ForgotPassword(ForgotPasswordViewModelMyOwn model)
        {
            if (ModelState.IsValid)
            {
                ResetPassword RP = new ResetPassword();
                UserModel UM = new UserModel();
                UserManagerFK UMF = new UserManagerFK();
                string email = UMF.GetUserEmail(model.UserName);

                if (email == null)
                {

                    return View("ForgotPasswordConfirmation");
                }

                Guid EMailCode = Guid.NewGuid();
                var callbackUrl = Url.Action("ResetPassword", "UserAccount", new { userId = email, code = EMailCode }, protocol: Request.Url.Scheme);

                UMF.AddResetPasswordDetails(EMailCode, email, "Y");

                //SmtpClient SmtpClient = new SmtpClient("smtp.gmail.com");
                //MailAddressCollection MailAddressCollection = new MailAddressCollection();
                //MailMessage message = new MailMessage();
                //message.From = new MailAddress("*****@*****.**", "Faheem Kathrada");
                //message.Body = "Please reset your password by clicking < a href =\"" + callbackUrl + "\">here</a>";
                //message.Subject = "Nexidia Log Files";
                //message.To.Add("*****@*****.**");

                //SmtpClient.Port = 587;
                //SmtpClient.EnableSsl = true;
                //SmtpClient.Send(message);
                //message.Dispose();

                var client = new SmtpClient("smtp.gmail.com", 587)
                {
                    Credentials = new NetworkCredential("*****@*****.**", "8September@008"),
                    EnableSsl = true
                };
                client.Send("*****@*****.**", "*****@*****.**", "Password Reset", "Please reset your password by clicking < a href =\"" + callbackUrl + "\">here</a>");

                return RedirectToAction("ForgotPasswordConfirmation", "Account");
            }

            return View(model);
        }