Install Wizard

This commit is contained in:
Shaun Walker
2019-07-18 13:11:31 -04:00
parent af70f0a956
commit 1c0d2de9fe
36 changed files with 580 additions and 218 deletions

View File

@ -1,15 +1,31 @@
@using Oqtane.Shared
@using Oqtane.Client.Shared
@using Oqtane.Services
@inject IInstallationService InstallationService
<CascadingAuthenticationState>
<CascadingValue Value="@PageState">
<SiteRouter OnStateChange="@ChangeState" />
</CascadingValue>
</CascadingAuthenticationState>
@if (!Installed)
{
<Installer />
}
else
{
<CascadingAuthenticationState>
<CascadingValue Value="@PageState">
<SiteRouter OnStateChange="@ChangeState" />
</CascadingValue>
</CascadingAuthenticationState>
}
@code {
private bool Installed = false;
private PageState PageState { get; set; }
protected override async Task OnInitAsync()
{
var response = await InstallationService.IsInstalled();
Installed = response.Success;
}
private void ChangeState(PageState pagestate)
{
PageState = pagestate;

View File

@ -44,7 +44,7 @@
@code {
public override SecurityAccessLevelEnum SecurityAccessLevel { get { return SecurityAccessLevelEnum.Anonymous; } }
public string Message { get; set; } = "<div class=\"alert alert-info\" role=\"alert\">Use host/password For Demo Access</div>";
public string Message { get; set; } = "";
public string Username { get; set; } = "";
public string Password { get; set; } = "";
public bool Remember { get; set; } = false;

View File

@ -33,7 +33,7 @@
protected override async Task OnInitAsync()
{
HtmlTextService htmltextservice = new HtmlTextService(http, sitestate);
HtmlTextService htmltextservice = new HtmlTextService(http, sitestate, UriHelper);
List<HtmlTextInfo> htmltextlist = await htmltextservice.GetHtmlTextAsync(ModuleState.ModuleId);
if (htmltextlist != null)
{
@ -44,7 +44,7 @@
private async Task SaveContent()
{
HtmlTextService htmltextservice = new HtmlTextService(http, sitestate);
HtmlTextService htmltextservice = new HtmlTextService(http, sitestate, UriHelper);
if (htmltext != null)
{
htmltext.Content = content;

View File

@ -5,6 +5,7 @@
@using Oqtane.Client.Modules.Controls
@using Oqtane.Shared;
@inherits ModuleBase
@inject IUriHelper UriHelper
@inject HttpClient http
@inject SiteState sitestate
@ -17,7 +18,7 @@
protected override async Task OnInitAsync()
{
HtmlTextService htmltextservice = new HtmlTextService(http, sitestate);
HtmlTextService htmltextservice = new HtmlTextService(http, sitestate, UriHelper);
List<HtmlTextInfo> htmltext = await htmltextservice.GetHtmlTextAsync(ModuleState.ModuleId);
if (htmltext != null)
{

View File

@ -13,16 +13,18 @@ namespace Oqtane.Client.Modules.HtmlText.Services
{
private readonly HttpClient http;
private readonly SiteState sitestate;
private readonly IUriHelper urihelper;
public HtmlTextService(HttpClient http, SiteState sitestate)
public HtmlTextService(HttpClient http, SiteState sitestate, IUriHelper urihelper)
{
this.http = http;
this.sitestate = sitestate;
this.urihelper = urihelper;
}
private string apiurl
{
get { return CreateApiUrl(sitestate.Alias, "HtmlText"); }
get { return CreateApiUrl(sitestate.Alias, urihelper.GetAbsoluteUri(), "HtmlText"); }
}
public async Task<List<HtmlTextInfo>> GetHtmlTextAsync(int ModuleId)

View File

@ -11,17 +11,19 @@ namespace Oqtane.Services
public class AliasService : ServiceBase, IAliasService
{
private readonly HttpClient http;
private readonly SiteState sitestate;
private readonly IUriHelper urihelper;
public AliasService(HttpClient http, IUriHelper urihelper)
public AliasService(HttpClient http, SiteState sitestate, IUriHelper urihelper)
{
this.http = http;
this.sitestate = sitestate;
this.urihelper = urihelper;
}
private string apiurl
{
get { return CreateApiUrl(urihelper.GetAbsoluteUri(), "Alias"); }
get { return CreateApiUrl(sitestate.Alias, urihelper.GetAbsoluteUri(), "Alias"); }
}
public async Task<List<Alias>> GetAliasesAsync()

View File

@ -0,0 +1,12 @@
using Oqtane.Models;
using System.Collections.Generic;
using System.Threading.Tasks;
namespace Oqtane.Services
{
public interface IInstallationService
{
Task<GenericResponse> IsInstalled();
Task<GenericResponse> Install(string connectionstring);
}
}

View File

@ -0,0 +1,39 @@
using Oqtane.Models;
using System.Threading.Tasks;
using System.Net.Http;
using System.Linq;
using Microsoft.AspNetCore.Components;
using System.Collections.Generic;
using Oqtane.Shared;
namespace Oqtane.Services
{
public class InstallationService : ServiceBase, IInstallationService
{
private readonly HttpClient http;
private readonly SiteState sitestate;
private readonly IUriHelper urihelper;
public InstallationService(HttpClient http, SiteState sitestate, IUriHelper urihelper)
{
this.http = http;
this.sitestate = sitestate;
this.urihelper = urihelper;
}
private string apiurl
{
get { return CreateApiUrl(sitestate.Alias, urihelper.GetAbsoluteUri(), "Installation"); }
}
public async Task<GenericResponse> IsInstalled()
{
return await http.GetJsonAsync<GenericResponse>(apiurl + "/installed");
}
public async Task<GenericResponse> Install(string connectionstring)
{
return await http.PostJsonAsync<GenericResponse>(apiurl, connectionstring);
}
}
}

View File

@ -14,16 +14,18 @@ namespace Oqtane.Services
{
private readonly HttpClient http;
private readonly SiteState sitestate;
private readonly IUriHelper urihelper;
public ModuleDefinitionService(HttpClient http, SiteState sitestate)
public ModuleDefinitionService(HttpClient http, SiteState sitestate, IUriHelper urihelper)
{
this.http = http;
this.sitestate = sitestate;
this.urihelper = urihelper;
}
private string apiurl
{
get { return CreateApiUrl(sitestate.Alias, "ModuleDefinition"); }
get { return CreateApiUrl(sitestate.Alias, urihelper.GetAbsoluteUri(), "ModuleDefinition"); }
}
public async Task<List<ModuleDefinition>> GetModuleDefinitionsAsync()

View File

@ -12,16 +12,18 @@ namespace Oqtane.Services
{
private readonly HttpClient http;
private readonly SiteState sitestate;
private readonly IUriHelper urihelper;
public ModuleService(HttpClient http, SiteState sitestate)
public ModuleService(HttpClient http, SiteState sitestate, IUriHelper urihelper)
{
this.http = http;
this.sitestate = sitestate;
this.urihelper = urihelper;
}
private string apiurl
{
get { return CreateApiUrl(sitestate.Alias, "Module"); }
get { return CreateApiUrl(sitestate.Alias, urihelper.GetAbsoluteUri(), "Module"); }
}
public async Task<List<Module>> GetModulesAsync(int PageId)

View File

@ -12,16 +12,18 @@ namespace Oqtane.Services
{
private readonly HttpClient http;
private readonly SiteState sitestate;
private readonly IUriHelper urihelper;
public PageModuleService(HttpClient http, SiteState sitestate)
public PageModuleService(HttpClient http, SiteState sitestate, IUriHelper urihelper)
{
this.http = http;
this.sitestate = sitestate;
this.urihelper = urihelper;
}
private string apiurl
{
get { return CreateApiUrl(sitestate.Alias, "PageModule"); }
get { return CreateApiUrl(sitestate.Alias, "PageModule", urihelper.GetAbsoluteUri()); }
}
public async Task<List<PageModule>> GetPageModulesAsync()

View File

@ -12,16 +12,18 @@ namespace Oqtane.Services
{
private readonly HttpClient http;
private readonly SiteState sitestate;
private readonly IUriHelper urihelper;
public PageService(HttpClient http, SiteState sitestate)
public PageService(HttpClient http, SiteState sitestate, IUriHelper urihelper)
{
this.http = http;
this.sitestate = sitestate;
this.urihelper = urihelper;
}
private string apiurl
{
get { return CreateApiUrl(sitestate.Alias, "Page"); }
get { return CreateApiUrl(sitestate.Alias, urihelper.GetAbsoluteUri(), "Page"); }
}
public async Task<List<Page>> GetPagesAsync(int SiteId)

View File

@ -1,4 +1,5 @@
using System;
using Microsoft.AspNetCore.Components;
using Oqtane.Models;
using Oqtane.Shared;
@ -6,21 +7,24 @@ namespace Oqtane.Services
{
public class ServiceBase
{
// method for alias agnostic api call
public string CreateApiUrl(string absoluteUri, string serviceName)
{
Uri uri = new Uri(absoluteUri);
string apiurl = uri.Scheme + "://" + uri.Authority + "/~/api/" + serviceName;
return apiurl;
}
// method for alias specific api call
public string CreateApiUrl(Alias alias, string serviceName)
public string CreateApiUrl(Alias alias, string absoluteUri, string serviceName)
{
string apiurl = alias.Url + "/";
if (alias.Path == "")
string apiurl = "";
if (alias != null)
{
apiurl += "~/";
// build a url which passes the alias that may include a subfolder for multi-tenancy
apiurl = alias.Url + "/";
if (alias.Path == "")
{
apiurl += "~/";
}
}
else
{
// build a url which ignores any subfolder for multi-tenancy
Uri uri = new Uri(absoluteUri);
apiurl = uri.Scheme + "://" + uri.Authority + "/~/";
}
apiurl += "api/" + serviceName;
return apiurl;

View File

@ -12,16 +12,18 @@ namespace Oqtane.Services
{
private readonly HttpClient http;
private readonly SiteState sitestate;
private readonly IUriHelper urihelper;
public SiteService(HttpClient http, SiteState sitestate)
public SiteService(HttpClient http, SiteState sitestate, IUriHelper urihelper)
{
this.http = http;
this.sitestate = sitestate;
this.urihelper = urihelper;
}
private string apiurl
{
get { return CreateApiUrl(sitestate.Alias, "Site"); }
get { return CreateApiUrl(sitestate.Alias, urihelper.GetAbsoluteUri(), "Site"); }
}
public async Task<List<Site>> GetSitesAsync()

View File

@ -12,16 +12,18 @@ namespace Oqtane.Services
{
private readonly HttpClient http;
private readonly SiteState sitestate;
private readonly IUriHelper urihelper;
public TenantService(HttpClient http, SiteState sitestate)
public TenantService(HttpClient http, SiteState sitestate, IUriHelper urihelper)
{
this.http = http;
this.sitestate = sitestate;
this.urihelper = urihelper;
}
private string apiurl
{
get { return CreateApiUrl(sitestate.Alias, "Tenant"); }
get { return CreateApiUrl(sitestate.Alias, urihelper.GetAbsoluteUri(), "Tenant"); }
}
public async Task<List<Tenant>> GetTenantsAsync()

View File

@ -14,16 +14,18 @@ namespace Oqtane.Services
{
private readonly HttpClient http;
private readonly SiteState sitestate;
private readonly IUriHelper urihelper;
public ThemeService(HttpClient http, SiteState sitestate)
public ThemeService(HttpClient http, SiteState sitestate, IUriHelper urihelper)
{
this.http = http;
this.sitestate = sitestate;
this.urihelper = urihelper;
}
private string apiurl
{
get { return CreateApiUrl(sitestate.Alias, "Theme"); }
get { return CreateApiUrl(sitestate.Alias, urihelper.GetAbsoluteUri(), "Theme"); }
}
public async Task<List<Theme>> GetThemesAsync()

View File

@ -24,7 +24,7 @@ namespace Oqtane.Services
private string apiurl
{
get { return CreateApiUrl(sitestate.Alias, "User"); }
get { return CreateApiUrl(sitestate.Alias, urihelper.GetAbsoluteUri(), "User"); }
}
public async Task<List<User>> GetUsersAsync()

View File

@ -0,0 +1,187 @@
@using Oqtane.Services
@using Oqtane.Models
@inject IUriHelper UriHelper
@inject IInstallationService InstallationService
@inject IUserService UserService
<div class="container">
<div class="row">
<div class="mx-auto text-center">
<img src="oqtane.png" />
</div>
</div>
<hr style="width: 100%; color: gray; height: 1px; background-color:gray;" />
<h2 class="text-center">Database Configuration</h2>
<div class="row">
<div class="mx-auto text-center">
<table class="form-group" cellpadding="4" cellspacing="4">
<tbody>
<tr>
<td>
<label for="Title" class="control-label" style="font-weight: bold">Database Type: </label>
</td>
<td>
<select class="custom-select" @bind="@DatabaseType">
<option value="LocalDB">Local Database</option>
<option value="SQLServer">SQL Server</option>
</select>
</td>
</tr>
<tr>
<td>
<label for="Title" class="control-label" style="font-weight: bold">Server: </label>
</td>
<td>
<input type="text" id="ServerName" class="form-control" @bind="@ServerName" />
</td>
</tr>
<tr>
<td>
<label for="Title" class="control-label" style="font-weight: bold">Database: </label>
</td>
<td>
<input type="text" id="DatabaseName" class="form-control" @bind="@DatabaseName" />
</td>
</tr>
<tr>
<td>
<label for="Title" class="control-label" style="font-weight: bold">Integrated Security: </label>
</td>
<td>
<select class="custom-select" @onchange="@SetIntegratedSecurity">
<option value="true" selected>True</option>
<option value="false">False</option>
</select>
</td>
</tr>
<tr style="@IntegratedSecurityDisplay">
<td>
<label for="Title" class="control-label" style="font-weight: bold">Username: </label>
</td>
<td>
<input type="text" id="Username" class="form-control" @bind="@Username" />
</td>
</tr>
<tr style="@IntegratedSecurityDisplay">
<td>
<label for="Title" class="control-label" style="font-weight: bold">Password: </label>
</td>
<td>
<input type="password" id="Password" class="form-control" @bind="@Password" />
</td>
</tr>
</tbody>
</table>
</div>
</div>
<hr style="width: 100%; color: gray; height: 1px; background-color:gray;" />
<h2 class="text-center">Application Administrator</h2>
<div class="row">
<div class="mx-auto text-center">
<table class="form-group" cellpadding="4" cellspacing="4">
<tbody>
<tr>
<td>
<label for="Title" class="control-label" style="font-weight: bold">Username: </label>
</td>
<td>
<input type="text" id="Email" class="form-control" @bind="@HostUsername" />
</td>
</tr>
<tr>
<td>
<label for="Title" class="control-label" style="font-weight: bold">Password: </label>
</td>
<td>
<input type="password" id="Email" class="form-control" @bind="@HostPassword" />
</td>
</tr>
</tbody>
</table>
</div>
</div>
<div class="row">
<div class="mx-auto text-center">
<button class="btn btn-success" @onclick="@Install">Install Now</button><br /><br />
@((MarkupString)@Message)
</div>
<div class="loading" style="@LoadingDisplay"></div>
</div>
</div>
@code {
private string DatabaseType = "LocalDB";
private string ServerName = "(LocalDb)\\MSSQLLocalDB";
private string DatabaseName = "Oqtane-" + DateTime.Now.ToString("yyyyMMddHHmm");
private bool IntegratedSecurity = true;
private string Username = "";
private string Password = "";
private string HostUsername = "host";
private string HostPassword = "";
private string Message = "";
private string IntegratedSecurityDisplay = "display:none;";
private string LoadingDisplay = "display:none;";
private void SetIntegratedSecurity(UIChangeEventArgs e)
{
if (Convert.ToBoolean(e.Value))
{
IntegratedSecurityDisplay = "display:none;";
}
else
{
IntegratedSecurityDisplay = "";
}
}
private async Task Install()
{
if (HostPassword.Length >= 6)
{
LoadingDisplay = "";
StateHasChanged();
string connectionstring = "";
if (DatabaseType == "LocalDB")
{
connectionstring = "Data Source=" + ServerName + ";AttachDbFilename=|DataDirectory|\\" + DatabaseName + ".mdf;Initial Catalog=" + DatabaseName + ";Integrated Security=SSPI;";
}
else
{
connectionstring = "Data Source=" + ServerName + ";Initial Catalog=" + DatabaseName + ";";
if (IntegratedSecurityDisplay == "display:none;")
{
connectionstring += "Integrated Security=SSPI;";
}
else
{
connectionstring += "User ID=" + Username + ";Password=" + Password;
}
}
GenericResponse response = await InstallationService.Install(connectionstring);
if (response.Success)
{
User user = new User();
user.Username = HostUsername;
user.DisplayName = HostUsername;
user.Password = HostPassword;
user.IsSuperUser = true;
user.Roles = "";
await UserService.AddUserAsync(user);
UriHelper.NavigateTo("", true);
}
else
{
Message = "<div class=\"alert alert-danger\" role=\"alert\">" + response.Message + "</div>";
LoadingDisplay = "display:none;";
}
}
else
{
Message = "<div class=\"alert alert-danger\" role=\"alert\">Password Must Be 6 Characters Or Greater</div>";
}
}
}

View File

@ -36,6 +36,7 @@ namespace Oqtane.Client
// register scoped core services
services.AddScoped<SiteState>();
services.AddScoped<IInstallationService, InstallationService>();
services.AddScoped<IModuleDefinitionService, ModuleDefinitionService>();
services.AddScoped<IThemeService, ThemeService>();
services.AddScoped<IAliasService, AliasService>();

View File

@ -246,3 +246,13 @@ app {
text-align: center;
color: gray;
}
.loading {
background: rgba(0,0,0,0.2) url('../loading.gif') no-repeat 50% 50%;
width: 100%;
height: 100%;
position: fixed;
top: 0;
left: 0;
z-index: 999;
}

View File

@ -20,6 +20,14 @@ window.interop = {
}
return "";
},
getElementByName: function (name) {
var elements = document.getElementsByName(name);
if (elements.length) {
return elements[0].value;
} else {
return "";
}
},
addCSS: function (fileName) {
var head = document.head;
var link = document.createElement("link");

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.0 KiB