protected virtual bool ChangePasswordCore(ControllerContext controllerContext, SubmissionSetting submissionSetting = null)
        {
            var memberAuth = controllerContext.HttpContext.Membership();

            if (memberAuth.GetMember().Identity.IsAuthenticated == false)
            {
                throw new HttpException((int)System.Net.HttpStatusCode.Unauthorized, "");
            }

            var membership = MemberPluginHelper.GetMembership();

            var  model = new ChangeMemberPasswordModel();
            bool valid = ModelBindHelper.BindModel(model, "", controllerContext, submissionSetting);

            if (valid)
            {
                valid = _manager.Validate(membership, memberAuth.GetMember().Identity.Name, model.OldPassword);
                if (valid)
                {
                    _manager.ChangePassword(membership, memberAuth.GetMember().Identity.Name, model.NewPassword);
                    valid = true;
                }
                else
                {
                    valid = false;
                    controllerContext.Controller.ViewData.ModelState.AddModelError("OldPassword", "The old password is incorrect.".RawLabel().ToString());
                }
            }
            return(valid);
        }
예제 #2
0
        public System.Web.Mvc.ActionResult Submit(Models.Site site, System.Web.Mvc.ControllerContext controllerContext, Models.SubmissionSetting submissionSetting)
        {
            SingOutCore(controllerContext);
            var redirectUrl = MemberPluginHelper.GetReturnUrl(controllerContext);

            if (string.IsNullOrEmpty(redirectUrl))
            {
                redirectUrl = controllerContext.HttpContext.Request.UrlReferrer.ToString();
            }

            if (controllerContext.HttpContext.Request.IsAjaxRequest())
            {
                JsonResultData resultData = new JsonResultData();

                resultData.RedirectUrl = redirectUrl;
                resultData.Success     = true;

                return(new JsonResult()
                {
                    Data = resultData, JsonRequestBehavior = JsonRequestBehavior.AllowGet
                });
            }
            else
            {
                return(new RedirectResult(redirectUrl));
            }
        }
예제 #3
0
        public System.Web.Mvc.ActionResult HttpPost(View.Page_Context context, View.PagePositionContext positionContext)
        {
            SingOutCore(context.ControllerContext);

            var redirectUrl = MemberPluginHelper.GetReturnUrl(context.ControllerContext);

            if (string.IsNullOrEmpty(redirectUrl))
            {
                redirectUrl = context.ControllerContext.HttpContext.Request.UrlReferrer.ToString();
            }
            return(new RedirectResult(redirectUrl));
        }
        public System.Web.Mvc.ActionResult HttpPost(View.Page_Context context, View.PagePositionContext positionContext)
        {
            System.Web.Helpers.AntiForgery.Validate();

            var isValid     = ChangePasswordCore(context.ControllerContext);
            var redirectUrl = MemberPluginHelper.GetReturnUrl(context.ControllerContext);

            if (isValid && !string.IsNullOrEmpty(redirectUrl))
            {
                return(new RedirectResult(redirectUrl));
            }
            context.ControllerContext.Controller.ViewBag.MembershipSuccess = isValid;
            return(null);
        }
예제 #5
0
        protected virtual bool EditCore(ControllerContext controllerContext, SubmissionSetting submissionSetting, out string redirectUrl)
        {
            redirectUrl = "";

            var memberAuth = controllerContext.HttpContext.Membership();

            if (memberAuth.GetMember().Identity.IsAuthenticated == false)
            {
                throw new HttpException((int)System.Net.HttpStatusCode.Unauthorized, "");
            }
            var membership = MemberPluginHelper.GetMembership();

            var membershipUser = controllerContext.HttpContext.Membership().GetMembershipUser();

            var editMemberModel = new EditMemberProfileModel();

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

            if (valid)
            {
                redirectUrl = editMemberModel.RedirectUrl;
                if (!string.IsNullOrEmpty(redirectUrl))
                {
                    redirectUrl = MemberPluginHelper.ResolveSiteUrl(controllerContext, redirectUrl);
                }

                try
                {
                    _manager.EditMemberProfile(membership, memberAuth.GetMember().Identity.Name, editMemberModel.Email, editMemberModel.Culture,
                                               editMemberModel.TimeZoneId, editMemberModel.PasswordQuestion, editMemberModel.PasswordAnswer, editMemberModel.Profiles);
                    valid = true;
                }
                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);
        }
예제 #6
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);
        }
