Defaults in settings model. Allow force load of settings from file
parent
f474f4fee2
commit
6483bea96b
|
@ -10,10 +10,10 @@
|
|||
{
|
||||
public int Port { get; set; } = 1337;
|
||||
public bool Beacon { get; set; } = true;
|
||||
public string DatabaseConnectionString { get; set; } = "";
|
||||
public string DatabaseConnectionString { get; set; } = "Data Source=LANCommander.db;Cache=Shared";
|
||||
public string IGDBClientId { get; set; } = "";
|
||||
public string IGDBClientSecret { get; set; } = "";
|
||||
public LANCommanderTheme Theme { get; set; }
|
||||
public LANCommanderTheme Theme { get; set; } = LANCommanderTheme.Light;
|
||||
|
||||
public LANCommanderAuthenticationSettings Authentication { get; set; } = new LANCommanderAuthenticationSettings();
|
||||
}
|
||||
|
@ -23,10 +23,10 @@
|
|||
public bool RequireApproval { get; set; } = false;
|
||||
public string TokenSecret { get; set; } = "";
|
||||
public int TokenLifetime { get; set; } = 30;
|
||||
public bool PasswordRequireNonAlphanumeric { get; set; }
|
||||
public bool PasswordRequireLowercase { get; set; }
|
||||
public bool PasswordRequireUppercase { get; set; }
|
||||
public bool PasswordRequireDigit { get; set; }
|
||||
public bool PasswordRequireNonAlphanumeric { get; set; } = false;
|
||||
public bool PasswordRequireLowercase { get; set; } = false;
|
||||
public bool PasswordRequireUppercase { get; set; } = false;
|
||||
public bool PasswordRequireDigit { get; set; } = true;
|
||||
public int PasswordRequiredLength { get; set; } = 8;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,7 +19,7 @@ ConfigurationManager configuration = builder.Configuration;
|
|||
|
||||
// Add services to the container.
|
||||
Logger.Debug("Loading settings");
|
||||
var settings = SettingService.GetSettings();
|
||||
var settings = SettingService.GetSettings(true);
|
||||
Logger.Debug("Loaded!");
|
||||
|
||||
Logger.Debug("Configuring MVC and Blazor");
|
||||
|
|
|
@ -8,7 +8,9 @@ namespace LANCommander.Services
|
|||
{
|
||||
private const string SettingsFilename = "Settings.yml";
|
||||
|
||||
public static LANCommanderSettings GetSettings()
|
||||
private static LANCommanderSettings Settings { get; set; }
|
||||
|
||||
public static LANCommanderSettings LoadSettings()
|
||||
{
|
||||
if (File.Exists(SettingsFilename))
|
||||
{
|
||||
|
@ -19,31 +21,24 @@ namespace LANCommander.Services
|
|||
.WithNamingConvention(PascalCaseNamingConvention.Instance)
|
||||
.Build();
|
||||
|
||||
return deserializer.Deserialize<LANCommanderSettings>(contents);
|
||||
Settings = deserializer.Deserialize<LANCommanderSettings>(contents);
|
||||
}
|
||||
else
|
||||
{
|
||||
var settings = new LANCommanderSettings
|
||||
{
|
||||
Port = 1337,
|
||||
Beacon = true,
|
||||
DatabaseConnectionString = "Data Source=LANCommander.db;Cache=Shared",
|
||||
Authentication = new LANCommanderAuthenticationSettings
|
||||
{
|
||||
TokenSecret = Guid.NewGuid().ToString(),
|
||||
TokenLifetime = 30,
|
||||
PasswordRequireNonAlphanumeric = false,
|
||||
PasswordRequireLowercase = false,
|
||||
PasswordRequireUppercase = false,
|
||||
PasswordRequireDigit = true,
|
||||
PasswordRequiredLength = 6
|
||||
}
|
||||
};
|
||||
Settings = new LANCommanderSettings();
|
||||
|
||||
SaveSettings(settings);
|
||||
|
||||
return settings;
|
||||
SaveSettings(Settings);
|
||||
}
|
||||
|
||||
return Settings;
|
||||
}
|
||||
|
||||
public static LANCommanderSettings GetSettings(bool forceLoad = false)
|
||||
{
|
||||
if (Settings == null || forceLoad)
|
||||
Settings = LoadSettings();
|
||||
|
||||
return Settings;
|
||||
}
|
||||
|
||||
public static void SaveSettings(LANCommanderSettings settings)
|
||||
|
@ -53,6 +48,8 @@ namespace LANCommander.Services
|
|||
.Build();
|
||||
|
||||
File.WriteAllText(SettingsFilename, serializer.Serialize(settings));
|
||||
|
||||
Settings = settings;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue