/// <summary>
        /// Saves all settings that are stored in the database, to the configuration table.
        /// </summary>
        /// <param name="summary">Summary data containing the settings.</param>
        /// <param name="isInstalling">If true, a new <see cref="SiteConfiguration"/> is created, otherwise the current one is updated.</param>
        /// <exception cref="DatabaseException">An NHibernate (database) error occurred while saving the configuration.</exception>
        public static void SaveSiteConfiguration(SettingsSummary summary, bool isInstalling)
        {
            try
            {
                SiteConfiguration config;

                if (isInstalling)
                {
                    config = new SiteConfiguration();
                }
                else
                {
                    config = SiteConfiguration.Current;
                }

                config.AllowedFileTypes = summary.AllowedExtensions;
                config.AllowUserSignup = summary.AllowUserSignup;
                config.EnableRecaptcha = summary.EnableRecaptcha;
                config.MarkupType = summary.MarkupType;
                config.RecaptchaPrivateKey = summary.RecaptchaPrivateKey;
                config.RecaptchaPublicKey = summary.RecaptchaPublicKey;
                config.SiteUrl = summary.SiteUrl;
                config.Title = summary.SiteName;
                config.Theme = summary.Theme;

                config.Version = RoadkillSettings.Version;

                NHibernateRepository.Current.SaveOrUpdate<SiteConfiguration>(config);
            }
            catch (HibernateException ex)
            {
                throw new DatabaseException(ex, "An exception occurred while saving the site configuration.");
            }
        }
 /// <summary>
 /// Creates the database schema tables.
 /// </summary>
 /// <param name="summary">The settings data.</param>
 /// <exception cref="DatabaseException">An NHibernate (database) error occurred while creating the database tables.</exception>
 public static void CreateTables(SettingsSummary summary)
 {
     try
     {
         NHibernateRepository.Current.Configure(RoadkillSettings.DatabaseType, summary.ConnectionString, true, summary.CacheEnabled);
     }
     catch (HibernateException ex)
     {
         throw new DatabaseException(ex, "An exception occurred while creating the site schema tables.");
     }
 }
Example #3
0
 /// <summary>
 /// Adds the admin user.
 /// </summary>
 /// <param name="summary">The settings to get the data from.</param>
 /// <exception cref="InstallerException">An NHibernate (database) error occurred while adding the admin user.</exception>
 public static void AddAdminUser(SettingsSummary summary)
 {
     try
     {
         UserManager.Current.AddUser(summary.AdminEmail,"admin", summary.AdminPassword, true, false);
     }
     catch (SecurityException ex)
     {
         throw new InstallerException(ex, "Failed to add the admin user");
     }
 }
        /// <summary>
        /// Adds web.config settings for forms authentication.
        /// </summary>
        private static void WriteConfigForFormsAuth(Configuration config, SettingsSummary summary)
        {
            // Turn on forms authentication
            AuthenticationSection authSection = config.GetSection("system.web/authentication") as AuthenticationSection;
            authSection.Mode = AuthenticationMode.Forms;
            authSection.Forms.LoginUrl = "~/User/Login";

            // Turn on anonymous auth
            AnonymousIdentificationSection anonSection = config.GetSection("system.web/anonymousIdentification") as AnonymousIdentificationSection;
            anonSection.Enabled = true;
        }
        /// <summary>
        /// Saves the relevant parts of <see cref="SettingsSummary"/> to the web.config.
        /// </summary>
        /// <param name="summary">Summary data containing the settings.</param>
        /// <exception cref="InstallerException">An error occurred writing to or saving the web.config file</exception>
        public static void SaveWebConfigSettings(SettingsSummary summary)
        {
            try
            {
                Configuration config = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration("~");

                if (summary.UseWindowsAuth)
                {
                    WriteConfigForWindowsAuth(config);
                }
                else
                {
                    WriteConfigForFormsAuth(config, summary);
                }

                // Create a "Roadkill" connection string, or use the existing one if it exists.
                ConnectionStringSettings roadkillConnection = new ConnectionStringSettings("Roadkill", summary.ConnectionString);

                if (config.ConnectionStrings.ConnectionStrings["Roadkill"] == null)
                    config.ConnectionStrings.ConnectionStrings.Add(roadkillConnection);
                else
                    config.ConnectionStrings.ConnectionStrings["Roadkill"].ConnectionString = summary.ConnectionString;

                // The roadkill section
                RoadkillSection section = config.GetSection("roadkill") as RoadkillSection;
                section.AdminRoleName = summary.AdminRoleName;
                section.AttachmentsFolder = summary.AttachmentsFolder;
                section.CacheEnabled = summary.CacheEnabled;
                section.CacheText = summary.CacheText;
                section.ConnectionStringName = "Roadkill";
                section.DatabaseType = summary.DatabaseType.ToString();
                section.EditorRoleName = summary.EditorRoleName;
                section.LdapConnectionString = summary.LdapConnectionString;
                section.LdapUsername = summary.LdapUsername;
                section.LdapPassword = summary.LdapPassword;
                section.UseWindowsAuthentication = summary.UseWindowsAuth;

                section.Installed = true;

                config.Save(ConfigurationSaveMode.Minimal);
            }
            catch (ConfigurationErrorsException ex)
            {
                throw new InstallerException(ex, "An exception occurred while updating the settings to the web.config");
            }
        }
        public static SettingsSummary GetCurrentSettings()
        {
            SettingsSummary summary = new SettingsSummary();

            summary.AdminRoleName = RoadkillSettings.AdminRoleName;
            summary.AllowedExtensions = string.Join(",",RoadkillSettings.AllowedFileTypes);
            summary.AllowUserSignup = SiteConfiguration.Current.AllowUserSignup;
            summary.AttachmentsFolder = RoadkillSettings.AttachmentsFolder;
            summary.CacheEnabled = RoadkillSettings.CachedEnabled;
            summary.CacheText = RoadkillSettings.CacheText;
            summary.ConnectionString = RoadkillSettings.ConnectionString;
            summary.DatabaseType = RoadkillSettings.DatabaseType;
            summary.EditorRoleName = RoadkillSettings.EditorRoleName;
            summary.EnableRecaptcha = SiteConfiguration.Current.EnableRecaptcha;
            summary.LdapConnectionString = RoadkillSettings.LdapConnectionString;
            summary.LdapUsername = RoadkillSettings.LdapUsername;
            summary.LdapPassword = RoadkillSettings.LdapPassword;
            summary.MarkupType = RoadkillSettings.MarkupType;
            summary.RecaptchaPrivateKey = SiteConfiguration.Current.RecaptchaPrivateKey;
            summary.RecaptchaPublicKey = SiteConfiguration.Current.RecaptchaPublicKey;
            summary.SiteName = SiteConfiguration.Current.Title;
            summary.SiteUrl = SiteConfiguration.Current.SiteUrl;
            summary.Theme = RoadkillSettings.Theme;
            summary.UseWindowsAuth = RoadkillSettings.UseWindowsAuthentication;

            return summary;
        }