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);
        }
Exemplo n.º 2
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);
        }
Exemplo n.º 3
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);
        }
Exemplo n.º 4
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);
        }
Exemplo n.º 5
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);
        }
Exemplo n.º 6
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);
        }