public BsJsonResult ReturnDraft(DraftVm draft) { Article model = null; CustomUrl customUrl = null; if (ModelState.IsValid) { var article = _articleService.GetById(draft.Id); model = Mapper.Map(draft, article); model.ArticleState = ArticleState.ReturnedDraft; customUrl = CreateOrUpdateCustomUrl(draft); } if (!ModelState.IsValid) { ModelState.AddFormError("Ошибка: ", "Поля заполнены не верно. Черновик не был сохранен и не может быть возвращен."); return(new BsJsonResult( new Dictionary <string, object> { { "Errors", ModelState.GetErrors() } }, BsResponseStatus.ValidationError)); } _articleService.Update(model); if (customUrl != null) { _customUrlService.CreateOrUpdate(customUrl); } return(new BsJsonResult(new { Status = BsResponseStatus.Success })); }
public ActionResult Login(LoginViewModel loginModel) { if (ModelState.IsValid) { if (Membership.ValidateUser(loginModel.CNP, loginModel.Password)) { var userData = new UserData(HesiraDB, loginModel.CNP); if (HttpContext.Session != null) { HttpContext.Session["UserData"] = userData; } FormsAuthentication.SetAuthCookie(loginModel.CNP, true); if (LocalAndSafeUrl(loginModel.ReturnUrl)) { return(Redirect(loginModel.ReturnUrl)); } return(RedirectToAction("Index", "Home")); } var message = Resource.SignInFailed; // login message - provider validation method if (System.Web.HttpContext.Current.Items["LoginMessage"] != null && !string.IsNullOrEmpty(System.Web.HttpContext.Current.Items["LoginMessage"].ToString())) { message = (System.Web.HttpContext.Current.Items["LoginMessage"]).ToString(); } ModelState.AddFormError("", message); } return(View(loginModel)); }
public ActionResult Index(AuthenticationModel model, string mode) { //add global validation error ModelState.AddFormError("LoginModel", "<strong>This account has been suspended!</strong> <a href=\"#\" class=\"alert-link\">Contact us</a> for more details."); return(View(model)); }
public BsJsonResult SaveZItem(ZDevVm zItem) { const string imagesPath = "~/Content/Uploads/ZDev/"; string errorText = null; ZDev model = null; var validImageTypes = new string[] { "image/gif", "image/jpeg", "image/pjpeg", "image/png" }; if (zItem.ImageUpload != null && zItem.ImageUpload.ContentLength > 0 && !validImageTypes.Contains(zItem.ImageUpload.ContentType)) { ModelState.AddModelError("ImageUpload", "Выберите GIF, JPG или PNG изображение."); } if (ModelState.IsValid) { var zDev = _zDevService.GetById(zItem.Id); model = Mapper.Map(zItem, zDev); } if (!ModelState.IsValid) { errorText = "Поля заполнены не верно. Черновик не был сохранен."; } if (errorText != null) { ModelState.AddFormError("Ошибка: ", errorText); return(new BsJsonResult( new Dictionary <string, object> { { "Errors", ModelState.GetErrors() } }, BsResponseStatus.ValidationError)); } _zDevService.CreateOrUpdate(model); if (zItem.ImageUpload != null && zItem.ImageUpload.ContentLength > 0) { string folderPath = Server.MapPath(imagesPath); string imageName = model.Id + Path.GetExtension(zItem.ImageUpload.FileName); if (!Directory.Exists(folderPath)) { Directory.CreateDirectory(folderPath); } model.ImagePath = imagesPath + imageName; _zDevService.Update(model); zItem.ImageUpload.SaveAs(Path.Combine(folderPath, imageName)); } return(new BsJsonResult(new { Status = BsResponseStatus.Success })); }
public BsJsonResult SaveDraft(DraftVm draft) { string errorText = null; string indexHtml = null; Article model = null; CustomUrl customUrl = null; if (ModelState.IsValid) { var article = _articleService.GetById(draft.Id); model = Mapper.Map(draft, article); customUrl = CreateOrUpdateCustomUrl(draft); if (model.ArticleState == ArticleState.New) { model.ArticleState = ArticleState.Draft; } if (model.ArticleState == ArticleState.Article) { if (!_htmlParserHelper.GetIndexHtmlFromArticleText(model.Text, out indexHtml)) { errorText = "Статья не содержит линии разрыва печати. Без неё публиковать нельзя!"; } } } if (!ModelState.IsValid) { errorText = "Поля заполнены не верно. Черновик не был сохранен."; } if (errorText != null) { ModelState.AddFormError("Ошибка: ", errorText); return(new BsJsonResult( new Dictionary <string, object> { { "Errors", ModelState.GetErrors() } }, BsResponseStatus.ValidationError)); } model.IndexHtml = indexHtml; _articleService.Update(model); //TODO: remove (temporary for output cache) MemoryCacheHelper.ArticlesUpdateTime = DateTime.Now; if (customUrl != null) { _customUrlService.CreateOrUpdate(customUrl); } return(new BsJsonResult(new { Status = BsResponseStatus.Success })); }
public BsJsonResult Register(AuthenticationModel model) { //keep errors only for RegisterModel ModelState.ClearModelState(model.GetPropertyName(m => m.RegisterModel) + "."); //add validation error to BsRange field if (model.RegisterModel != null && model.RegisterModel.Interval != null && //model.RegisterModel.Interval.To.ItemValue.HasValue && //model.RegisterModel.Interval.From.ItemValue.HasValue && model.RegisterModel.Interval.From.ItemValue > model.RegisterModel.Interval.To.ItemValue) { ModelState.AddFieldError("RegisterModel.Interval", model.RegisterModel.Interval.GetType(), "Invalid interval"); } //if (model.RegisterModel != null && // model.RegisterModel.Interval != null && // model.RegisterModel.Interval.To.ItemValue.HasValue && // model.RegisterModel.Interval.From.ItemValue.HasValue && // model.RegisterModel.Interval.From.ItemValue.Value > model.RegisterModel.Interval.To.ItemValue.Value) //{ // ModelState.AddFieldError("RegisterModel.Interval", // model.RegisterModel.Interval.GetType(), // "Invalid interval"); //} //add validation error to BsSelectList field ModelState.AddFieldError("RegisterModel.CountriesList", model.RegisterModel.CountriesList.GetType(), "Selected location doesn't match your GPS location"); //add global validation error ModelState.AddFormError("RegisterModel", "This email address is in use."); if (ModelState.IsValid) { } else { //JSON serialize ModelState errors return(new BsJsonResult( new Dictionary <string, object> { { "Errors", ModelState.GetErrors() } }, BsResponseStatus.ValidationError)); } return(new BsJsonResult()); }
public override void Execute() { WriteLiteral("\r\n\r\n"); #line 4 "..\..\Register.cshtml" Page.Title = AdminResources.RegisterTitle; var adminPath = SiteAdmin.AdminVirtualPath.TrimStart('~'); Page.Desc = String.Format(CultureInfo.CurrentCulture, AdminResources.RegisterDesc, Html.Encode(adminPath)); // If the password is already set the redirect to login if (AdminSecurity.HasAdminPassword()) { SiteAdmin.RedirectToLogin(Response); return; } if (IsPost) { AntiForgery.Validate(); var password = Request.Form["password"]; var reenteredPassword = Request.Form["repassword"]; if (password.IsEmpty()) { ModelState.AddError("password", AdminResources.Validation_PasswordRequired); } else if (password != reenteredPassword) { ModelState.AddError("repassword", AdminResources.Validation_PasswordsDoNotMatch); } if (ModelState.IsValid) { // Save the admin password if (AdminSecurity.SaveTemporaryPassword(password)) { // Get the return url var returnUrl = SiteAdmin.GetReturnUrl(Request) ?? SiteAdmin.AdminVirtualPath; // Redirect to the return url Response.Redirect(returnUrl); } else { // Add a validation error since creating the password.txt failed ModelState.AddFormError(AdminResources.AdminModuleRequiresAccessToAppData); } } } #line default #line hidden WriteLiteral("\r\n<br/>\r\n\r\n"); #line 47 "..\..\Register.cshtml" Write(Html.ValidationSummary()); #line default #line hidden WriteLiteral("\r\n\r\n<form method=\"post\" action=\"\">\r\n"); #line 50 "..\..\Register.cshtml" Write(AntiForgery.GetHtml()); #line default #line hidden WriteLiteral("\r\n<fieldset>\r\n <ol>\r\n <li class=\"password\">\r\n <label for=\"pa" + "ssword\">"); #line 54 "..\..\Register.cshtml" Write(AdminResources.EnterPassword); #line default #line hidden WriteLiteral("</label>\r\n "); #line 55 "..\..\Register.cshtml" Write(Html.Password("password")); #line default #line hidden WriteLiteral(" "); #line 55 "..\..\Register.cshtml" Write(Html.ValidationMessage("password", "*")); #line default #line hidden WriteLiteral("\r\n </li>\r\n <li class=\"password\">\r\n <label>"); #line 58 "..\..\Register.cshtml" Write(AdminResources.ReenterPassword); #line default #line hidden WriteLiteral("</label>\r\n "); #line 59 "..\..\Register.cshtml" Write(Html.Password("repassword")); #line default #line hidden WriteLiteral(" "); #line 59 "..\..\Register.cshtml" Write(Html.ValidationMessage("repassword", "*")); #line default #line hidden WriteLiteral("\r\n </li>\r\n </ol>\r\n <p class=\"form-actions\">\r\n <input type=\"su" + "bmit\" value=\""); #line 63 "..\..\Register.cshtml" Write(AdminResources.CreatePassword); #line default #line hidden WriteLiteral("\" class=\"long-input\" />\r\n </p>\r\n</fieldset>\r\n</form>\r\n"); }
public override void Execute() { WriteLiteral("\r\n\r\n"); WriteLiteral("\r\n"); DefineSection("PackageHead", () => { WriteLiteral(" \r\n <script type=\"text/javascript\" src=\""); Write(Href("scripts/PackageAction.js")); WriteLiteral("\"></script>\r\n <noscript>"); Write(PackageManagerResources.JavascriptRequired); WriteLiteral("</noscript>\r\n"); }); WriteLiteral("\r\n\r\n"); // Read from request var packageId = Request["package"]; var version = Request["version"]; WebProjectManager projectManager; try { projectManager = new WebProjectManager(PackageManagerModule.ActiveSource.Source, PackageManagerModule.SiteRoot); } catch (Exception exception) { WriteLiteral(" <div class=\"error message\">"); Write(exception.Message); WriteLiteral("</div>\r\n"); return; } IPackage package = projectManager.LocalRepository.FindPackage(packageId, version != null ? SemanticVersion.Parse(version) : null); if (package == null) { ModelState.AddFormError(PackageManagerResources.BadRequest); Write(Html.ValidationSummary()); return; } // Set up layout values var packagesHomeUrl = Href(PageUtils.GetPackagesHome(), Request.Url.Query); Page.SectionTitle = String.Format(CultureInfo.CurrentCulture, PackageManagerResources.UninstallPackageDesc, package.GetDisplayName()); if (IsPost) { AntiForgery.Validate(); bool removeDependencies = Request.Form["removeDependencies"].AsBool(false); try { projectManager.UninstallPackage(package, removeDependencies: removeDependencies); } catch (Exception exception) { ModelState.AddFormError(exception.Message); } if (ModelState.IsValid) { Response.Redirect(packagesHomeUrl + "&action-completed=Uninstall"); } else { Write(Html.ValidationSummary(String.Format(CultureInfo.CurrentCulture, PackageManagerResources.PackageUninstallationError, package.GetDisplayName()))); } return; } var encodedPackageName = Html.Encode(package.GetDisplayName()); WriteLiteral(" <h4>"); Write(Html.Raw(String.Format(CultureInfo.CurrentCulture, PackageManagerResources.AreYouSureUninstall, encodedPackageName))); WriteLiteral("</h4>\r\n"); WriteLiteral("<form method=\"post\" action=\"\" id=\"submitForm\">\r\n<fieldset class=\"no-border\">\r\n " + " "); Write(AntiForgery.GetHtml()); WriteLiteral("\r\n <input type=\"hidden\" name=\"package\" value=\""); Write(packageId); WriteLiteral("\" />\r\n <input type=\"hidden\" name=\"version\" value=\""); Write(version); WriteLiteral("\" />\r\n"); if (package.Dependencies.Any()) { WriteLiteral(" <div>\r\n <label><input type=\"checkbox\" name=\"removeDependencies" + "\" value=\"true\" checked=\"checked\"/>"); Write(PackageManagerResources.RemoveDependencies); WriteLiteral("</label>\r\n </div>\r\n"); WriteLiteral(" <br />\r\n"); } WriteLiteral(" <input type=\"submit\" value=\""); Write(PackageManagerResources.UninstallPackage); WriteLiteral("\" />\r\n \r\n <input type=\"reset\" value=\""); Write(PackageManagerResources.Cancel); WriteLiteral("\" data-returnurl=\""); Write(packagesHomeUrl); WriteLiteral("\" />\r\n</fieldset>\r\n</form>"); }
public override void Execute() { WriteLiteral("\r\n\r\n"); WriteLiteral("\r\n"); DefineSection("PackageHead", () => { WriteLiteral(" \r\n <script type=\"text/javascript\" src=\""); #line 9 "..\..\packages\Install.cshtml" Write(Href("scripts/PackageAction.js")); #line default #line hidden WriteLiteral("\"></script>\r\n <noscript>"); #line 10 "..\..\packages\Install.cshtml" Write(PackageManagerResources.JavascriptRequired); #line default #line hidden WriteLiteral("</noscript>\r\n"); }); WriteLiteral("\r\n"); #line 12 "..\..\packages\Install.cshtml" // Read params from request var sourceName = Request["source"]; var packageId = Request["package"]; var version = Request["version"]; var packageSource = PageUtils.GetPackageSource(sourceName); WebProjectManager projectManager; try { projectManager = new WebProjectManager(packageSource.Source, PackageManagerModule.SiteRoot); } catch (Exception exception) { #line default #line hidden WriteLiteral(" <div class=\"error message\">"); #line 24 "..\..\packages\Install.cshtml" Write(exception.Message); #line default #line hidden WriteLiteral("</div>\r\n"); #line 25 "..\..\packages\Install.cshtml" return; } IPackage package = projectManager.SourceRepository.FindPackage(packageId, version != null ? SemanticVersion.Parse(version) : null); if (package == null) { ModelState.AddFormError(PackageManagerResources.BadRequest); #line default #line hidden #line 31 "..\..\packages\Install.cshtml" Write(Html.ValidationSummary()); #line default #line hidden #line 31 "..\..\packages\Install.cshtml" return; } Page.SectionTitle = String.Format(CultureInfo.CurrentCulture, PackageManagerResources.InstallPackageDesc, package.GetDisplayName()); var packagesHomeUrl = Href(PageUtils.GetPackagesHome(), Request.Url.Query); if (IsPost) { AntiForgery.Validate(); try { projectManager.InstallPackage(package); } catch (Exception exception) { ModelState.AddFormError(exception.Message); } if (ModelState.IsValid) { Response.Redirect(packagesHomeUrl + "&action-completed=Install"); } else { #line default #line hidden #line 50 "..\..\packages\Install.cshtml" Write(Html.ValidationSummary(String.Format(CultureInfo.CurrentCulture, PackageManagerResources.PackageInstallationError, package.GetDisplayName()))); #line default #line hidden #line 50 "..\..\packages\Install.cshtml" return; } } #line default #line hidden WriteLiteral("\r\n"); #line 56 "..\..\packages\Install.cshtml" Write(RenderPage("_PackageDetails.cshtml", new Dictionary <string, object> { { "Package", package } })); #line default #line hidden WriteLiteral("\r\n\r\n"); #line 58 "..\..\packages\Install.cshtml" var licensePackages = projectManager.GetPackagesRequiringLicenseAcceptance(package); if (licensePackages.Any()) { #line default #line hidden WriteLiteral(" <hr />\r\n"); WriteLiteral(" <ul>\r\n"); #line 63 "..\..\packages\Install.cshtml" foreach (var licensePackage in licensePackages.Where(p => PageUtils.IsValidLicenseUrl(p.LicenseUrl))) { #line default #line hidden WriteLiteral(" <li>\r\n <strong>"); #line 65 "..\..\packages\Install.cshtml" Write(licensePackage.Id); #line default #line hidden WriteLiteral(" "); #line 65 "..\..\packages\Install.cshtml" Write(licensePackage.Version); #line default #line hidden WriteLiteral("</strong> \r\n ("); #line 66 "..\..\packages\Install.cshtml" Write(PackageManagerResources.AuthorsLabel); #line default #line hidden WriteLiteral(": <span class=\"package-author\">"); #line 66 "..\..\packages\Install.cshtml" Write(String.Join(PackageManagerResources.WordSeparator, licensePackage.Authors)); #line default #line hidden WriteLiteral("</span>)\r\n <br />\r\n <a href=\""); #line 68 "..\..\packages\Install.cshtml" Write(licensePackage.LicenseUrl); #line default #line hidden WriteLiteral("\" target=\"_blank\">"); #line 68 "..\..\packages\Install.cshtml" Write(PackageManagerResources.ViewLicenseTerms); #line default #line hidden WriteLiteral("</a>\r\n </li>\r\n"); #line 70 "..\..\packages\Install.cshtml" } #line default #line hidden WriteLiteral(" </ul> \r\n"); #line 72 "..\..\packages\Install.cshtml" } else { #line default #line hidden WriteLiteral(" <br />\r\n"); WriteLiteral(" <hr />\r\n"); #line 75 "..\..\packages\Install.cshtml" } #line default #line hidden WriteLiteral("\r\n<form method=\"post\" action=\"\" id=\"submitForm\">\r\n<p>"); #line 79 "..\..\packages\Install.cshtml" Write(PackageManagerResources.Disclaimer); #line default #line hidden WriteLiteral("</p> \r\n<fieldset class=\"no-border install\">\r\n <input type=\"hidden\" name=\"so" + "urce\" value=\""); #line 81 "..\..\packages\Install.cshtml" Write(sourceName); #line default #line hidden WriteLiteral("\" />\r\n <input type=\"hidden\" name=\"package\" value=\""); #line 82 "..\..\packages\Install.cshtml" Write(packageId); #line default #line hidden WriteLiteral("\" />\r\n <input type=\"hidden\" name=\"version\" value=\""); #line 83 "..\..\packages\Install.cshtml" Write(version); #line default #line hidden WriteLiteral("\" />\r\n "); #line 84 "..\..\packages\Install.cshtml" Write(AntiForgery.GetHtml()); #line default #line hidden WriteLiteral("\r\n\r\n <input type=\"submit\" value=\""); #line 86 "..\..\packages\Install.cshtml" Write(PackageManagerResources.InstallPackage); #line default #line hidden WriteLiteral("\" />\r\n <input type=\"reset\" value=\""); #line 87 "..\..\packages\Install.cshtml" Write(PackageManagerResources.Cancel); #line default #line hidden WriteLiteral("\" data-returnurl=\""); #line 87 "..\..\packages\Install.cshtml" Write(packagesHomeUrl); #line default #line hidden WriteLiteral("\" />\r\n</fieldset>\r\n \r\n\r\n</form>"); }
public override void Execute() { WriteLiteral("\r\n\r\n"); WriteLiteral("\r\n"); DefineSection("PackageHead", () => { WriteLiteral(" \r\n <script type=\"text/javascript\" src=\""); #line 8 "..\..\packages\Update.cshtml" Write(Href("scripts/PackageAction.js")); #line default #line hidden WriteLiteral("\"></script>\r\n <noscript>"); #line 9 "..\..\packages\Update.cshtml" Write(PackageManagerResources.JavascriptRequired); #line default #line hidden WriteLiteral("</noscript>\r\n"); }); WriteLiteral("\r\n"); #line 11 "..\..\packages\Update.cshtml" // Read params from request var sourceName = Request["source"]; var packageId = Request["package"]; var versionString = Request["version"]; var packageSource = PageUtils.GetPackageSource(sourceName); var version = !versionString.IsEmpty() ? SemanticVersion.Parse(versionString) : null; WebProjectManager projectManager; try { projectManager = new WebProjectManager(packageSource.Source, PackageManagerModule.SiteRoot); } catch (Exception exception) { #line default #line hidden WriteLiteral(" <div class=\"error message\">"); #line 24 "..\..\packages\Update.cshtml" Write(exception.Message); #line default #line hidden WriteLiteral("</div>\r\n"); #line 25 "..\..\packages\Update.cshtml" return; } var updatePackage = projectManager.SourceRepository.FindPackage(packageId, version); if (updatePackage == null) { ModelState.AddFormError(PackageManagerResources.BadRequest); #line default #line hidden #line 30 "..\..\packages\Update.cshtml" Write(Html.ValidationSummary()); #line default #line hidden #line 30 "..\..\packages\Update.cshtml" return; } var package = projectManager.LocalRepository.FindPackage(packageId); // Layout Page.SectionTitle = String.Format(CultureInfo.CurrentCulture, PackageManagerResources.UpdatePackageDesc, package.GetDisplayName(), updatePackage.Version); var packagesHomeUrl = Href(PageUtils.GetPackagesHome(), Request.Url.Query); if (IsPost) { AntiForgery.Validate(); try { projectManager.UpdatePackage(updatePackage); } catch (Exception exception) { ModelState.AddFormError(exception.Message); } if (ModelState.IsValid) { Response.Redirect(packagesHomeUrl + "&action-completed=Update"); } else { #line default #line hidden #line 52 "..\..\packages\Update.cshtml" Write(Html.ValidationSummary(String.Format(CultureInfo.CurrentCulture, PackageManagerResources.PackageUpdateError, package.GetDisplayName()))); #line default #line hidden #line 52 "..\..\packages\Update.cshtml" } return; } #line default #line hidden WriteLiteral("\r\n"); #line 58 "..\..\packages\Update.cshtml" Write(RenderPage("_PackageDetails.cshtml", new Dictionary <string, object> { { "Package", updatePackage } })); #line default #line hidden WriteLiteral("\r\n<br />\r\n<form method=\"post\" action=\"\" id=\"submitForm\">\r\n "); #line 61 "..\..\packages\Update.cshtml" Write(AntiForgery.GetHtml()); #line default #line hidden WriteLiteral("\r\n <input type=\"hidden\" name=\"source\" value=\""); #line 62 "..\..\packages\Update.cshtml" Write(sourceName); #line default #line hidden WriteLiteral("\" />\r\n <input type=\"hidden\" name=\"package\" value=\""); #line 63 "..\..\packages\Update.cshtml" Write(packageId); #line default #line hidden WriteLiteral("\" />\r\n <input type=\"hidden\" name=\"version\" value=\""); #line 64 "..\..\packages\Update.cshtml" Write(version); #line default #line hidden WriteLiteral("\" />\r\n\r\n <input type=\"submit\" value=\""); #line 66 "..\..\packages\Update.cshtml" Write(PackageManagerResources.UpdatePackage); #line default #line hidden WriteLiteral("\" />\r\n <input type=\"reset\" value=\""); #line 67 "..\..\packages\Update.cshtml" Write(PackageManagerResources.Cancel); #line default #line hidden WriteLiteral("\" data-returnurl=\""); #line 67 "..\..\packages\Update.cshtml" Write(packagesHomeUrl); #line default #line hidden WriteLiteral("\" />\r\n <br /><br />\r\n</form>"); }