예제 #7
0
        protected virtual void SendActivateMail(ControllerContext controllerContext, Site site, MembershipUser memberUser, RegisterMemberModel registerMemberModel, string activateCode)
        {
            var activateUrl = registerMemberModel.ActivateUrl;

            if (string.IsNullOrEmpty(activateUrl))
            {
                throw new ArgumentNullException("ActivateUrl is required.");
            }

            activateUrl = string.Format(MemberPluginHelper.ResolveSiteUrl(controllerContext, activateUrl)
                                        , memberUser.UserName, activateCode);
            activateUrl = UrlUtility.ToHttpAbsolute(activateUrl);

            var subject = registerMemberModel.EmailSubject;
            var body    = string.Format(registerMemberModel.EmailBody, activateUrl);

            site.SendMailToCustomer(registerMemberModel.Email, subject, body, true, null);
        }
예제 #8
0
        protected virtual bool LoginCore(ControllerContext controllerContext, SubmissionSetting submissionSetting, out ValidateMemberModel model)
        {
            var membership = MemberPluginHelper.GetMembership();

            model = new ValidateMemberModel();
            bool valid = ModelBindHelper.BindModel(model, "", controllerContext, submissionSetting);

            if (valid)
            {
                try
                {
                    valid = _manager.Validate(membership, model.UserName, model.Password);
                    if (valid)
                    {
                        controllerContext.HttpContext.Membership().SetAuthCookie(model.UserName, model.RememberMe == null ? false : model.RememberMe.Value);

                        if (!string.IsNullOrEmpty(model.RedirectUrl))
                        {
                            model.RedirectUrl = MemberPluginHelper.ResolveSiteUrl(controllerContext, model.RedirectUrl);
                        }
                        if (!string.IsNullOrEmpty(MemberPluginHelper.GetReturnUrl(controllerContext)))
                        {
                            model.RedirectUrl = MemberPluginHelper.GetReturnUrl(controllerContext);
                        }
                    }
                    else
                    {
                        controllerContext.Controller.ViewData.ModelState.AddModelError("UserName", "Username and/or password are incorrect.".RawLabel().ToString());
                    }
                }
                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);
        }
        public System.Web.Mvc.ActionResult Submit(Models.Site site, System.Web.Mvc.ControllerContext controllerContext, Models.SubmissionSetting submissionSetting)
        {
            JsonResultData resultData = new JsonResultData();

            if (!ChangePasswordCore(controllerContext, submissionSetting))
            {
                resultData.AddModelState(controllerContext.Controller.ViewData.ModelState);
                resultData.Success = false;
            }
            else
            {
                resultData.RedirectUrl = MemberPluginHelper.GetReturnUrl(controllerContext);
                resultData.Success     = true;
            }
            return(new JsonResult()
            {
                Data = resultData
            });
        }
예제 #10
0
        protected virtual bool RegisterCore(ControllerContext controllerContext, SubmissionSetting submissionSetting, out string redirectUrl)
        {
            redirectUrl = "";
            var membership = MemberPluginHelper.GetMembership();

            var registerMemberModel = new RegisterMemberModel();

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

            if (valid)
            {
                redirectUrl = registerMemberModel.RedirectUrl;
                if (!string.IsNullOrEmpty(redirectUrl))
                {
                    redirectUrl = MemberPluginHelper.ResolveSiteUrl(controllerContext, redirectUrl);
                }
                try
                {
                    var membershipUser = _manager.Create(membership, registerMemberModel.UserName, registerMemberModel.Email, registerMemberModel.Password, registerMemberModel.IsApproved, registerMemberModel.Culture
                                                         , registerMemberModel.TimeZoneId, registerMemberModel.PasswordQuestion, registerMemberModel.PasswordAnswer, null, registerMemberModel.Profiles, null);

                    if (registerMemberModel.IsApproved == false)
                    {
                        SendActivateMail(controllerContext, Site.Current, membershipUser, registerMemberModel, membershipUser.ActivateCode);
                    }
                }
                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);
        }
예제 #11
0
        protected virtual bool ActivateCore(ControllerContext controllerContext, SubmissionSetting submissionSetting, out string redirectUrl)
        {
            redirectUrl = "";

            var membership = MemberPluginHelper.GetMembership();

            var  model = new ActivateMemberModel();
            bool valid = ModelBindHelper.BindModel(model, "", controllerContext, submissionSetting);

            if (valid)
            {
                try
                {
                    valid = _manager.Activate(membership, model.Member, model.Code);
                    if (valid)
                    {
                        redirectUrl = MemberPluginHelper.ResolveSiteUrl(controllerContext, model.SuccessUrl);
                    }
                    else
                    {
                        redirectUrl = MemberPluginHelper.ResolveSiteUrl(controllerContext, model.FailedUrl);
                    }
                }
                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);
        }
예제 #12
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);
        }