Exemplo n.º 1
0
        protected virtual bool ForgotPasswordCore(ControllerContext controllerContext, SubmissionSetting submissionSetting, out string redirectUrl)
        {
            redirectUrl = "";
            var membership = MemberPluginHelper.GetMembership();

            var forgotPasswordModel = new ForgotPasswordModel();

            bool valid = ModelBindHelper.BindModel(forgotPasswordModel, "", controllerContext, submissionSetting);

            if (valid)
            {
                redirectUrl = forgotPasswordModel.RedirectUrl;
                if (!string.IsNullOrEmpty(redirectUrl))
                {
                    redirectUrl = MemberPluginHelper.ResolveSiteUrl(controllerContext, redirectUrl);
                }
                try
                {
                    var membershipUser = _manager.ForgotPassword(membership, forgotPasswordModel.UserName);

                    SendMail(controllerContext, Site.Current, membershipUser, forgotPasswordModel);
                }
                catch (DataViolationException e)
                {
                    controllerContext.Controller.ViewData.ModelState.FillDataViolation(e.Violations);
                    valid = false;
                }
                catch (Exception e)
                {
                    controllerContext.Controller.ViewData.ModelState.AddModelError("", e.Message);
                    Kooboo.HealthMonitoring.Log.LogException(e);
                    valid = false;
                }
            }
            return(valid);
        }
Exemplo n.º 2
0
        protected virtual void SendMail(ControllerContext controllerContext, Site site, MembershipUser membershipUser, ForgotPasswordModel forgotPasswordModel)
        {
            var resetPasswordUrl = forgotPasswordModel.ResetPasswordUrl;
            if (string.IsNullOrEmpty(resetPasswordUrl))
            {
                throw new ArgumentNullException("ResetPasswordUrl is required.");
            }

            resetPasswordUrl = string.Format(MemberPluginHelper.ResolveSiteUrl(controllerContext, resetPasswordUrl)
                , forgotPasswordModel.UserName, membershipUser.ActivateCode);
            resetPasswordUrl = UrlUtility.ToHttpAbsolute(resetPasswordUrl);

            var subject = forgotPasswordModel.EmailSubject;
            var body = string.Format(forgotPasswordModel.EmailBody, membershipUser.UserName, resetPasswordUrl);

            site.SendMailToCustomer(membershipUser.Email, subject, body, true, null);
        }
Exemplo n.º 3
0
        protected virtual bool ForgotPasswordCore(ControllerContext controllerContext, SubmissionSetting submissionSetting, out string redirectUrl)
        {
            redirectUrl = "";
            var membership = MemberPluginHelper.GetMembership();

            var forgotPasswordModel = new ForgotPasswordModel();

            bool valid = ModelBindHelper.BindModel(forgotPasswordModel, "", controllerContext, submissionSetting);

            if (valid)
            {
                redirectUrl = forgotPasswordModel.RedirectUrl;
                if (!string.IsNullOrEmpty(redirectUrl))
                {
                    redirectUrl = MemberPluginHelper.ResolveSiteUrl(controllerContext, redirectUrl);
                }
                try
                {
                    var membershipUser = _manager.ForgotPassword(membership, forgotPasswordModel.UserName);

                    SendMail(controllerContext, Site.Current, membershipUser, forgotPasswordModel);

                }
                catch (DataViolationException e)
                {
                    controllerContext.Controller.ViewData.ModelState.FillDataViolation(e.Violations);
                    valid = false;
                }
                catch (Exception e)
                {
                    controllerContext.Controller.ViewData.ModelState.AddModelError("", e.Message);
                    Kooboo.HealthMonitoring.Log.LogException(e);
                    valid = false;
                }
            }
            return valid;
        }
Exemplo n.º 4
0
        protected virtual void SendMail(ControllerContext controllerContext, Site site, MembershipUser membershipUser, ForgotPasswordModel forgotPasswordModel)
        {
            var resetPasswordUrl = forgotPasswordModel.ResetPasswordUrl;

            if (string.IsNullOrEmpty(resetPasswordUrl))
            {
                throw new ArgumentNullException("ResetPasswordUrl is required.");
            }

            resetPasswordUrl = string.Format(MemberPluginHelper.ResolveSiteUrl(controllerContext, resetPasswordUrl)
                                             , forgotPasswordModel.UserName, membershipUser.ActivateCode);
            resetPasswordUrl = UrlUtility.ToHttpAbsolute(resetPasswordUrl);

            var subject = forgotPasswordModel.EmailSubject;
            var body    = string.Format(forgotPasswordModel.EmailBody, resetPasswordUrl);

            site.SendMailToCustomer(membershipUser.Email, subject, body, true, null);
        }