コード例 #1
0
        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
        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;
        }