示例#1
0
        public ActionResult ForgotPassword(string email)
        {
            var user = HttpContext.Session.Get <UserViewModel>(Constants.SessionKeyUserInfo);//for loggging

            try
            {
                var emailID = authHandler.ForgetPassword(email);
                /* Mail Send */
                string emailEncr = EncryptDecrypt.Encrypt(emailID, "sblw-3hn8-sqoy19");
                var    basePath  = string.Format("{0}://{1}", Request.Scheme /*URLprotocol*/, Request.Host);
                var    link      = basePath + "/Auth/ResetPassword/?id=" + emailEncr;

                var eModel = new EmailViewModel
                {
                    Subject = "Reset Password",
                    Body    = "Dear Sir/Madam,<br/>You initiated a request to help with your account password. Click the link below to set a new password for CareerIndeed portal" +
                              "<br/><a href=" + link + ">Reset Password link</a><br><br>" + "Thank You<br>CareerIndeed Team",
                    To       = new string[] { emailID },
                    From     = config["EmailCredential:Fromemail"],
                    IsHtml   = true,
                    MailType = (int)MailType.ForgotPassword
                };
                emailHandler.SendMail(eModel, -1);

                //SendVerificationLinkEmail(emailID, "ResetPassword");
                ViewData["SuccessMessage"] = "Password Reset link send to your Email";
            }
            catch (UserNotFoundException ex)
            {
                Logger.Logger.WriteLog(Logger.Logtype.Error, ex.Message, 0, typeof(AuthController), ex);
                ModelState.AddModelError("ErrorMessage", string.Format("{0}", ex.Message));
                ViewData["SuccessMessage"] = ex.Message;
            }
            catch (DataNotFound ex)
            {
                Logger.Logger.WriteLog(Logger.Logtype.Error, ex.Message, 0, typeof(AuthController), ex);
                ModelState.AddModelError("ErrorMessage", string.Format("{0}", ex.Message));
                ViewData["SuccessMessage"] = ex.Message;
            }
            catch (Exception ex)
            {
                Logger.Logger.WriteLog(Logger.Logtype.Error, ex.Message, 0, typeof(AuthController), ex);
                ModelState.AddModelError("ErrorMessage", string.Format("{0}", ex.Message));
                ViewData["SuccessMessage"] = "Error Occured,Please contact at [email protected]";
            }
            return(View());
        }