Ejemplo n.º 1
0
        public ActionResult Forgetpass(ForgetPassModel mode)
        {
            if (_captchaShow)
            {
                if (!mode.Captcha.ToLower().Equals(Session[ConstantKeys.CaptchaSession].ToString().ToLower()))
                {
                    return Json(new { Status = 0, Message = "Enter security code not correct!" });
                }
            }

            string emailFrom = AppSettings.Settings.SMTPAccount;
            string emailCc = ConfigurationManager.AppSettings["EmailCc"];
            string emailBcc = ConfigurationManager.AppSettings["EmailBcc"];
            string linkChangePass = ConfigurationManager.AppSettings["LinkChangePassword"];
            string siteUrl = AppSettings.Settings.SiteUrl.TrimEnd('/'); //ConfigurationManager.AppSettings["SiteUrl"].TrimEnd('/');

            Guid guid = Guid.NewGuid();
            var user = _userService.GetUserByEmail(mode.EmailTo);
            if (user != null)
            {
                string encyptToken = guid.ToString();//CryptorEngine.Encrypt(guid.ToString(), true);
                //string encyptEmail = CryptorEngine.Encrypt(mode.EmailTo, true);

                user.TokenForgotPassWord = encyptToken;
                _userService.Update(user);
                _unitOfWork.SaveChanges();

                // linkChangePass = string.Format(linkChangePass, siteUrl, encyptToken, encyptEmail);
                linkChangePass = string.Format(linkChangePass, siteUrl, encyptToken);

                var emailTemplateId = (int)EmailTemplateType.ForgetPass;
                var emaiTemplate = _emailTemplateService.GetEmailByID(emailTemplateId);

                var subject = emaiTemplate.Subject;
                string mailbody = emaiTemplate.Content;;
                mailbody = mailbody.Replace(ConstantKeys.UserName, user.UserName);
                mailbody = mailbody.Replace(ConstantKeys.ResetPasswordUrl, linkChangePass);
                mailbody = mailbody.Replace(ConstantKeys.SiteUrl, siteUrl);

                string ip = System.Web.HttpContext.Current.Request.UserHostAddress;

                var status = SendMailUtility.SendMailWithOutCC(subject, mailbody, mode.EmailTo, emailCc, emailBcc);

                var emailqueues = new EmailQueue();
                if (ModelState.IsValid)
                {
                    emailqueues.EmailFrom = emailFrom;
                    emailqueues.SendBy = user.UserId;
                    emailqueues.Active = status;
                    emailqueues.CreatedDate = DateTime.Now;
                    emailqueues.UpdatedDate = DateTime.Now;
                    emailqueues.EmailTo = mode.EmailTo;
                    emailqueues.EmailCc = emailCc;
                    emailqueues.EmailBcc = emailBcc;
                    emailqueues.EmailSubject = subject;
                    emailqueues.SenderIP = ip;
                    emailqueues.DisplayNameFrom = user.UserName;

                    _emailQueueService.Insert(emailqueues);
                    _unitOfWork.SaveChanges();
                }

            }
            else
            {
                return Json(new { Status = 0, Message = "Email not exist!" });
            }
            return Json(new { Status = 1, Message = "Please, check your email." });
        }
Ejemplo n.º 2
0
 public ActionResult Forgetpass()
 {
     var model = new ForgetPassModel();
     model.CaptchaShow = _captchaShow;
     if (!_captchaShow)
     {
         model.Captcha = "captcha";
     }
     return View(model);
 }