public ActionResult Unsubscribe(UnsubscribeFormViewModel viewModel) { if (!AntiCsrfHelpers.IsValidCsrfToken(this.Request?.Form)) { return(new EmptyResult()); } if (this.ModelState.IsValid && this.Model.ListId != Guid.Empty) { string error; bool isSucceeded = this.Model.Unsubscribe(viewModel, out error); this.ViewBag.Error = error; this.ViewBag.IsSucceded = isSucceeded; if (isSucceeded) { var redirectUrl = viewModel.RedirectPageUrl; var validator = ObjectFactory.Resolve <IRedirectUriValidator>(); if (this.Model.SuccessfullySubmittedForm == SuccessfullySubmittedForm.OpenSpecificPage && !string.IsNullOrEmpty(redirectUrl) && validator.IsValid(redirectUrl)) { return(this.Redirect(redirectUrl)); } this.ModelState.Clear(); } } viewModel = this.Model.CreateViewModel(); var fullTemplateName = this.emailAddressTemplateNamePrefix + this.EmailAddressTemplateName; return(this.View(fullTemplateName, viewModel)); }
public ActionResult Index(RegistrationViewModel viewModel) { if (!AntiCsrfHelpers.IsValidCsrfToken(this.Request?.Form)) { return(new EmptyResult()); } return(RegisterUser(viewModel)); }
public ActionResult Index(FormCollection collection) { if (!AntiCsrfHelpers.IsValidCsrfToken(collection)) { return(new EmptyResult()); } if (!this.ViewData.ContainsKey(FormController.ShouldProcessRequestKey) || (bool)this.ViewData[FormController.ShouldProcessRequestKey]) { var success = this.Model.TrySubmitForm(collection, this.Request != null ? this.Request.Files : null, this.Request != null ? this.Request.UserHostAddress : null); if (success == SubmitStatus.Success && this.Model.NeedsRedirect) { if (this.Model.RaiseBeforeFormActionEvent()) { return(this.Redirect(this.Model.GetRedirectPageUrl())); } else { return(this.Index()); } } if (this.Model.RaiseBeforeFormActionEvent()) { var resultMessage = this.Model.GetSubmitMessage(success); this.ViewBag.SubmitMessage = resultMessage; if (success == SubmitStatus.Success) { var viewTemplatePath = FormController.TemplateNamePrefix + FormController.SubmitResultTemplateName; return(this.View(viewTemplatePath)); } else { this.ViewBag.ErrorMessage = resultMessage; this.Model.FormCollection = collection; return(this.Index()); } } else { return(this.Index()); } } else { return(this.Index()); } }
public JsonResult AjaxSubmit(FormCollection collection) { if (collection == null) { throw new ArgumentNullException("collection"); } if (!AntiCsrfHelpers.IsValidCsrfToken(collection)) { return(this.Json(new { success = false, error = "Invalid anti CSRF token" })); } var widgetIdIdString = collection[WidgetId]; Guid widgetId; if (string.IsNullOrWhiteSpace(widgetIdIdString) || !Guid.TryParse(widgetIdIdString, out widgetId)) { widgetId = Guid.Empty; } var formModel = ControllerHelper.LoadControllerModel(widgetId, Telerik.Sitefinity.Services.SystemManager.CurrentContext.Culture) as IFormModel; formModel = formModel ?? this.Model; var result = formModel.TrySubmitForm(collection, this.Request.Files, this.Request.UserHostAddress); if (result != SubmitStatus.Success && formModel.RaiseBeforeFormActionEvent()) { return(this.Json(new { success = false, error = formModel.GetSubmitMessage(result) })); } else { var redirectPageUrl = string.Empty; if (formModel.NeedsRedirect) { redirectPageUrl = formModel.GetRedirectPageUrl(); } if (string.IsNullOrWhiteSpace(redirectPageUrl)) { return(this.Json(new { success = true, message = formModel.GetSubmitMessage(result) })); } else { return(this.Json(new { success = true, redirectUrl = redirectPageUrl })); } } }
public ActionResult Index(LoginFormViewModel model) { if (!AntiCsrfHelpers.IsValidCsrfToken(this.Request?.Form)) { return(new EmptyResult()); } if (ModelState.IsValid) { model = this.Model.Authenticate(model, this.ControllerContext.HttpContext); } this.Model.InitializeLoginViewModel(model); var fullTemplateName = this.loginFormTemplatePrefix + this.LoginFormTemplate; return(this.View(fullTemplateName, model)); }
public ActionResult Subscribe(SubscribeFormViewModel viewModel) { if (!AntiCsrfHelpers.IsValidCsrfToken(this.Request?.Form)) { return(new EmptyResult()); } if (!this.IsLicensed) { return(this.Content(this.LicensingMessage)); } if (ModelState.IsValid) { string error; bool isSucceeded = this.Model.AddSubscriber(viewModel, out error); this.ViewBag.Error = error; this.ViewBag.IsSucceeded = isSucceeded; this.ViewBag.Email = AntiXssEncoder.HtmlEncode(viewModel.Email, false); if (isSucceeded) { var validator = ObjectFactory.Resolve <IRedirectUriValidator>(); var redirectUrl = viewModel.RedirectPageUrl; if (this.Model.SuccessfullySubmittedForm == SuccessfullySubmittedForm.OpenSpecificPage && !string.IsNullOrEmpty(redirectUrl) && validator.IsValid(redirectUrl)) { return(this.Redirect(redirectUrl)); } this.ModelState.Clear(); } } var fullTemplateName = this.templateNamePrefix + this.TemplateName; viewModel = this.Model.CreateViewModel(); return(this.View(fullTemplateName, viewModel)); }
public ActionResult Index(ProfileEditViewModel viewModel) { if (!AntiCsrfHelpers.IsValidCsrfToken(this.Request?.Form)) { return(new EmptyResult()); } this.Model.ValidateProfileData(viewModel, this.ModelState); this.Model.InitializeUserRelatedData(viewModel, false); if (ModelState.IsValid) { try { var isUpdated = this.Model.EditUserProfile(viewModel); if (!isUpdated) { return(this.Content(Res.Get <ProfileResources>().EditNotAllowed)); } if (this.Model.IsEmailChanged(viewModel)) { return(this.View(ConfirmPasswordModeTemplatePrefix + this.EditModeTemplateName, new ProfileEmailEditViewModel() { UserId = viewModel.User.Id, Email = viewModel.Email })); } switch (this.Model.SaveChangesAction) { case SaveAction.SwitchToReadMode: return(this.ReadProfile()); case SaveAction.ShowMessage: viewModel.ShowProfileChangedMsg = true; break; case SaveAction.ShowPage: return(this.Redirect(this.Model.GetPageUrl(this.Model.ProfileSavedPageId))); } } catch (ProviderException ex) { this.ViewBag.ErrorMessage = ex.Message; } catch (DuplicateKeyException) { this.ViewBag.ErrorMessage = Res.Get <ProfileResources>().EmailExistsMessage; } catch (Exception) { this.ViewBag.ErrorMessage = Res.Get <ProfileResources>().ChangePasswordGeneralErrorMessage; } } this.ViewBag.HasPasswordErrors = !this.ModelState.IsValidField("OldPassword") || !this.ModelState.IsValidField("NewPassword") || !this.ModelState.IsValidField("RepeatPassword") || !string.IsNullOrEmpty(this.ViewBag.ErrorMessage); this.SetReadOnlyInfo(viewModel); var fullTemplateName = ProfileController.EditModeTemplatePrefix + this.EditModeTemplateName; return(this.View(fullTemplateName, viewModel)); }