Beispiel #1
0
        public ActionResult ForgotPassword(string Email)
        {
            Login_tbl Login_tbl = _loginService.ForgotPassword(Email);

            if (Login_tbl != null)
            {
                var EmailInfo = _loginService.AddEmailInfo(Login_tbl.ID);
                var smtp      = new SmtpClient
                {
                    Host                  = ConfigurationManager.AppSettings["Host"],
                    Port                  = Convert.ToInt32(ConfigurationManager.AppSettings["Port"]),
                    EnableSsl             = true,
                    DeliveryMethod        = SmtpDeliveryMethod.Network,
                    UseDefaultCredentials = false,
                    Credentials           = new NetworkCredential(ConfigurationManager.AppSettings["AdminId"], ConfigurationManager.AppSettings["AdminPassword"])
                };
                using (var message = new MailMessage(new MailAddress(ConfigurationManager.AppSettings["AdminId"], "Admin"), new MailAddress(Email, "user"))
                {
                    Subject = "Reset Password",
                    Body = "Hello " + Login_tbl.FirstName + ",<br/><br/>Welcome to Online Training Portal. We received a request to reset your password.Please <a href=" + ConfigurationManager.AppSettings["ChangePasswordUrl"] + "/" + UrlSecurityManager.Encrypt(EmailInfo.ID.ToString(), ConfigurationManager.AppSettings["SecurityKey"]) + ">Click Here</a> to reset Password<br/><br/>This link is only valid for 30 minutes. <br/><br/><br/>Regards,<br/>Admin"
                })
                {
                    message.IsBodyHtml = true;
                    smtp.Send(message);
                }
                TempData["Success"] = "True";
                TempData["Message"] = "please check your email to change password";
                return(RedirectToAction("Login"));
            }
            else
            {
                TempData["Success"] = "False";
                TempData["Message"] = "Email does not exist.Please contact Admin for registration";
                return(RedirectToAction("Login"));
            }
        }