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 int Port { get; set; } = 1337;
|
||||||
public bool Beacon { get; set; } = true;
|
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 IGDBClientId { get; set; } = "";
|
||||||
public string IGDBClientSecret { 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();
|
public LANCommanderAuthenticationSettings Authentication { get; set; } = new LANCommanderAuthenticationSettings();
|
||||||
}
|
}
|
||||||
|
@ -23,10 +23,10 @@
|
||||||
public bool RequireApproval { get; set; } = false;
|
public bool RequireApproval { get; set; } = false;
|
||||||
public string TokenSecret { get; set; } = "";
|
public string TokenSecret { get; set; } = "";
|
||||||
public int TokenLifetime { get; set; } = 30;
|
public int TokenLifetime { get; set; } = 30;
|
||||||
public bool PasswordRequireNonAlphanumeric { get; set; }
|
public bool PasswordRequireNonAlphanumeric { get; set; } = false;
|
||||||
public bool PasswordRequireLowercase { get; set; }
|
public bool PasswordRequireLowercase { get; set; } = false;
|
||||||
public bool PasswordRequireUppercase { get; set; }
|
public bool PasswordRequireUppercase { get; set; } = false;
|
||||||
public bool PasswordRequireDigit { get; set; }
|
public bool PasswordRequireDigit { get; set; } = true;
|
||||||
public int PasswordRequiredLength { get; set; } = 8;
|
public int PasswordRequiredLength { get; set; } = 8;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,7 +19,7 @@ ConfigurationManager configuration = builder.Configuration;
|
||||||
|
|
||||||
// Add services to the container.
|
// Add services to the container.
|
||||||
Logger.Debug("Loading settings");
|
Logger.Debug("Loading settings");
|
||||||
var settings = SettingService.GetSettings();
|
var settings = SettingService.GetSettings(true);
|
||||||
Logger.Debug("Loaded!");
|
Logger.Debug("Loaded!");
|
||||||
|
|
||||||
Logger.Debug("Configuring MVC and Blazor");
|
Logger.Debug("Configuring MVC and Blazor");
|
||||||
|
|
|
@ -8,7 +8,9 @@ namespace LANCommander.Services
|
||||||
{
|
{
|
||||||
private const string SettingsFilename = "Settings.yml";
|
private const string SettingsFilename = "Settings.yml";
|
||||||
|
|
||||||
public static LANCommanderSettings GetSettings()
|
private static LANCommanderSettings Settings { get; set; }
|
||||||
|
|
||||||
|
public static LANCommanderSettings LoadSettings()
|
||||||
{
|
{
|
||||||
if (File.Exists(SettingsFilename))
|
if (File.Exists(SettingsFilename))
|
||||||
{
|
{
|
||||||
|
@ -19,31 +21,24 @@ namespace LANCommander.Services
|
||||||
.WithNamingConvention(PascalCaseNamingConvention.Instance)
|
.WithNamingConvention(PascalCaseNamingConvention.Instance)
|
||||||
.Build();
|
.Build();
|
||||||
|
|
||||||
return deserializer.Deserialize<LANCommanderSettings>(contents);
|
Settings = deserializer.Deserialize<LANCommanderSettings>(contents);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
var settings = new LANCommanderSettings
|
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
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
SaveSettings(settings);
|
SaveSettings(Settings);
|
||||||
|
|
||||||
return settings;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return Settings;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static LANCommanderSettings GetSettings(bool forceLoad = false)
|
||||||
|
{
|
||||||
|
if (Settings == null || forceLoad)
|
||||||
|
Settings = LoadSettings();
|
||||||
|
|
||||||
|
return Settings;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void SaveSettings(LANCommanderSettings settings)
|
public static void SaveSettings(LANCommanderSettings settings)
|
||||||
|
@ -53,6 +48,8 @@ namespace LANCommander.Services
|
||||||
.Build();
|
.Build();
|
||||||
|
|
||||||
File.WriteAllText(SettingsFilename, serializer.Serialize(settings));
|
File.WriteAllText(SettingsFilename, serializer.Serialize(settings));
|
||||||
|
|
||||||
|
Settings = settings;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue