public async Task<ActionResult> IndexPOST(SetupViewModel model) { if (!ModelState.IsValid) { return IndexViewResult(model); } var setupContext = new SetupContext { SiteName = model.SiteName, DatabaseProvider = model.DatabaseProvider, DatabaseConnectionString = model.ConnectionString, DatabaseTablePrefix = model.TablePrefix, EnabledFeatures = null, // default list, AdminUsername = model.AdminUserName, AdminEmail = model.AdminEmail, AdminPassword = model.Password }; var executionId = await _setupService.SetupAsync(setupContext); var urlPrefix = ""; if (!String.IsNullOrWhiteSpace(_shellSettings.RequestUrlPrefix)) { urlPrefix = _shellSettings.RequestUrlPrefix + "/"; } // Redirect to the welcome page. // TODO: Redirect on the home page once we don't rely on Orchard.Demo return Redirect("~/" + urlPrefix + "home/index"); }
public ActionResult IndexPOST(SetupViewModel model) { //HACK: (erikpo) Couldn't get a custom ValidationAttribute to validate two properties if (!model.DatabaseOptions && string.IsNullOrEmpty(model.DatabaseConnectionString)) ModelState.AddModelError("DatabaseConnectionString", "A SQL connection string is required"); if (!ModelState.IsValid) { return IndexViewResult(model); } try { var setupContext = new SetupContext { SiteName = model.SiteName, AdminUsername = model.AdminUsername, AdminPassword = model.AdminPassword, DatabaseProvider = model.DatabaseOptions ? "SQLite" : "SqlServer", DatabaseConnectionString = model.DatabaseConnectionString, DatabaseTablePrefix = model.DatabaseTablePrefix, EnabledFeatures = null // default list }; _setupService.Setup(setupContext); // redirect to the welcome page. return Redirect("~/"); } catch (Exception exception) { _notifier.Error(T("Setup failed:")); for (var scan = exception; scan != null; scan = scan.InnerException) { _notifier.Error(scan.Message); } return IndexViewResult(model); } }
private ActionResult IndexViewResult(SetupViewModel model) { string message; if (!CanWriteToAppDataFolder(out message)) { _notifier.Error( T( "Hey, it looks like I can't write to the App_Data folder in the root of this application and that's where I need to save some of the information you're about to enter.\r\n\r\nPlease give me (the machine account this application is running under) write access to App_Data so I can get this app all set up for you.\r\n\r\nThanks!\r\n\r\n----\r\n{0}", message)); } return View(model); }
public async Task<ActionResult> Index() { var recipes = await _setupService.GetSetupRecipesAsync(); var defaultRecipe = recipes.FirstOrDefault(x => x.Tags.Contains("default")) ?? recipes.First(); var model = new SetupViewModel { DatabaseProviders = GetDatabaseProviders(), Recipes = recipes, RecipeName = defaultRecipe.Name }; return View(model); }
public ActionResult IndexPOST(SetupViewModel model) { if (!ModelState.IsValid) { return IndexViewResult(model); } var setupContext = new SetupContext { SiteName = model.SiteName, EnabledFeatures = null, // default list }; var executionId = _setupService.Setup(setupContext); // redirect to the welcome page. return Redirect("~/" + _shellSettings.RequestUrlPrefix + "home/index"); }
public ActionResult IndexPOST(SetupViewModel model) { var recipes = OrderRecipes(_setupService.Recipes()); // if no builtin provider, a connection string is mandatory if (model.DatabaseProvider != SetupDatabaseType.Builtin && string.IsNullOrEmpty(model.DatabaseConnectionString)) ModelState.AddModelError("DatabaseConnectionString", T("A connection string is required").Text); if (!String.IsNullOrWhiteSpace(model.ConfirmPassword) && model.AdminPassword != model.ConfirmPassword ) { ModelState.AddModelError("ConfirmPassword", T("Password confirmation must match").Text); } if (model.DatabaseProvider != SetupDatabaseType.Builtin && !String.IsNullOrWhiteSpace(model.DatabaseTablePrefix)) { model.DatabaseTablePrefix = model.DatabaseTablePrefix.Trim(); if(!Char.IsLetter(model.DatabaseTablePrefix[0])) { ModelState.AddModelError("DatabaseTablePrefix", T("The table prefix must begin with a letter").Text); } if(model.DatabaseTablePrefix.Any(x => !Char.IsLetterOrDigit(x))) { ModelState.AddModelError("DatabaseTablePrefix", T("The table prefix must contain letters or digits").Text); } } if (model.Recipe == null) { if (!(recipes.Select(r => r.Name).Contains(DefaultRecipe))) { ModelState.AddModelError("Recipe", T("No recipes were found in the Setup module").Text); } else { model.Recipe = DefaultRecipe; } } if (!ModelState.IsValid) { model.Recipes = recipes; foreach (var recipe in recipes.Where(recipe => recipe.Name == model.Recipe)) { model.RecipeDescription = recipe.Description; } model.DatabaseIsPreconfigured = !string.IsNullOrEmpty(_setupService.Prime().DataProvider); return IndexViewResult(model); } try { string providerName = null; switch (model.DatabaseProvider) { case SetupDatabaseType.Builtin: providerName = "SqlCe"; break; case SetupDatabaseType.SqlServer: providerName = "SqlServer"; break; case SetupDatabaseType.MySql: providerName = "MySql"; break; default: throw new ApplicationException("Unknown database type: " + model.DatabaseProvider); } var setupContext = new SetupContext { SiteName = model.SiteName, AdminUsername = model.AdminUsername, AdminPassword = model.AdminPassword, DatabaseProvider = providerName, DatabaseConnectionString = model.DatabaseConnectionString, DatabaseTablePrefix = model.DatabaseTablePrefix, EnabledFeatures = null, // default list Recipe = model.Recipe }; string executionId = _setupService.Setup(setupContext); // First time installation if finally done. Tell the background views compilation // process to stop, so that it doesn't interfere with the user (asp.net compilation // uses a "single lock" mechanism for compiling views). _viewsBackgroundCompilation.Stop(); // redirect to the welcome page. return Redirect("~/" + _shellSettings.RequestUrlPrefix); } catch (Exception ex) { Logger.Error(ex, "Setup failed"); _notifier.Error(T("Setup failed: {0}", ex.Message)); model.Recipes = recipes; foreach (var recipe in recipes.Where(recipe => recipe.Name == model.Recipe)) { model.RecipeDescription = recipe.Description; } model.DatabaseIsPreconfigured = !string.IsNullOrEmpty(_setupService.Prime().DataProvider); return IndexViewResult(model); } }
private ActionResult IndexViewResult(SetupViewModel model) { return View(model); }
public async Task<ActionResult> IndexPOST(SetupViewModel model) { model.DatabaseProviders = GetDatabaseProviders(); model.Recipes = await _setupService.GetSetupRecipesAsync(); var selectedProvider = model.DatabaseProviders.FirstOrDefault(x => x.Value == model.DatabaseProvider); if (selectedProvider != null && selectedProvider.HasConnectionString && String.IsNullOrWhiteSpace(model.ConnectionString)) { ModelState.AddModelError("ConnectionString", T["The connection string is mandatory for this provider"]); } if (String.IsNullOrEmpty(model.Password)) { ModelState.AddModelError(nameof(model.Password), T["The password is required"]); } if (model.Password != model.PasswordConfirmation) { ModelState.AddModelError(nameof(model.PasswordConfirmation), T["The password confirmation doesn't match the password."]); } RecipeDescriptor selectedRecipe = null; if (String.IsNullOrEmpty(model.RecipeName) || (selectedRecipe = model.Recipes.FirstOrDefault(x => x.Name == model.RecipeName)) == null) { ModelState.AddModelError(nameof(model.RecipeName), T["Invalid recipe."]); } if (!ModelState.IsValid) { return View(model); } var setupContext = new SetupContext { SiteName = model.SiteName, DatabaseProvider = model.DatabaseProvider, DatabaseConnectionString = model.ConnectionString, DatabaseTablePrefix = model.TablePrefix, EnabledFeatures = null, // default list, AdminUsername = model.AdminUserName, AdminEmail = model.AdminEmail, AdminPassword = model.Password, Errors = new Dictionary<string, string>(), Recipe = selectedRecipe }; var executionId = await _setupService.SetupAsync(setupContext); // Check if a component in the Setup failed if (setupContext.Errors.Any()) { foreach (var error in setupContext.Errors) { ModelState.AddModelError(error.Key, error.Value); } return View(model); } var urlPrefix = ""; if (!String.IsNullOrWhiteSpace(_shellSettings.RequestUrlPrefix)) { urlPrefix = _shellSettings.RequestUrlPrefix + "/"; } return Redirect("~/" + urlPrefix); }
public ActionResult IndexPOST(SetupViewModel model) { var recipes = OrderRecipes(_setupService.Recipes()); // if no builtin provider, a connection string is mandatory if (model.DatabaseProvider != SetupDatabaseType.Builtin && string.IsNullOrEmpty(model.DatabaseConnectionString)) ModelState.AddModelError("DatabaseConnectionString", "قربون، رشته اتصال لازمه ها!"); if (!String.IsNullOrWhiteSpace(model.ConfirmPassword) && model.AdminPassword != model.ConfirmPassword ) { ModelState.AddModelError("ConfirmPassword", "قربونت برم، رمزهای عبوری که وارد کردی مثل هم نیستن."); } if (model.DatabaseProvider != SetupDatabaseType.Builtin && !String.IsNullOrWhiteSpace(model.DatabaseTablePrefix)) { model.DatabaseTablePrefix = model.DatabaseTablePrefix.Trim(); if(!Char.IsLetter(model.DatabaseTablePrefix[0])) { ModelState.AddModelError("DatabaseTablePrefix", "شرمنده، ولی پیشوندهای جدول ها باید حتما با حرف شروع بشه"); } if(model.DatabaseTablePrefix.Any(x => !Char.IsLetterOrDigit(x))) { ModelState.AddModelError("DatabaseTablePrefix", "قربونت برم، پیشوندهای جدول ها فقط میتونه حرف یا عدد باشه، چیز دیگه نمیشه"); } } if (model.Recipe == null) { if (!(recipes.Select(r => r.Name).Contains(DefaultRecipe))) { ModelState.AddModelError("Recipe", "دستور پخت ها رو توی ماژول Setup پیدا نکردم. ببینم، ارچاردفا رو دستکاری کردی؟"); } else { model.Recipe = DefaultRecipe; } } if (!ModelState.IsValid) { model.Recipes = recipes; foreach (var recipe in recipes.Where(recipe => recipe.Name == model.Recipe)) { model.RecipeDescription = recipe.Description; } model.DatabaseIsPreconfigured = !string.IsNullOrEmpty(_setupService.Prime().DataProvider); return IndexViewResult(model); } try { string providerName = null; switch (model.DatabaseProvider) { case SetupDatabaseType.Builtin: providerName = "SqlCe"; break; case SetupDatabaseType.SqlServer: providerName = "SqlServer"; break; case SetupDatabaseType.MySql: providerName = "MySql"; break; default: throw new ApplicationException("Unknown database type: " + model.DatabaseProvider); } var setupContext = new SetupContext { SiteName = model.SiteName, AdminUsername = model.AdminUsername, AdminPassword = model.AdminPassword, DatabaseProvider = providerName, DatabaseConnectionString = model.DatabaseConnectionString, DatabaseTablePrefix = model.DatabaseTablePrefix, EnabledFeatures = null, // default list Recipe = model.Recipe }; string executionId = _setupService.Setup(setupContext); // First time installation if finally done. Tell the background views compilation // process to stop, so that it doesn't interfere with the user (asp.net compilation // uses a "single lock" mechanism for compiling views). _viewsBackgroundCompilation.Stop(); // redirect to the welcome page. return Redirect("~/" + _shellSettings.RequestUrlPrefix); } catch (Exception ex) { Logger.Error(ex, "Setup failed"); _notifier.Error(new LocalizedString(string.Format("اوخیش، راه اندازی به خطا خورد: {0}", ex.Message))); model.Recipes = recipes; foreach (var recipe in recipes.Where(recipe => recipe.Name == model.Recipe)) { model.RecipeDescription = recipe.Description; } model.DatabaseIsPreconfigured = !string.IsNullOrEmpty(_setupService.Prime().DataProvider); return IndexViewResult(model); } }
public ActionResult IndexPOST(SetupViewModel model) { var recipes = OrderRecipes(_setupService.Recipes()); //TODO: Couldn't get a custom ValidationAttribute to validate two properties if (!model.DatabaseOptions && string.IsNullOrEmpty(model.DatabaseConnectionString)) ModelState.AddModelError("DatabaseConnectionString", T("A SQL connection string is required").Text); if (!String.IsNullOrWhiteSpace(model.ConfirmPassword) && model.AdminPassword != model.ConfirmPassword ) { ModelState.AddModelError("ConfirmPassword", T("Password confirmation must match").Text); } if(!model.DatabaseOptions && !String.IsNullOrWhiteSpace(model.DatabaseTablePrefix)) { model.DatabaseTablePrefix = model.DatabaseTablePrefix.Trim(); if(!Char.IsLetter(model.DatabaseTablePrefix[0])) { ModelState.AddModelError("DatabaseTablePrefix", T("The table prefix must begin with a letter").Text); } } if (model.Recipe == null) { if (!(recipes.Select(r => r.Name).Contains(DefaultRecipe))) { ModelState.AddModelError("Recipe", T("No recipes were found in the Setup module").Text); } else { model.Recipe = DefaultRecipe; } } if (!ModelState.IsValid) { model.Recipes = recipes; foreach (var recipe in recipes.Where(recipe => recipe.Name == model.Recipe)) { model.RecipeDescription = recipe.Description; } model.DatabaseIsPreconfigured = !string.IsNullOrEmpty(_setupService.Prime().DataProvider); return IndexViewResult(model); } try { var setupContext = new SetupContext { SiteName = model.SiteName, AdminUsername = model.AdminUsername, AdminPassword = model.AdminPassword, DatabaseProvider = model.DatabaseOptions ? "SqlCe" : "SqlServer", DatabaseConnectionString = model.DatabaseConnectionString, DatabaseTablePrefix = model.DatabaseTablePrefix, EnabledFeatures = null, // default list Recipe = model.Recipe }; string executionId = _setupService.Setup(setupContext); // First time installation if finally done. Tell the background views compilation // process to stop, so that it doesn't interfere with the user (asp.net compilation // uses a "single lock" mechanism for compiling views). _viewsBackgroundCompilation.Stop(); // redirect to the welcome page. return Redirect("~/"); } catch (Exception exception) { this.Error(exception, T("Setup failed:"), Logger, _notifier); model.Recipes = recipes; foreach (var recipe in recipes.Where(recipe => recipe.Name == model.Recipe)) { model.RecipeDescription = recipe.Description; } model.DatabaseIsPreconfigured = !string.IsNullOrEmpty(_setupService.Prime().DataProvider); return IndexViewResult(model); } }