Removed legacy setup and config save
This commit is contained in:
@@ -1,43 +0,0 @@
|
|||||||
using Newtonsoft.Json;
|
|
||||||
|
|
||||||
namespace Moonlight.App.Helpers;
|
|
||||||
|
|
||||||
public class ConfigUtils
|
|
||||||
{
|
|
||||||
public static void SaveConfigurationAsJson(IConfiguration configuration, string filePath)
|
|
||||||
{
|
|
||||||
// Serialize the configuration to a JSON object
|
|
||||||
var jsonObject = new Dictionary<string, object>();
|
|
||||||
foreach (var section in configuration.GetChildren())
|
|
||||||
{
|
|
||||||
SerializeSection(section, jsonObject);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Convert the JSON object to a JSON string
|
|
||||||
var jsonString = JsonConvert.SerializeObject(jsonObject);
|
|
||||||
|
|
||||||
// Write the JSON string to a file
|
|
||||||
File.WriteAllText(filePath, jsonString);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void SerializeSection(IConfigurationSection section, IDictionary<string, object> jsonObject)
|
|
||||||
{
|
|
||||||
var children = section.GetChildren();
|
|
||||||
|
|
||||||
if (!children.Any())
|
|
||||||
{
|
|
||||||
// Leaf node
|
|
||||||
jsonObject[section.Key] = section.Value;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// Non-leaf node
|
|
||||||
var childObject = new Dictionary<string, object>();
|
|
||||||
foreach (var childSection in children)
|
|
||||||
{
|
|
||||||
SerializeSection(childSection, childObject);
|
|
||||||
}
|
|
||||||
jsonObject[section.Key] = childObject;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -74,9 +74,4 @@ public class ConfigService : IConfiguration
|
|||||||
get => Configuration[key];
|
get => Configuration[key];
|
||||||
set => Configuration[key] = value;
|
set => Configuration[key] = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Save()
|
|
||||||
{
|
|
||||||
ConfigUtils.SaveConfigurationAsJson(Configuration, "..\\..\\appsettings.json");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -1,69 +0,0 @@
|
|||||||
@page "/setup/features"
|
|
||||||
|
|
||||||
@using Moonlight.App.Services
|
|
||||||
|
|
||||||
@inject ConfigService ConfigService
|
|
||||||
@inject NavigationManager NavigationManager
|
|
||||||
@inject SmartTranslateService SmartTranslateService
|
|
||||||
|
|
||||||
<IsSetup>
|
|
||||||
<div class="card col d-flex justify-content-center">
|
|
||||||
<div class="card-header">
|
|
||||||
<span class="card-title"><TL>Configure features</TL> (3/4)</span>
|
|
||||||
</div>
|
|
||||||
<div class="card-body p-10">
|
|
||||||
<div class="input-group">
|
|
||||||
<label class="col-lg-4 col-form-label fw-semibold fs-6">
|
|
||||||
<TL>Support chat</TL>
|
|
||||||
</label>
|
|
||||||
<div class="col-lg-8 d-flex align-items-center">
|
|
||||||
<div class="form-check form-check-solid form-switch form-check-custom fv-row">
|
|
||||||
<input @bind="EnableSupportChat" class="form-check-input w-45px h-30px" type="checkbox" id="supportChat">
|
|
||||||
<label class="form-check-label" for="supportChat"></label>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div class="input-group mt-5">
|
|
||||||
<WButton Text="@(SmartTranslateService.Translate("Save and continue"))"
|
|
||||||
WorkingText="@(SmartTranslateService.Translate("Saving"))"
|
|
||||||
CssClasses="btn-success"
|
|
||||||
OnClick="Save">
|
|
||||||
</WButton>
|
|
||||||
<a href="/setup/final" class="btn btn-primary">
|
|
||||||
<TL>Next</TL>
|
|
||||||
</a>
|
|
||||||
<a href="/setup/users" class="btn btn-danger">
|
|
||||||
<TL>Back</TL>
|
|
||||||
</a>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</IsSetup>
|
|
||||||
<NonSetup>
|
|
||||||
<SetupCompletedAlert></SetupCompletedAlert>
|
|
||||||
</NonSetup>
|
|
||||||
|
|
||||||
@code
|
|
||||||
{
|
|
||||||
private bool EnableSupportChat
|
|
||||||
{
|
|
||||||
get => bool.Parse(
|
|
||||||
ConfigService
|
|
||||||
.GetSection("Moonlight")
|
|
||||||
.GetSection("SupportChat")
|
|
||||||
["Enabled"]!
|
|
||||||
);
|
|
||||||
set => ConfigService
|
|
||||||
.GetSection("Moonlight")
|
|
||||||
.GetSection("SupportChat")
|
|
||||||
["Enabled"] = value.ToString();
|
|
||||||
}
|
|
||||||
|
|
||||||
private Task Save()
|
|
||||||
{
|
|
||||||
ConfigService.Save();
|
|
||||||
NavigationManager.NavigateTo("/setup/final");
|
|
||||||
|
|
||||||
return Task.CompletedTask;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,40 +0,0 @@
|
|||||||
@page "/setup/final"
|
|
||||||
|
|
||||||
@using Moonlight.App.Services
|
|
||||||
@using Moonlight.App.Services.Interop
|
|
||||||
|
|
||||||
@inject ConfigService ConfigService
|
|
||||||
@inject NavigationManager NavigationManager
|
|
||||||
@inject SmartTranslateService SmartTranslateService
|
|
||||||
@inject ToastService ToastService
|
|
||||||
|
|
||||||
<IsSetup>
|
|
||||||
<div class="card col d-flex justify-content-center">
|
|
||||||
<div class="card-header">
|
|
||||||
<span class="card-title"><TL>Finalize installation</TL> (4/4)</span>
|
|
||||||
</div>
|
|
||||||
<div class="card-body p-10">
|
|
||||||
<div class="input-group mt-5">
|
|
||||||
<WButton Text="@(SmartTranslateService.Translate("Finish"))"
|
|
||||||
WorkingText="@(SmartTranslateService.Translate("Saving"))"
|
|
||||||
CssClasses="btn-success"
|
|
||||||
OnClick="Save">
|
|
||||||
</WButton>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</IsSetup>
|
|
||||||
<NonSetup>
|
|
||||||
<SetupCompletedAlert></SetupCompletedAlert>
|
|
||||||
</NonSetup>
|
|
||||||
|
|
||||||
@code
|
|
||||||
{
|
|
||||||
private async Task Save()
|
|
||||||
{
|
|
||||||
ConfigService.GetSection("Moonlight")["SetupComplete"] = true.ToString();
|
|
||||||
ConfigService.Save();
|
|
||||||
await ToastService.Success(SmartTranslateService.Translate("Moonlight basic settings successfully configured"));
|
|
||||||
NavigationManager.NavigateTo("/");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,53 +0,0 @@
|
|||||||
@page "/setup"
|
|
||||||
@using Moonlight.App.Services
|
|
||||||
|
|
||||||
@inject ConfigService ConfigService
|
|
||||||
@inject NavigationManager NavigationManager
|
|
||||||
@inject SmartTranslateService SmartTranslateService
|
|
||||||
|
|
||||||
<IsSetup>
|
|
||||||
<div class="card col d-flex justify-content-center">
|
|
||||||
<div class="card-header">
|
|
||||||
<span class="card-title"><TL>Configure basics</TL> (1/4)</span>
|
|
||||||
</div>
|
|
||||||
<div class="card-body p-10">
|
|
||||||
<label class="form-label">
|
|
||||||
<TL>Brand name</TL>
|
|
||||||
</label>
|
|
||||||
<div class="input-group mb-5">
|
|
||||||
<span class="input-group-text">
|
|
||||||
<i class="bx bx-purchase-tag-alt"></i>
|
|
||||||
</span>
|
|
||||||
<input
|
|
||||||
@bind="@(ConfigService.GetSection("Moonlight").GetSection("Marketing")["BrandName"])"
|
|
||||||
type="text"
|
|
||||||
class="form-control"
|
|
||||||
placeholder="@(SmartTranslateService.Translate("Insert brand name..."))">
|
|
||||||
</div>
|
|
||||||
<div class="input-group mt-5">
|
|
||||||
<WButton Text="@(SmartTranslateService.Translate("Save and continue"))"
|
|
||||||
WorkingText="@(SmartTranslateService.Translate("Saving"))"
|
|
||||||
CssClasses="btn-success"
|
|
||||||
OnClick="Save">
|
|
||||||
</WButton>
|
|
||||||
<a href="/setup/users" class="btn btn-primary">
|
|
||||||
<TL>Next</TL>
|
|
||||||
</a>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</IsSetup>
|
|
||||||
<NonSetup>
|
|
||||||
<SetupCompletedAlert></SetupCompletedAlert>
|
|
||||||
</NonSetup>
|
|
||||||
|
|
||||||
@code
|
|
||||||
{
|
|
||||||
private Task Save()
|
|
||||||
{
|
|
||||||
ConfigService.Save();
|
|
||||||
NavigationManager.NavigateTo("/setup/users");
|
|
||||||
|
|
||||||
return Task.CompletedTask;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,142 +0,0 @@
|
|||||||
@page "/setup/users"
|
|
||||||
@using Moonlight.App.Services
|
|
||||||
@using Microsoft.AspNetCore.Components
|
|
||||||
@using Moonlight.App.Database.Entities
|
|
||||||
@using Moonlight.App.Exceptions
|
|
||||||
@using Moonlight.App.Services.Interop
|
|
||||||
@using Logging.Net
|
|
||||||
@using Moonlight.App.Repositories
|
|
||||||
|
|
||||||
@inject UserService UserService
|
|
||||||
@inject UserRepository UserRepository
|
|
||||||
@inject SmartTranslateService SmartTranslateService
|
|
||||||
@inject AlertService AlertService
|
|
||||||
@inject ToastService ToastService
|
|
||||||
|
|
||||||
<IsSetup>
|
|
||||||
<div class="card col d-flex justify-content-center">
|
|
||||||
<div class="card-header">
|
|
||||||
<span class="card-title"><TL>Add admin accounts</TL> (2/4)</span>
|
|
||||||
</div>
|
|
||||||
<div class="card-body p-10">
|
|
||||||
<label class="form-label">
|
|
||||||
<TL>First name</TL>
|
|
||||||
</label>
|
|
||||||
<div class="input-group mb-5">
|
|
||||||
<span class="input-group-text">
|
|
||||||
<i class="bx bx-envelope"></i>
|
|
||||||
</span>
|
|
||||||
<input
|
|
||||||
@bind="@(NewUser.FirstName)"
|
|
||||||
type="text"
|
|
||||||
class="form-control"
|
|
||||||
required=""
|
|
||||||
placeholder="@(SmartTranslateService.Translate("Insert first name..."))">
|
|
||||||
</div>
|
|
||||||
<label class="form-label">
|
|
||||||
<TL>Last name</TL>
|
|
||||||
</label>
|
|
||||||
<div class="input-group mb-5">
|
|
||||||
<span class="input-group-text">
|
|
||||||
<i class="bx bx-envelope"></i>
|
|
||||||
</span>
|
|
||||||
<input
|
|
||||||
@bind="@(NewUser.LastName)"
|
|
||||||
type="text"
|
|
||||||
class="form-control"
|
|
||||||
required=""
|
|
||||||
placeholder="@(SmartTranslateService.Translate("Insert last name..."))">
|
|
||||||
</div>
|
|
||||||
<label class="form-label">
|
|
||||||
<TL>Email address</TL>
|
|
||||||
</label>
|
|
||||||
<div class="input-group mb-5">
|
|
||||||
<span class="input-group-text">
|
|
||||||
<i class="bx bx-envelope"></i>
|
|
||||||
</span>
|
|
||||||
<input
|
|
||||||
@bind="@(NewUser.Email)"
|
|
||||||
type="email"
|
|
||||||
class="form-control"
|
|
||||||
required=""
|
|
||||||
placeholder="@(SmartTranslateService.Translate("Insert email address..."))">
|
|
||||||
</div>
|
|
||||||
<label class="form-label">
|
|
||||||
<TL>Enter password</TL>
|
|
||||||
</label>
|
|
||||||
<div class="input-group mb-5">
|
|
||||||
<span class="input-group-text">
|
|
||||||
<i class="bx bx-envelope"></i>
|
|
||||||
</span>
|
|
||||||
<input
|
|
||||||
@bind="@(NewUser.Password)"
|
|
||||||
type="password"
|
|
||||||
class="form-control"
|
|
||||||
required="">
|
|
||||||
</div>
|
|
||||||
<div class="input-group mt-5">
|
|
||||||
<WButton Text="@(SmartTranslateService.Translate("Add"))"
|
|
||||||
WorkingText="@(SmartTranslateService.Translate("Adding..."))"
|
|
||||||
CssClasses="btn-success"
|
|
||||||
OnClick="Save">
|
|
||||||
</WButton>
|
|
||||||
<a href="/setup/features" class="btn btn-primary">
|
|
||||||
<TL>Next</TL>
|
|
||||||
</a>
|
|
||||||
<a href="/setup" class="btn btn-danger">
|
|
||||||
<TL>Back</TL>
|
|
||||||
</a>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</IsSetup>
|
|
||||||
<NonSetup>
|
|
||||||
<SetupCompletedAlert></SetupCompletedAlert>
|
|
||||||
</NonSetup>
|
|
||||||
|
|
||||||
@code
|
|
||||||
{
|
|
||||||
private User NewUser = new();
|
|
||||||
|
|
||||||
private async Task Save()
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
await UserService.Register(
|
|
||||||
NewUser.Email,
|
|
||||||
NewUser.Password,
|
|
||||||
NewUser.FirstName,
|
|
||||||
NewUser.LastName
|
|
||||||
);
|
|
||||||
|
|
||||||
var user = UserRepository.Get().First(x => x.Email == NewUser.Email);
|
|
||||||
user.Admin = true;
|
|
||||||
UserRepository.Update(user);
|
|
||||||
|
|
||||||
await ToastService.Success(
|
|
||||||
SmartTranslateService.Translate("User successfully created")
|
|
||||||
);
|
|
||||||
}
|
|
||||||
catch (DisplayException e)
|
|
||||||
{
|
|
||||||
await AlertService.Error(
|
|
||||||
SmartTranslateService.Translate("Error"),
|
|
||||||
e.Message
|
|
||||||
);
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
await AlertService.Error(
|
|
||||||
SmartTranslateService.Translate("Error"),
|
|
||||||
SmartTranslateService.Translate("An error occured while creating user")
|
|
||||||
);
|
|
||||||
|
|
||||||
Logger.Error("Error while creating user");
|
|
||||||
Logger.Error(e);
|
|
||||||
}
|
|
||||||
|
|
||||||
NewUser = new();
|
|
||||||
|
|
||||||
await InvokeAsync(StateHasChanged);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user