public ActionResult StepFour() { if (DataSettingsHelper.SiteIsInstalled) return RedirectToAction("index", "home"); if (!DataSettingsHelper.DatabaseIsInstalled) return RedirectToRoute("Install"); var manager = new DataSettingsManager(); var settings = manager.LoadSettings(); if (settings.SiteOwner == null) return RedirectToRoute("Install"); var model = PrepareStepFourModel(siteOwner: settings.SiteOwner); return View(model); }
public ActionResult StepFour(StepFourModel model) { if (DataSettingsHelper.SiteIsInstalled) return RedirectToAction("index", "home"); if (!DataSettingsHelper.DatabaseIsInstalled) return RedirectToRoute("Install"); // Load the local settings var manager = new DataSettingsManager(); var settings = manager.LoadSettings(); // Ensure the form is valid if (ModelState.IsValid) { var siteOwner = settings.SiteOwner; siteOwner.DisplayName = model.DisplayName; siteOwner.Email = model.Email; siteOwner.UserName = SeoExtensions.GetSeoName(model.UserName); // Install the rest of the site data var installService = EngineContext.Current.Resolve<IInstallService>(); installService.InstallUserData(siteOwner, model.MailFromDisplayName, model.MailFromEmail, model.MailHost, model.MailPort, model.MailUsername, model.MailPassword, model.TwitterAccessToken, model.TwitterAccessTokenSecret); // Clear our the site owner data from the settings file settings.InstallComplete = true; settings.SiteOwner = null; manager.SaveSettings(settings); // Restart the application var webHelper = EngineContext.Current.Resolve<IWebHelper>(); webHelper.RestartAppDomain(); // Redirect home return RedirectToAction("index", "home"); } model = PrepareStepFourModel(model); return View(model); }
public ActionResult StepOne() { if (DataSettingsHelper.SiteIsInstalled) return RedirectToAction("index", "home"); if (DataSettingsHelper.DatabaseIsInstalled) return RedirectToAction("steptwo", "install"); var model = PrepareStepOneModel(); var manager = new DataSettingsManager(); var settings = manager.LoadSettings(); if (settings != null) { var builder = new SqlConnectionStringBuilder(settings.ConnectionString); model.DatabaseName = builder.InitialCatalog; model.DatabasePassword = builder.Password; model.DatabaseServerName = builder.DataSource; model.DatabaseUsername = builder.UserID; } return View(model); }
public ActionResult StepOne(StepOneModel model) { var manager = new DataSettingsManager(); model = PrepareStepOneModel(model); // Make sure if SQL Server authenticaton is selected, we have been given a username/password if (model.DatabaseAuthenticationMethod == 10) { if (string.IsNullOrEmpty(model.DatabaseUsername)) ModelState.AddModelError("DatabaseUsername", "Please enter your SQL username."); if (string.IsNullOrEmpty(model.DatabasePassword)) ModelState.AddModelError("DatabasePassword", "Please enter your SQL password."); } // Make sure we have the required folder permissions string root = Server.MapPath("~/"); var directories = new List<string> { Path.Combine(root, "robots.txt"), Path.Combine(root, "App_Data"), Path.Combine(root, "Uploads"), Path.Combine(root, "Uploads\\Media"), Path.Combine(root, "Uploads\\Profile") }; // Check each directory, flagging a modelstate error if the permissions aren't correct foreach (var directory in directories.Where(directory => !CheckPermissions(directory, false, true, true, true))) ModelState.AddModelError("", string.Format("The '{0}' account is not granted with Modify permission on folder '{1}'. Please configure these permissions.", WindowsIdentity.GetCurrent().Name, directory)); // Ensure the rest of the form is valid if (ModelState.IsValid) { try { // Build the connection string string connectionString = GenerateConnectionString(model.DatabaseAuthenticationMethod == 20, model.DatabaseServerName, model.DatabaseName, model.DatabaseUsername, model.DatabasePassword); // If the database doesn't exist, create it if (!DatabaseExists(connectionString)) { string databaseCreationError = CreateDatabase(connectionString); if (!string.IsNullOrEmpty(databaseCreationError)) throw new Exception(databaseCreationError); Thread.Sleep(3000); } // Create settings and save var settings = new DataSettings {ConnectionString = connectionString}; manager.SaveSettings(settings); // Initialise the database var dataProviderInstance = new EfDataProvider(); dataProviderInstance.InitDatabase(); // Install the core data var installService = EngineContext.Current.Resolve<IInstallService>(); bool coreDataInstalled = installService.InstallCoreData(); // Make sure the core data installed correctly before running on ahead if (!coreDataInstalled) ModelState.AddModelError("", "An error occurred during installation, please try again."); else return RedirectToAction("steptwo", "install"); } catch (Exception ex) { ModelState.AddModelError("", "Installation failed: " + ex); } } return View(model); }