public ActionResult Submit(Site site, ControllerContext controllerContext, SubmissionSetting submissionSetting) { object model = null; Exception exception = null; var formValues = new NameValueCollection(controllerContext.HttpContext.Request.Unvalidated().Form); try { var repository = site.GetRepository(); var valueProvider = new MvcValueProvider(controllerContext.Controller.ValueProvider); formValues = PluginHelper.ApplySubmissionSettings(submissionSetting, formValues, valueProvider); var folderName = formValues["FolderName"]; if (!string.IsNullOrEmpty(folderName)) { var folder = FolderHelper.Parse <TextFolder>(repository, folderName); model = DoPost(repository, folder, controllerContext, formValues); } } catch (Exception e) { exception = e; } return(PluginHelper.ReturnActionResult(controllerContext, model, exception)); }
public static NameValueCollection ApplySubmissionSettings(SubmissionSetting submissionSetting, NameValueCollection defaultValues, Kooboo.CMS.Common.Formula.IValueProvider valueProvider) { IFormulaParser formulaParser = Kooboo.CMS.Common.Runtime.EngineContext.Current.Resolve <IFormulaParser>(); if (submissionSetting.Settings != null) { foreach (var item in submissionSetting.Settings) { defaultValues[item.Key] = formulaParser.Populate(item.Value, valueProvider); } } return(defaultValues); }
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); }
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); }
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); }
protected virtual bool ContactSiteCore(ControllerContext controllerContext, SubmissionSetting submissionSetting, out string redirectUrl) { redirectUrl = ""; var ContactSiteModel = new ContactSiteModel(); bool valid = ModelBindHelper.BindModel(ContactSiteModel, "", controllerContext, submissionSetting); if (valid) { try { SendMail(controllerContext, Site.Current, ContactSiteModel, controllerContext.HttpContext.Request.Files); } 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); }
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); }
public System.Web.Mvc.ActionResult Submit(Site site, ControllerContext controllerContext, SubmissionSetting submissionSetting) { // Setup temp fields Site = site; ControllerContext = controllerContext; SubmissionSetting = submissionSetting; var model = new TModel(); if (!ModelBindHelper.BindModel <TModel>(model, "", ControllerContext, SubmissionSetting)) { var resultData = new JsonResultData(); resultData.Success = false; resultData.AddModelState(ControllerContext.Controller.ViewData.ModelState); ClearTempFields(); return(new JsonResult { Data = resultData }); } try { var result = Execute(model); string redirectUrl = null; if (result != null) { redirectUrl = result.RedirectUrl; } if (!String.IsNullOrEmpty(redirectUrl)) { return(RedirectTo(redirectUrl, result == null ? null : result.Data)); } else { return(new JsonResult { Data = new JsonResultData { Success = true, Model = result == null ? null : result.Data } }); } } catch (InvalidModelStateException ex) { var resultData = new JsonResultData(); resultData.Success = false; resultData.AddModelState(ex.ModelState); return(new JsonResult { Data = resultData }); } catch (Exception ex) { Kooboo.HealthMonitoring.Log.LogException(ex); var resultData = new JsonResultData(); resultData.Success = false; resultData.AddException(ex); return(new JsonResult { Data = resultData }); } finally { ClearTempFields(); } }
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); }
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); }
public static bool BindModel <T>(T model, string prefix, ControllerContext controllerContext, SubmissionSetting submissionSetting) { if (submissionSetting == null) { return(BindModel(model, prefix, controllerContext)); } else { var formValues = new NameValueCollection(controllerContext.HttpContext.Request.Form); var formulaValueProvider = new MvcValueProvider(controllerContext.Controller.ValueProvider); formValues = PluginHelper.ApplySubmissionSettings(submissionSetting, formValues, formulaValueProvider); ValueProviderCollection valueProvider = new ValueProviderCollection(); valueProvider.Add(new NameValueCollectionValueProvider(formValues, System.Globalization.CultureInfo.CurrentCulture)); valueProvider.Add(controllerContext.Controller.ValueProvider); IModelBinder binder = ModelBinders.Binders.GetBinder(typeof(T)); ModelBindingContext bindingContext = new ModelBindingContext { ModelMetadata = ModelMetadataProviders.Current.GetMetadataForType(() => model, typeof(T)), ModelName = prefix, ModelState = controllerContext.Controller.ViewData.ModelState, PropertyFilter = null, ValueProvider = valueProvider }; binder.BindModel(controllerContext, bindingContext); return(controllerContext.Controller.ViewData.ModelState.IsValid); } }