Ejemplo n.º 1
0
        public ActionResult ForgetPasswordRequest(Models.ForgotPasswordRequestModel model)
        {
            if (ModelState.IsValid)
            {
                BLL.UserProfile profile = _userProfileService.GetUser(model.UserName);
                if (profile != null && !profile.LockedInInd)
                {
                    BLL.ForgetPasswordRequest req = new BLL.ForgetPasswordRequest()
                    {
                        Completed = false,
                        ExpieryDate = DateTime.Now.AddMonths(2),
                        GeneratedDate = DateTime.Now,
                        RequestKey = MD5Hashing.MD5Hash(Guid.NewGuid().ToString()),
                        UserProfileID = profile.UserProfileID
                    };
                    if (_forgetPasswordRequestService.AddForgetPasswordRequest(req))
                    {

                        string to = profile.Email;
                        string subject = "Password Change Request";
                        string link = Request.Url.Host + "/Account/ForgetPassword/?key=" + req.RequestKey;
                        string body = string.Format(@"Dear {1}
                                                            <br /><br />
                                                        A password reset request has been submitted for your DRMFSS - CTS account. If you submitted this password reset request, please follow the following link.
                                                        <br /><br />
                                                        <a href='{0}'>Please Follow this Link</a> <br />
                                                        <br /><br />
                                                        Please ignore this message if the password request was not submitted by you. This request will expire in 24 hours.
                                                        <br /><br />
                                                       Thank you,<br />
                                                       Administrator.
                                                        ", link, profile.GetFullName());

                        try
                        {
                            // Read the configuration table for smtp settings.

                           string from = _settingService.GetSettingValue("SMTP_EMAIL_FROM");
                           string smtp = _settingService.GetSettingValue("SMTP_ADDRESS");
                           int port = Convert.ToInt32(_settingService.GetSettingValue("SMTP_PORT"));
                           string userName =_settingService.GetSettingValue("SMTP_USER_NAME");
                           string password = _settingService.GetSettingValue("SMTP_PASSWORD");
                            // send the email using the utilty method in the shared dll.
                           Shared.SendMail mail = new Shared.SendMail(from, to, subject, body, null, true, smtp,userName,password, port);
                           return RedirectToAction("ConfirmPasswordChange");
                        }
                        catch (Exception e)
                        {
                            ViewBag.ErrorMessage = "The user name or email address you provided is not correct. Please try again.";
                        }
                    }
                    else
                    {
                        ViewBag.ErrorMessage = "The user name or email address you provided is not correct. Please try again.";
                    }

                }
                else
                {
                    ViewBag.ErrorMessage = "The user name or email address you provided is not correct. Please try again.";
                }
            }
            return View("ForgetPasswordRequest", model);
        }
Ejemplo n.º 2
0
        public ActionResult ForgetPasswordRequest(Models.ForgotPasswordRequestModel model)
        {
            if (ModelState.IsValid)
            {
                BLL.UserProfile profile = _userProfileService.GetUser(model.UserName);
                if (profile != null && !profile.LockedInInd)
                {
                    BLL.ForgetPasswordRequest req = new BLL.ForgetPasswordRequest()
                    {
                        Completed     = false,
                        ExpieryDate   = DateTime.Now.AddMonths(2),
                        GeneratedDate = DateTime.Now,
                        RequestKey    = MD5Hashing.MD5Hash(Guid.NewGuid().ToString()),
                        UserProfileID = profile.UserProfileID
                    };
                    if (_forgetPasswordRequestService.AddForgetPasswordRequest(req))
                    {
                        string to      = profile.Email;
                        string subject = "Password Change Request";
                        string link    = Request.Url.Host + "/Account/ForgetPassword/?key=" + req.RequestKey;
                        string body    = string.Format(@"Dear {1}
                                                            <br /><br />
                                                        A password reset request has been submitted for your DRMFSS - CTS account. If you submitted this password reset request, please follow the following link. 
                                                        <br /><br />
                                                        <a href='{0}'>Please Follow this Link</a> <br />
                                                        <br /><br />
                                                        Please ignore this message if the password request was not submitted by you. This request will expire in 24 hours.
                                                        <br /><br />
                                                       Thank you,<br />
                                                       Administrator.
                                                        ", link, profile.GetFullName());

                        try
                        {
                            // Read the configuration table for smtp settings.

                            string from     = _settingService.GetSettingValue("SMTP_EMAIL_FROM");
                            string smtp     = _settingService.GetSettingValue("SMTP_ADDRESS");
                            int    port     = Convert.ToInt32(_settingService.GetSettingValue("SMTP_PORT"));
                            string userName = _settingService.GetSettingValue("SMTP_USER_NAME");
                            string password = _settingService.GetSettingValue("SMTP_PASSWORD");
                            // send the email using the utilty method in the shared dll.
                            Shared.SendMail mail = new Shared.SendMail(from, to, subject, body, null, true, smtp, userName, password, port);
                            return(RedirectToAction("ConfirmPasswordChange"));
                        }
                        catch (Exception e)
                        {
                            ViewBag.ErrorMessage = "The user name or email address you provided is not correct. Please try again.";
                        }
                    }
                    else
                    {
                        ViewBag.ErrorMessage = "The user name or email address you provided is not correct. Please try again.";
                    }
                }
                else
                {
                    ViewBag.ErrorMessage = "The user name or email address you provided is not correct. Please try again.";
                }
            }
            return(View("ForgetPasswordRequest", model));
        }