Merge pull request #1 from oqtane/master

sync-9-15-2019
This commit is contained in:
ADefWebserver 2019-09-15 07:40:40 -07:00 committed by GitHub
commit ac23b720c4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
217 changed files with 7076 additions and 2822 deletions

2
.gitignore vendored
View File

@ -6,7 +6,9 @@ artifacts/
msbuild.binlog
.vscode/
*.binlog
*.nupkg
Oqtane.Server/appsettings.json
Oqtane.Server/Data/*.mdf
Oqtane.Server/Data/*.ldf

View File

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

View File

@ -2,7 +2,8 @@
@using Oqtane.Modules
@using Oqtane.Services
@using Oqtane.Models;
@using Oqtane.Client.Modules.Controls
@using Oqtane.Security
@namespace Oqtane.Modules.Admin.Dashboard
@inherits ModuleBase
@inject IPageService PageService
@inject IUserService UserService
@ -10,7 +11,7 @@
<ul class="list-group">
@foreach (var p in pages)
{
if (p.IsNavigation && UserService.IsAuthorized(PageState.User, p.ViewPermissions))
if (p.IsNavigation && UserSecurity.IsAuthorized(PageState.User, "View", p.Permissions))
{
string url = NavigateUrl(p.Path);
<li class="list-group-item">
@ -21,12 +22,13 @@
}
}
</ul>
<br /><br />
<br />
<br />
@code {
List<Page> pages;
protected override void OnInit()
protected override void OnInitialized()
{
// display list of pages which are children of current page
pages = PageState.Pages.Where(item => item.ParentId == PageState.Page.PageId).ToList();

View File

@ -5,6 +5,7 @@
@using Oqtane.Services
@using Oqtane.Providers
@using Oqtane.Shared
@namespace Oqtane.Modules.Admin.Login
@inherits ModuleBase
@inject IUriHelper UriHelper
@inject IJSRuntime jsRuntime
@ -42,7 +43,7 @@
</AuthorizeView>
@code {
public override SecurityAccessLevelEnum SecurityAccessLevel { get { return SecurityAccessLevelEnum.Anonymous; } }
public override SecurityAccessLevel SecurityAccessLevel { get { return SecurityAccessLevel.Anonymous; } }
public string Message { get; set; } = "";
public string Username { get; set; } = "";
@ -50,13 +51,6 @@ public string Password { get; set; } = "";
public bool Remember { get; set; } = false;
private async Task Login()
{
User user = new User();
user.Username = Username;
user.Password = Password;
user.IsPersistent = Remember;
user = await UserService.LoginUserAsync(user);
if (user.IsAuthenticated)
{
string ReturnUrl = PageState.QueryString["returnurl"];
@ -64,6 +58,14 @@ private async Task Login()
if (authstateprovider == null)
{
// server-side Blazor
User user = new User();
user.SiteId = PageState.Site.SiteId;
user.Username = Username;
user.Password = Password;
user = await UserService.LoginUserAsync(user, false, false);
if (user.IsAuthenticated)
{
// complete the login on the server so that the cookies are set correctly on SignalR
var interop = new Interop(jsRuntime);
string antiforgerytoken = await interop.GetElementByName("__RequestVerificationToken");
var fields = new { __RequestVerificationToken = antiforgerytoken, username = Username, password = Password, remember = Remember, returnurl = ReturnUrl };
@ -71,20 +73,33 @@ private async Task Login()
}
else
{
// client-side Blazor
authstateprovider.NotifyAuthenticationChanged();
UriHelper.NavigateTo(NavigateUrl(ReturnUrl, true));
Message = "<div class=\"alert alert-danger\" role=\"alert\">Login Failed. Please Remember That Passwords Are Case Sensitive.</div>";
}
}
else
{
// client-side Blazor
User user = new User();
user.SiteId = PageState.Site.SiteId;
user.Username = Username;
user.Password = Password;
user = await UserService.LoginUserAsync(user, true, Remember);
if (user.IsAuthenticated)
{
authstateprovider.NotifyAuthenticationChanged();
PageState.Reload = Constants.ReloadSite;
UriHelper.NavigateTo(NavigateUrl(ReturnUrl));
}
else
{
Message = "<div class=\"alert alert-danger\" role=\"alert\">Login Failed. Please Remember That Passwords Are Case Sensitive.</div>";
}
}
}
private void Cancel()
{
string ReturnUrl = PageState.QueryString["returnurl"];
UriHelper.NavigateTo(NavigateUrl(ReturnUrl));
UriHelper.NavigateTo(ReturnUrl);
}
}

View File

@ -0,0 +1,50 @@
@using Microsoft.AspNetCore.Components.Routing
@using Oqtane.Modules.Controls
@using Oqtane.Modules
@using Oqtane.Services
@using Oqtane.Shared
@namespace Oqtane.Modules.Admin.ModuleDefinitions
@inherits ModuleBase
@inject IUriHelper UriHelper
@inject IFileService FileService
@inject IModuleDefinitionService ModuleDefinitionService
<table class="table table-borderless">
<tr>
<td>
<label for="Name" class="control-label">Module: </label>
</td>
<td>
<FileUpload Filter=".nupkg"></FileUpload>
</td>
</tr>
</table>
@if (uploaded)
{
<button type="button" class="btn btn-success" @onclick="InstallFile">Install</button>
}
else
{
<button type="button" class="btn btn-success" @onclick="UploadFile">Upload</button>
}
<NavLink class="btn btn-secondary" href="@NavigateUrl()">Cancel</NavLink>
@code {
public override SecurityAccessLevel SecurityAccessLevel { get { return SecurityAccessLevel.Host; } }
bool uploaded = false;
private async Task UploadFile()
{
await FileService.UploadFilesAsync("Modules");
uploaded = true;
StateHasChanged();
}
private async Task InstallFile()
{
await ModuleDefinitionService.InstallModulesAsync();
PageState.Reload = Constants.ReloadApplication;
UriHelper.NavigateTo(NavigateUrl());
}
}

View File

@ -1,9 +1,9 @@
@using Oqtane.Services
@using Oqtane.Models
@using Oqtane.Modules
@using Oqtane.Client.Modules.Controls
@using Oqtane.Modules.Controls
@namespace Oqtane.Modules.Admin.ModuleDefinitions
@inherits ModuleBase
@inject IModuleDefinitionService ModuleDefinitionService
@if (moduledefinitions == null)
@ -12,7 +12,8 @@
}
else
{
<table class="table">
<ActionLink Action="Add" Text="Install Module" />
<table class="table table-borderless">
<thead>
<tr>
<th>Name</th>
@ -30,11 +31,11 @@ else
}
@code {
public override SecurityAccessLevelEnum SecurityAccessLevel { get { return SecurityAccessLevelEnum.Host; } }
public override SecurityAccessLevel SecurityAccessLevel { get { return SecurityAccessLevel.Host; } }
List<ModuleDefinition> moduledefinitions;
protected override async Task OnInitAsync()
protected override async Task OnInitializedAsync()
{
moduledefinitions = await ModuleDefinitionService.GetModuleDefinitionsAsync();
}

View File

@ -3,14 +3,17 @@
@using Oqtane.Models
@using Oqtane.Modules
@using Oqtane.Shared
@using Oqtane.Client.Modules.Controls
@using Oqtane.Security
@using Oqtane.Modules.Controls
@namespace Oqtane.Modules.Admin.ModuleSettings
@inherits ModuleBase
@inject IUriHelper UriHelper
@inject IThemeService ThemeService
@inject IModuleService ModuleService
@inject IPageModuleService PageModuleService
<table class="form-group">
<table class="table table-borderless">
<thead>
<tr>
<td>
<label for="Title" class="control-label">Title: </label>
@ -19,6 +22,8 @@
<input type="text" name="Title" class="form-control" @bind="@title" />
</td>
</tr>
</thead>
<tbody>
<tr>
<td>
<label for="Container" class="control-label">Container: </label>
@ -35,18 +40,10 @@
</tr>
<tr>
<td>
<label for="ViewPermissions" class="control-label">View Permissions: </label>
<label for="Name" class="control-label">Permissions: </label>
</td>
<td>
<input type="text" name="ViewPermissions" class="form-control" @bind="@viewpermissions" />
</td>
</tr>
<tr>
<td>
<label for="EditPermissions" class="control-label">Edit Permissions: </label>
</td>
<td>
<input type="text" name="EditPermissions" class="form-control" @bind="@editpermissions" />
<PermissionGrid EntityName="Module" Permissions="@permissions" @ref="permissiongrid" @ref:suppressField />
</td>
</tr>
<tr>
@ -62,48 +59,69 @@
</select>
</td>
</tr>
</tbody>
</table>
<button class="btn btn-success" @onclick="@SaveModule">Save</button>
@DynamicComponent
<button type="button" class="btn btn-success" @onclick="@SaveModule">Save</button>
<NavLink class="btn btn-secondary" href="@NavigateUrl()">Cancel</NavLink>
@code {
public override SecurityAccessLevelEnum SecurityAccessLevel { get { return SecurityAccessLevelEnum.Edit; } }
public override SecurityAccessLevel SecurityAccessLevel { get { return SecurityAccessLevel.Edit; } }
public override string Title { get { return "Module Settings"; } }
Dictionary<string, string> containers = new Dictionary<string, string>();
string title;
string containertype;
string viewpermissions;
string editpermissions;
string permissions;
string pageid;
protected override async Task OnInitAsync()
PermissionGrid permissiongrid;
RenderFragment DynamicComponent { get; set; }
object settings;
protected override async Task OnInitializedAsync()
{
title = ModuleState.Title;
containers = ThemeService.GetContainerTypes(await ThemeService.GetThemesAsync());
containertype = ModuleState.ContainerType;
viewpermissions = ModuleState.ViewPermissions;
editpermissions = ModuleState.EditPermissions;
permissions = ModuleState.Permissions;
pageid = ModuleState.PageId.ToString();
DynamicComponent = builder =>
{
Type moduleType = Type.GetType(ModuleState.ModuleType);
if (moduleType != null)
{
builder.OpenComponent(0, moduleType);
builder.AddComponentReferenceCapture(1, inst => { settings = Convert.ChangeType(inst, moduleType); });
builder.CloseComponent();
}
};
}
private async Task SaveModule()
{
Module module = ModuleState;
module.ViewPermissions = viewpermissions;
module.EditPermissions = editpermissions;
module.Permissions = permissiongrid.GetPermissions();
await ModuleService.UpdateModuleAsync(module);
PageModule pagemodule = new PageModule();
pagemodule.PageModuleId = ModuleState.PageModuleId;
pagemodule.PageId = Int32.Parse(pageid);
pagemodule.ModuleId = ModuleState.ModuleId;
PageModule pagemodule = await PageModuleService.GetPageModuleAsync(ModuleState.PageModuleId);
pagemodule.Title = title;
pagemodule.Pane = ModuleState.Pane;
pagemodule.Order = ModuleState.Order;
pagemodule.ContainerType = containertype;
await PageModuleService.UpdatePageModuleAsync(pagemodule);
UriHelper.NavigateTo(NavigateUrl(true));
Type moduleType = Type.GetType(ModuleState.ModuleType);
if (moduleType != null)
{
moduleType.GetMethod("UpdateSettings").Invoke(settings, null); // method must be public in settings component
}
PageState.Reload = Constants.ReloadPage;
UriHelper.NavigateTo(NavigateUrl());
}
}

View File

@ -1,14 +1,19 @@
@using Microsoft.AspNetCore.Components.Routing
@using Oqtane.Modules.Controls
@using Oqtane.Models
@using Oqtane.Services
@using Oqtane.Modules
@using Oqtane.Shared
@using Oqtane.Security
@namespace Oqtane.Modules.Admin.Pages
@inherits ModuleBase
@inject IUriHelper UriHelper
@inject IPageService PageService
@inject IThemeService ThemeService
<table class="form-group">
<ModuleMessage Message="@message" />
<table class="table table-borderless">
<tr>
<td>
<label for="Name" class="control-label">Name: </label>
@ -17,34 +22,44 @@
<input class="form-control" @bind="@name" />
</td>
</tr>
<tr>
<td>
<label for="Name" class="control-label">Path: </label>
</td>
<td>
<input class="form-control" @bind="@path" />
</td>
</tr>
<tr>
<td>
<label for="Name" class="control-label">Parent: </label>
</td>
<td>
<select class="form-control" @bind="@parentid">
<option value="">&lt;Select Parent&gt;</option>
@foreach (Page p in PageState.Pages)
<select class="form-control" @onchange="@(e => ParentChanged(e))">
<option value="">&lt;Site Root&gt;</option>
@foreach (Page page in pages)
{
<option value="@p.PageId">@p.Name</option>
<option value="@(page.PageId)">@(new string('-',page.Level * 2))@(page.Name)</option>
}
</select>
</td>
</tr>
<tr>
<td>
<label for="Name" class="control-label">Order: </label>
<label for="Name" class="control-label">Insert: </label>
</td>
<td>
<input class="form-control" @bind="@order" />
<select class="form-control" @bind="@insert">
<option value="<<">At Beginning</option>
@if (children != null && children.Count > 0)
{
<option value="<">Before</option>
<option value=">">After</option>
}
<option value=">>" selected>At End</option>
</select>
@if (children != null && children.Count > 0 && (insert == "<" || insert == ">"))
{
<select class="form-control" @bind="@childid">
<option value="-1">&lt;Select Page&gt;</option>
@foreach (Page page in children)
{
<option value="@(page.PageId)">@(page.Name)</option>
}
</select>
}
</td>
</tr>
<tr>
@ -53,8 +68,19 @@
</td>
<td>
<select class="form-control" @bind="@isnavigation">
<option value="true">Yes</option>
<option value="false">No</option>
<option value="True">Yes</option>
<option value="False">No</option>
</select>
</td>
</tr>
<tr>
<td>
<label for="Name" class="control-label">Edit Mode? </label>
</td>
<td>
<select class="form-control" @bind="@editmode">
<option value="True">Yes</option>
<option value="False">No</option>
</select>
</td>
</tr>
@ -96,66 +122,122 @@
</tr>
<tr>
<td>
<label for="Name" class="control-label">View Permissions: </label>
<label for="Name" class="control-label">Permissions: </label>
</td>
<td>
<input class="form-control" @bind="@viewpermissions" />
</td>
</tr>
<tr>
<td>
<label for="Name" class="control-label">Edit Permissions: </label>
</td>
<td>
<input class="form-control" @bind="@editpermissions" />
<PermissionGrid EntityName="Page" Permissions="@permissions" @ref="permissiongrid" @ref:suppressField />
</td>
</tr>
</table>
<button class="btn btn-success" @onclick="@SavePage">Save</button>
<button type="button" class="btn btn-success" @onclick="@SavePage">Save</button>
<NavLink class="btn btn-secondary" href="@NavigateUrl()">Cancel</NavLink>
@code {
public override SecurityAccessLevelEnum SecurityAccessLevel { get { return SecurityAccessLevelEnum.Admin; } }
public override SecurityAccessLevel SecurityAccessLevel { get { return SecurityAccessLevel.Admin; } }
string message = "";
Dictionary<string, string> themes = new Dictionary<string, string>();
Dictionary<string, string> panelayouts = new Dictionary<string, string>();
List<Page> pages;
string name;
string path;
string parentid;
string order = "";
string insert;
List<Page> children;
int childid = -1;
string isnavigation = "True";
string editmode = "False";
string themetype;
string layouttype = "";
string icon = "";
string viewpermissions = "All Users";
string editpermissions = "Administrators";
string permissions = ""; // need to set default permissions
protected override void OnInit()
PermissionGrid permissiongrid;
protected override void OnInitialized()
{
try
{
pages = PageState.Pages.Where(item => item.IsNavigation).ToList();
children = PageState.Pages.Where(item => item.ParentId == null && item.IsNavigation).OrderBy(item => item.Order).ToList();
themes = ThemeService.GetThemeTypes(PageState.Themes);
panelayouts = ThemeService.GetPaneLayoutTypes(PageState.Themes);
List<PermissionString> permissionstrings = new List<PermissionString>();
permissionstrings.Add(new PermissionString { PermissionName = "View", Permissions = Constants.AdminRole });
permissionstrings.Add(new PermissionString { PermissionName = "Edit", Permissions = Constants.AdminRole });
permissions = UserSecurity.SetPermissionStrings(permissionstrings);
}
catch (Exception ex)
{
message = ex.Message;
}
}
private void ParentChanged(UIChangeEventArgs e)
{
try
{
parentid = (string)e.Value;
if (string.IsNullOrEmpty(parentid))
{
children = PageState.Pages.Where(item => item.ParentId == null && item.IsNavigation).OrderBy(item => item.Order).ToList();
}
else
{
children = PageState.Pages.Where(item => item.ParentId == int.Parse(parentid) && item.IsNavigation).OrderBy(item => item.Order).ToList();
}
StateHasChanged();
}
catch (Exception ex)
{
message = ex.Message;
}
}
private async Task SavePage()
{
Page p = new Page();
p.SiteId = PageState.Page.SiteId;
try
{
Page page = new Page();
page.SiteId = PageState.Page.SiteId;
page.Name = name;
if (string.IsNullOrEmpty(parentid))
{
p.ParentId = null;
page.ParentId = null;
page.Path = page.Name.ToLower();
}
else
{
p.ParentId = Int32.Parse(parentid);
page.ParentId = Int32.Parse(parentid);
Page parent = PageState.Pages.Where(item => item.ParentId == page.ParentId).FirstOrDefault();
page.Path = parent.Path + "/" + page.Name.ToLower();
}
p.Name = name;
p.Path = path;
p.Order = (order == null ? 1 : Int32.Parse(order));
p.IsNavigation = (isnavigation == null ? true : Boolean.Parse(isnavigation));
p.ThemeType = themetype;
p.LayoutType = (layouttype == null ? "" : layouttype);
p.Icon = (icon == null ? "" : icon);
Page child;
switch (insert)
{
case "<<":
page.Order = 0;
break;
case "<":
child = PageState.Pages.Where(item => item.PageId == childid).FirstOrDefault();
page.Order = child.Order - 1;
break;
case ">":
child = PageState.Pages.Where(item => item.PageId == childid).FirstOrDefault();
page.Order = child.Order + 1;
break;
case ">>":
page.Order = int.MaxValue;
break;
}
page.IsNavigation = (isnavigation == null ? true : Boolean.Parse(isnavigation));
page.EditMode = (editmode == null ? true : Boolean.Parse(editmode));
page.ThemeType = themetype;
page.LayoutType = (layouttype == null ? "" : layouttype);
page.Icon = (icon == null ? "" : icon);
Type type;
if (!string.IsNullOrEmpty(layouttype))
{
@ -166,10 +248,18 @@
type = Type.GetType(themetype);
}
System.Reflection.PropertyInfo property = type.GetProperty("Panes");
p.Panes = (string)property.GetValue(Activator.CreateInstance(type), null);
p.ViewPermissions = viewpermissions;
p.EditPermissions = editpermissions;
await PageService.AddPageAsync(p);
UriHelper.NavigateTo(NavigateUrl(path, true));
page.Panes = (string)property.GetValue(Activator.CreateInstance(type), null);
page.Permissions = permissiongrid.GetPermissions();
await PageService.AddPageAsync(page);
await PageService.UpdatePageOrderAsync(page.SiteId, page.ParentId);
PageState.Reload = Constants.ReloadSite;
UriHelper.NavigateTo(NavigateUrl());
}
catch (Exception ex)
{
message = ex.Message;
}
}
}

View File

@ -1,14 +1,19 @@
@using Microsoft.AspNetCore.Components.Routing
@using Oqtane.Modules.Controls
@using Oqtane.Models
@using Oqtane.Services
@using Oqtane.Modules
@using Oqtane.Shared
@using Oqtane.Security
@namespace Oqtane.Modules.Admin.Pages
@inherits ModuleBase
@inject IUriHelper UriHelper
@inject IPageService PageService
@inject IThemeService ThemeService
<table class="form-group">
<ModuleMessage Message="@message" />
<table class="table table-borderless">
<tr>
<td>
<label for="Name" class="control-label">Name: </label>
@ -39,22 +44,25 @@
</select>
</td>
</tr>
<tr>
<td>
<label for="Name" class="control-label">Order: </label>
</td>
<td>
<input class="form-control" @bind="@order" readonly />
</td>
</tr>
<tr>
<td>
<label for="Name" class="control-label">Navigation? </label>
</td>
<td>
<select class="form-control" @bind="@isnavigation" readonly>
<option value="true">Yes</option>
<option value="false">No</option>
<option value="True">Yes</option>
<option value="False">No</option>
</select>
</td>
</tr>
<tr>
<td>
<label for="Name" class="control-label">Edit Mode? </label>
</td>
<td>
<select class="form-control" @bind="@editmode" readonly>
<option value="True">Yes</option>
<option value="False">No</option>
</select>
</td>
</tr>
@ -63,7 +71,7 @@
<label for="Name" class="control-label">Theme: </label>
</td>
<td>
<select class="form-control" @bind="@themetype">
<select class="form-control" @bind="@themetype" readonly>
<option value="">&lt;Select Theme&gt;</option>
@foreach (KeyValuePair<string, string> item in themes)
{
@ -77,7 +85,7 @@
<label for="Name" class="control-label">Layout: </label>
</td>
<td>
<select class="form-control" @bind="@layouttype">
<select class="form-control" @bind="@layouttype" readonly>
<option value="">&lt;Select Layout&gt;</option>
@foreach (KeyValuePair<string, string> panelayout in panelayouts)
{
@ -96,26 +104,23 @@
</tr>
<tr>
<td>
<label for="Name" class="control-label">View Permissions: </label>
<label for="Name" class="control-label">Permissions: </label>
</td>
<td>
<input class="form-control" @bind="@viewpermissions" readonly />
</td>
</tr>
<tr>
<td>
<label for="Name" class="control-label">Edit Permissions: </label>
</td>
<td>
<input class="form-control" @bind="@editpermissions" readonly />
<PermissionGrid EntityName="Page" Permissions="@permissions" @ref="permissiongrid" @ref:suppressField />
</td>
</tr>
</table>
<button class="btn btn-danger" @onclick="@DeletePage">Delete</button>
<button type="button" class="btn btn-danger" @onclick="@DeletePage">Delete</button>
<NavLink class="btn btn-secondary" href="@NavigateUrl()">Cancel</NavLink>
<br />
<br />
<AuditInfo CreatedBy="@createdby" CreatedOn="@createdon" ModifiedBy="@modifiedby" ModifiedOn="@modifiedon"></AuditInfo>
@code {
public override SecurityAccessLevelEnum SecurityAccessLevel { get { return SecurityAccessLevelEnum.Admin; } }
public override SecurityAccessLevel SecurityAccessLevel { get { return SecurityAccessLevel.Admin; } }
string message = "";
Dictionary<string, string> themes = new Dictionary<string, string>();
Dictionary<string, string> panelayouts = new Dictionary<string, string>();
@ -124,39 +129,68 @@
string name;
string path;
string parentid;
string order;
string isnavigation;
string editmode;
string themetype;
string layouttype;
string icon;
string viewpermissions;
string editpermissions;
string permissions;
string createdby;
DateTime createdon;
string modifiedby;
DateTime modifiedon;
protected override void OnInit()
PermissionGrid permissiongrid;
protected override void OnInitialized()
{
try
{
themes = ThemeService.GetThemeTypes(PageState.Themes);
panelayouts = ThemeService.GetPaneLayoutTypes(PageState.Themes);
PageId = Int32.Parse(PageState.QueryString["id"]);
Page p = PageState.Pages.Where(item => item.PageId == PageId).FirstOrDefault();
if (p != null)
Page page = PageState.Pages.Where(item => item.PageId == PageId).FirstOrDefault();
if (page != null)
{
name = p.Name;
path = p.Path;
order = p.Order.ToString();
isnavigation = p.IsNavigation.ToString();
themetype = p.ThemeType;
layouttype = p.LayoutType;
icon = p.Icon;
viewpermissions = p.ViewPermissions;
editpermissions = p.EditPermissions;
name = page.Name;
path = page.Path;
isnavigation = page.IsNavigation.ToString();
editmode = page.EditMode.ToString();
themetype = page.ThemeType;
layouttype = page.LayoutType;
icon = page.Icon;
permissions = page.Permissions;
createdby = page.CreatedBy;
createdon = page.CreatedOn;
modifiedby = page.ModifiedBy;
modifiedon = page.ModifiedOn;
}
}
catch (Exception ex)
{
message = ex.Message;
}
}
private async Task DeletePage()
{
try
{
await PageService.DeletePageAsync(Int32.Parse(PageState.QueryString["id"]));
UriHelper.NavigateTo(NavigateUrl("", true));
PageState.Reload = Constants.ReloadSite;
if (PageState.Page.Name == "Page Management")
{
UriHelper.NavigateTo(NavigateUrl());
}
else
{
UriHelper.NavigateTo(NavigateUrl(""));
}
}
catch (Exception ex)
{
message = ex.Message;
}
}
}

View File

@ -1,15 +1,19 @@
@using Microsoft.AspNetCore.Components.Routing
@using Oqtane.Modules.Controls
@using Oqtane.Models
@using Oqtane.Services
@using Oqtane.Modules
@using Oqtane.Shared
@using Oqtane.Client.Modules.Controls
@using Oqtane.Security
@namespace Oqtane.Modules.Admin.Pages
@inherits ModuleBase
@inject IUriHelper UriHelper
@inject IPageService PageService
@inject IThemeService ThemeService
<table class="form-group">
<ModuleMessage Message="@message" />
<table class="table table-borderless">
<tr>
<td>
<label for="Name" class="control-label">Name: </label>
@ -23,7 +27,7 @@
<label for="Name" class="control-label">Path: </label>
</td>
<td>
<input class="form-control" @bind="@path" />
<input class="form-control" @bind="@path" readonly />
</td>
</tr>
<tr>
@ -31,21 +35,40 @@
<label for="Name" class="control-label">Parent: </label>
</td>
<td>
<select class="form-control" @bind="@parentid">
<option value="">&lt;Select Parent&gt;</option>
@foreach (Page p in PageState.Pages)
<select class="form-control" @onchange="@(e => ParentChanged(e))">
<option value="">&lt;Site Root&gt;</option>
@foreach (Page page in pages)
{
<option value="@p.PageId">@p.Name</option>
<option value="@(page.PageId)">@(new string('-', page.Level * 2))@(page.Name)</option>
}
</select>
</td>
</tr>
<tr>
<td>
<label for="Name" class="control-label">Order: </label>
<label for="Name" class="control-label">Move : </label>
</td>
<td>
<input class="form-control" @bind="@order" />
<select class="form-control" @bind="@insert">
<option value="">&lt;Maintain Current Location&gt;</option>
<option value="<<">To Beginning</option>
@if (children != null && children.Count > 0)
{
<option value="<">Before</option>
<option value=">">After</option>
}
<option value=">>" selected>To End</option>
</select>
@if (children != null && children.Count > 0 && (insert == "<" || insert == ">"))
{
<select class="form-control" @bind="@childid">
<option value="-1">&lt;Select Page&gt;</option>
@foreach (Page page in children)
{
<option value="@(page.PageId)">@(page.Name)</option>
}
</select>
}
</td>
</tr>
<tr>
@ -54,8 +77,19 @@
</td>
<td>
<select class="form-control" @bind="@isnavigation">
<option value="true">Yes</option>
<option value="false">No</option>
<option value="True">Yes</option>
<option value="False">No</option>
</select>
</td>
</tr>
<tr>
<td>
<label for="Name" class="control-label">Edit Mode? </label>
</td>
<td>
<select class="form-control" @bind="@editmode">
<option value="True">Yes</option>
<option value="False">No</option>
</select>
</td>
</tr>
@ -97,90 +131,156 @@
</tr>
<tr>
<td>
<label for="Name" class="control-label">View Permissions: </label>
<label for="Name" class="control-label">Permissions: </label>
</td>
<td>
<input class="form-control" @bind="@viewpermissions" />
</td>
</tr>
<tr>
<td>
<label for="Name" class="control-label">Edit Permissions: </label>
</td>
<td>
<input class="form-control" @bind="@editpermissions" />
<PermissionGrid EntityName="Page" Permissions="@permissions" @ref="permissiongrid" @ref:suppressField />
</td>
</tr>
</table>
<button class="btn btn-success" @onclick="@SavePage">Save</button>
<button type="button" class="btn btn-success" @onclick="@SavePage">Save</button>
<NavLink class="btn btn-secondary" href="@NavigateUrl()">Cancel</NavLink>
<br />
<br />
<AuditInfo CreatedBy="@createdby" CreatedOn="@createdon" ModifiedBy="@modifiedby" ModifiedOn="@modifiedon"></AuditInfo>
@code {
public override SecurityAccessLevelEnum SecurityAccessLevel { get { return SecurityAccessLevelEnum.Admin; } }
public override SecurityAccessLevel SecurityAccessLevel { get { return SecurityAccessLevel.Admin; } }
string message = "";
Dictionary<string, string> themes = new Dictionary<string, string>();
Dictionary<string, string> panelayouts = new Dictionary<string, string>();
List<Page> pages;
int PageId;
string name;
string path;
string parentid;
string order;
string insert = "";
List<Page> children;
int childid = -1;
string isnavigation;
string editmode;
string themetype;
string layouttype;
string icon;
string viewpermissions;
string editpermissions;
string permissions;
string createdby;
DateTime createdon;
string modifiedby;
DateTime modifiedon;
protected override void OnInit()
PermissionGrid permissiongrid;
protected override void OnInitialized()
{
try
{
pages = PageState.Pages.Where(item => item.IsNavigation).ToList();
children = PageState.Pages.Where(item => item.ParentId == null && item.IsNavigation).OrderBy(item => item.Order).ToList();
themes = ThemeService.GetThemeTypes(PageState.Themes);
panelayouts = ThemeService.GetPaneLayoutTypes(PageState.Themes);
PageId = Int32.Parse(PageState.QueryString["id"]);
Page p = PageState.Pages.Where(item => item.PageId == PageId).FirstOrDefault();
if (p != null)
Page page = PageState.Pages.Where(item => item.PageId == PageId).FirstOrDefault();
if (page != null)
{
name = p.Name;
path = p.Path;
if (p.ParentId == null)
name = page.Name;
path = page.Path;
if (page.ParentId == null)
{
parentid = "";
}
else
{
parentid = p.ParentId.ToString();
parentid = page.ParentId.ToString();
}
order = p.Order.ToString();
isnavigation = p.IsNavigation.ToString();
themetype = p.ThemeType;
layouttype = p.LayoutType;
icon = p.Icon;
viewpermissions = p.ViewPermissions;
editpermissions = p.EditPermissions;
isnavigation = page.IsNavigation.ToString();
editmode = page.EditMode.ToString();
themetype = page.ThemeType;
layouttype = page.LayoutType;
icon = page.Icon;
permissions = page.Permissions;
createdby = page.CreatedBy;
createdon = page.CreatedOn;
modifiedby = page.ModifiedBy;
modifiedon = page.ModifiedOn;
}
}
catch (Exception ex)
{
message = ex.Message;
}
}
private void ParentChanged(UIChangeEventArgs e)
{
try
{
parentid = (string)e.Value;
if (string.IsNullOrEmpty(parentid))
{
children = PageState.Pages.Where(item => item.ParentId == null && item.IsNavigation).OrderBy(item => item.Order).ToList();
}
else
{
children = PageState.Pages.Where(item => item.ParentId == int.Parse(parentid) && item.IsNavigation).OrderBy(item => item.Order).ToList();
}
StateHasChanged();
}
catch (Exception ex)
{
message = ex.Message;
}
}
private async Task SavePage()
{
Page p = PageState.Page;
p.PageId = Int32.Parse(PageState.QueryString["id"]);
try
{
Page page = PageState.Page;
int? currentparentid = page.ParentId;
page.PageId = Int32.Parse(PageState.QueryString["id"]);
page.Name = name;
if (string.IsNullOrEmpty(parentid))
{
p.ParentId = null;
page.ParentId = null;
page.Path = page.Name.ToLower();
}
else
{
p.ParentId = Int32.Parse(parentid);
page.ParentId = Int32.Parse(parentid);
Page parent = PageState.Pages.Where(item => item.ParentId == page.ParentId).FirstOrDefault();
page.Path = parent.Path + "/" + page.Name.ToLower();
}
p.Name = name;
p.Path = path;
p.Order = (order == null ? 1 : Int32.Parse(order));
p.IsNavigation = (isnavigation == null ? true : Boolean.Parse(isnavigation));
p.ThemeType = themetype;
p.LayoutType = (layouttype == null ? "" : layouttype);
p.Icon = (icon == null ? "" : icon);
if (insert != "")
{
Page child;
switch (insert)
{
case "<<":
page.Order = 0;
break;
case "<":
child = PageState.Pages.Where(item => item.PageId == childid).FirstOrDefault();
page.Order = child.Order - 1;
break;
case ">":
child = PageState.Pages.Where(item => item.PageId == childid).FirstOrDefault();
page.Order = child.Order + 1;
break;
case ">>":
page.Order = int.MaxValue;
break;
}
}
page.IsNavigation = (isnavigation == null ? true : Boolean.Parse(isnavigation));
page.EditMode = (editmode == null ? true : Boolean.Parse(editmode));
page.ThemeType = themetype;
page.LayoutType = (layouttype == null ? "" : layouttype);
page.Icon = (icon == null ? "" : icon);
Type type;
if (!string.IsNullOrEmpty(layouttype))
{
@ -191,10 +291,18 @@
type = Type.GetType(themetype);
}
System.Reflection.PropertyInfo property = type.GetProperty("Panes");
p.Panes = (string)property.GetValue(Activator.CreateInstance(type), null);
p.ViewPermissions = viewpermissions;
p.EditPermissions = editpermissions;
await PageService.UpdatePageAsync(p);
UriHelper.NavigateTo(NavigateUrl(path));
page.Panes = (string)property.GetValue(Activator.CreateInstance(type), null);
page.Permissions = permissiongrid.GetPermissions();
await PageService.UpdatePageAsync(page);
await PageService.UpdatePageOrderAsync(page.SiteId, page.ParentId);
await PageService.UpdatePageOrderAsync(page.SiteId, currentparentid);
PageState.Reload = Constants.ReloadSite;
UriHelper.NavigateTo(NavigateUrl());
}
catch (Exception ex)
{
message = ex.Message;
}
}
}

View File

@ -1,40 +1,36 @@
@using Oqtane.Services
@using Oqtane.Modules.Controls
@using Oqtane.Services
@using Oqtane.Models
@using Oqtane.Modules
@using Oqtane.Client.Modules.Controls
@using Oqtane.Shared
@namespace Oqtane.Modules.Admin.Pages
@inherits ModuleBase
@inject IPageService PageService
@if (PageState.Pages == null)
@if (PageState.Pages != null)
{
<p><em>Loading...</em></p>
}
else
{
<table class="table">
<ActionLink Action="Add" Text="Add Page" />
<table class="table table-borderless">
<thead>
<tr>
<th> </th>
<th>Path</th>
<th>&nbsp;</th>
<th>&nbsp;</th>
<th>Name</th>
</tr>
</thead>
<tbody>
@foreach (var p in PageState.Pages)
@foreach (Page page in PageState.Pages)
{
<tr>
<td><ActionLink Action="Edit" Parameters="@($"id=" + p.PageId.ToString())" /></td>
<td><ActionLink Action="Delete" Parameters="@($"id=" + p.PageId.ToString())" ButtonClass="btn-danger" /></td>
<td>@p.Path</td>
<td>@p.Name</td>
<td><ActionLink Action="Edit" Parameters="@($"id=" + page.PageId.ToString())" /></td>
<td><ActionLink Action="Delete" Parameters="@($"id=" + page.PageId.ToString())" Class="btn btn-danger" /></td>
<td>@(new string('-', page.Level * 2))@(page.Name)</td>
</tr>
}
</tbody>
</table>
<ActionLink Action="Add" Text="Add Page" />
}
@code {
public override SecurityAccessLevelEnum SecurityAccessLevel { get { return SecurityAccessLevelEnum.Admin; } }
public override SecurityAccessLevel SecurityAccessLevel { get { return SecurityAccessLevel.Admin; } }
}

View File

@ -0,0 +1,128 @@
@using Microsoft.AspNetCore.Components.Routing
@using Oqtane.Modules.Controls
@using Oqtane.Modules
@using Oqtane.Models
@using Oqtane.Services
@namespace Oqtane.Modules.Admin.Profile
@inherits ModuleBase
@inject IUriHelper UriHelper
@inject IUserService UserService
@inject IProfileService ProfileService
@inject ISettingService SettingService
<ModuleMessage Message="@message" />
@if (PageState.User != null && profiles != null)
{
<table class="table table-borderless">
<tr>
<td>
<label for="Name" class="control-label">Name: </label>
</td>
<td>
<input class="form-control" @bind="@displayname" />
</td>
</tr>
<tr>
<td>
<label for="Name" class="control-label">Email: </label>
</td>
<td>
<input class="form-control" @bind="@email" />
</td>
</tr>
@foreach (Profile profile in profiles)
{
var p = profile;
if (p.Category != category)
{
<tr>
<th colspan="2" style="text-align: center;">
@p.Category
</th>
</tr>
category = p.Category;
}
<tr>
<td>
<label for="@p.Name" class="control-label">@p.Title: </label>
</td>
<td>
<input class="form-control" maxlength="@p.MaxLength" value="@GetProfileValue(p.Name, p.DefaultValue)" placeholder="@p.Description" @onchange="@(e => ProfileChanged(e, p.Name))" />
</td>
</tr>
}
</table>
<button type="button" class="btn btn-primary" @onclick="@SaveUser">Save</button>
<button type="button" class="btn btn-secondary" @onclick="@Cancel">Cancel</button>
<br />
<br />
}
@code {
public override SecurityAccessLevel SecurityAccessLevel { get { return SecurityAccessLevel.View; } }
string message = "";
string displayname = "";
string email = "";
List<Profile> profiles;
Dictionary<string, string> settings;
string category = "";
protected override async Task OnInitializedAsync()
{
try
{
if (PageState.User != null)
{
displayname = PageState.User.DisplayName;
email = PageState.User.Email;
profiles = await ProfileService.GetProfilesAsync(ModuleState.SiteId);
settings = await SettingService.GetUserSettingsAsync(PageState.User.UserId);
}
else
{
message = "Current User Is Not Logged In";
}
}
catch (Exception ex)
{
message = ex.Message;
}
}
private string GetProfileValue(string SettingName, string DefaultValue)
{
return SettingService.GetSetting(settings, SettingName, DefaultValue);
}
private async Task SaveUser()
{
try
{
User user = PageState.User;
user.DisplayName = displayname;
user.Email = email;
await UserService.UpdateUserAsync(user);
await SettingService.UpdateUserSettingsAsync(settings, PageState.User.UserId);
UriHelper.NavigateTo("");
}
catch (Exception ex)
{
message = ex.Message;
}
}
private void Cancel()
{
UriHelper.NavigateTo(NavigateUrl(""));
}
private void ProfileChanged(UIChangeEventArgs e, string SettingName)
{
string value = (string)e.Value;
settings = SettingService.SetSetting(settings, SettingName, value);
}
}

View File

@ -2,6 +2,7 @@
@using Oqtane.Modules
@using Oqtane.Models
@using Oqtane.Services
@namespace Oqtane.Modules.Admin.Register
@inherits ModuleBase
@inject IUriHelper UriHelper
@inject IUserService UserService
@ -9,31 +10,37 @@
<div class="container">
<div class="form-group">
<label for="Username" class="control-label">Email: </label>
<input type="text" name="Username" class="form-control" placeholder="Username" @bind="@Username" />
<input type="text" name="Username" class="form-control" placeholder="Username" @bind="@Email" />
</div>
<div class="form-group">
<label for="Password" class="control-label">Password: </label>
<input type="password" name="Password" class="form-control" placeholder="Password" @bind="@Password" />
</div>
<button type="button" class="btn btn-primary" @onclick="@RegisterUser">Register</button>
<NavLink class="btn btn-secondary" href="/">Cancel</NavLink>
<button type="button" class="btn btn-secondary" @onclick="@Cancel">Cancel</button>
</div>
@code {
public override SecurityAccessLevelEnum SecurityAccessLevel { get { return SecurityAccessLevelEnum.Anonymous; } }
public override SecurityAccessLevel SecurityAccessLevel { get { return SecurityAccessLevel.Anonymous; } }
public string Username { get; set; } = "";
public string Email { get; set; } = "";
public string Password { get; set; } = "";
private async Task RegisterUser()
{
User user = new User();
user.Username = Username;
user.DisplayName = Username;
user.Roles = "Administrators;";
user.IsSuperUser = false;
user.SiteId = PageState.Site.SiteId;
user.Username = Email;
user.DisplayName = Email;
user.Email = Email;
user.IsHost = false;
user.Password = Password;
await UserService.AddUserAsync(user);
UriHelper.NavigateTo("");
}
private void Cancel()
{
UriHelper.NavigateTo(NavigateUrl("")); // navigate to home
}
}

View File

@ -0,0 +1,41 @@
@using Oqtane.Services
@using Oqtane.Models
@using Oqtane.Modules
@using Oqtane.Modules.Controls
@namespace Oqtane.Modules.Admin.Roles
@inherits ModuleBase
@inject IRoleService RoleService
@if (Roles == null)
{
<p><em>Loading...</em></p>
}
else
{
<table class="table table-borderless">
<thead>
<tr>
<th>Name</th>
</tr>
</thead>
<tbody>
@foreach (var Role in Roles)
{
<tr>
<td>@Role.Name</td>
</tr>
}
</tbody>
</table>
}
@code {
public override SecurityAccessLevel SecurityAccessLevel { get { return SecurityAccessLevel.Admin; } }
List<Role> Roles;
protected override async Task OnInitializedAsync()
{
Roles = await RoleService.GetRolesAsync(PageState.Site.SiteId);
}
}

View File

@ -2,6 +2,9 @@
@using Oqtane.Models
@using Oqtane.Services
@using Oqtane.Modules
@using Oqtane.Shared
@using Oqtane.Security
@namespace Oqtane.Modules.Admin.Sites
@inherits ModuleBase
@inject IUriHelper UriHelper
@inject ITenantService TenantService
@ -15,7 +18,7 @@
}
else
{
<table class="form-group">
<table class="table table-borderless">
<tr>
<td>
<label for="Name" class="control-label">Tenant: </label>
@ -55,12 +58,12 @@ else
</td>
</tr>
</table>
<button class="btn btn-success" @onclick="@SaveSite">Save</button>
<button type="button" class="btn btn-success" @onclick="@SaveSite">Save</button>
<NavLink class="btn btn-secondary" href="@NavigateUrl()">Cancel</NavLink>
}
@code {
public override SecurityAccessLevelEnum SecurityAccessLevel { get { return SecurityAccessLevelEnum.Host; } }
public override SecurityAccessLevel SecurityAccessLevel { get { return SecurityAccessLevel.Host; } }
List<Tenant> tenants;
string tenantid;
@ -68,7 +71,7 @@ else
string url;
string logo;
protected override async Task OnInitAsync()
protected override async Task OnInitializedAsync()
{
tenants = await TenantService.GetTenantsAsync();
}
@ -96,14 +99,18 @@ else
p.Path = "";
p.Order = 1;
p.IsNavigation = true;
p.ThemeType = "Oqtane.Client.Themes.Theme1.Theme1, Oqtane.Client";
p.ThemeType = PageState.Site.DefaultThemeType;
p.LayoutType = "";
p.Icon = "";
Type type = Type.GetType(p.ThemeType);
System.Reflection.PropertyInfo property = type.GetProperty("Panes");
p.Panes = (string)property.GetValue(Activator.CreateInstance(type), null);
p.ViewPermissions = "All Users";
p.EditPermissions = "Administrators";
List<PermissionString> permissionstrings = new List<PermissionString>();
permissionstrings.Add(new PermissionString { PermissionName = "View", Permissions = Constants.AllUsersRole });
permissionstrings.Add(new PermissionString { PermissionName = "Edit", Permissions = Constants.AdminRole });
p.Permissions = UserSecurity.SetPermissionStrings(permissionstrings);
await PageService.AddPageAsync(p);
UriHelper.NavigateTo(url, true);

View File

@ -1,7 +1,8 @@
@using Oqtane.Services
@using Oqtane.Models
@using Oqtane.Modules
@using Oqtane.Client.Modules.Controls
@using Oqtane.Modules.Controls
@namespace Oqtane.Modules.Admin.Sites
@inherits ModuleBase
@inject ISiteService SiteService
@ -12,7 +13,7 @@
}
else
{
<table class="table">
<table class="table table-borderless">
<thead>
<tr>
<th>Name</th>
@ -31,11 +32,11 @@ else
}
@code {
public override SecurityAccessLevelEnum SecurityAccessLevel { get { return SecurityAccessLevelEnum.Host; } }
public override SecurityAccessLevel SecurityAccessLevel { get { return SecurityAccessLevel.Host; } }
List<Site> sites;
protected override async Task OnInitAsync()
protected override async Task OnInitializedAsync()
{
sites = await SiteService.GetSitesAsync();
}

View File

@ -1,6 +1,7 @@
@using Oqtane.Services
@using Oqtane.Models
@using Oqtane.Modules
@namespace Oqtane.Modules.Admin.Themes
@inherits ModuleBase
@inject IThemeService ThemeService
@ -11,7 +12,7 @@
}
else
{
<table class="table">
<table class="table table-borderless">
<thead>
<tr>
<th>Name</th>
@ -29,11 +30,11 @@ else
}
@code {
public override SecurityAccessLevelEnum SecurityAccessLevel { get { return SecurityAccessLevelEnum.Host; } }
public override SecurityAccessLevel SecurityAccessLevel { get { return SecurityAccessLevel.Host; } }
List<Theme> Themes;
protected override async Task OnInitAsync()
protected override async Task OnInitializedAsync()
{
Themes = await ThemeService.GetThemesAsync();
}

View File

@ -1,7 +1,8 @@
@using Oqtane.Services
@using Oqtane.Models
@using Oqtane.Modules
@using Oqtane.Client.Modules.Controls
@using Oqtane.Modules.Controls
@namespace Oqtane.Modules.Admin.Users
@inherits ModuleBase
@inject IUserService UserService
@ -30,12 +31,12 @@ else
}
@code {
public override SecurityAccessLevelEnum SecurityAccessLevel { get { return SecurityAccessLevelEnum.Host; } }
public override SecurityAccessLevel SecurityAccessLevel { get { return SecurityAccessLevel.Admin; } }
List<User> Users;
protected override async Task OnInitAsync()
protected override async Task OnInitializedAsync()
{
Users = await UserService.GetUsersAsync();
Users = await UserService.GetUsersAsync(PageState.Site.SiteId);
}
}

View File

@ -2,34 +2,40 @@
@using Oqtane.Modules
@using Oqtane.Services
@using Oqtane.Shared
@using Oqtane.Security
@namespace Oqtane.Modules.Controls
@inherits ModuleBase
@inject IUserService UserService
@if (authorized)
{
<NavLink class="@buttonClass" href="@url">@text</NavLink>
<NavLink class="@classname" href="@url" style="@style">@text</NavLink>
}
@code {
[Parameter]
private string Action { get; set; }
public string Action { get; set; }
[Parameter]
private string Text { get; set; } // optional
public string Text { get; set; } // optional
[Parameter]
private string Parameters { get; set; } // optional
public string Parameters { get; set; } // optional
[Parameter]
private string ButtonClass { get; set; } // optional
public string Class { get; set; } // optional
[Parameter]
public string Style { get; set; } // optional
string text = "";
string url = "";
string parameters = "";
string buttonClass = "btn btn-primary";
string classname = "btn btn-primary";
string style = "";
bool authorized = false;
protected override void OnInit()
protected override void OnParametersSet()
{
text = Action;
if (!String.IsNullOrEmpty(Text))
@ -42,37 +48,45 @@
parameters = Parameters;
}
if (!string.IsNullOrEmpty(ButtonClass))
if (!string.IsNullOrEmpty(Class))
{
buttonClass = "btn " + ButtonClass;
classname = Class;
}
if (!string.IsNullOrEmpty(Style))
{
style = Style;
}
url = EditUrl(Action, parameters);
if (PageState.EditMode)
{
string typename = ModuleState.ModuleType.Replace(Utilities.GetTypeNameClass(ModuleState.ModuleType) + ",", Action + ",");
Type moduleType = Type.GetType(typename);
if (moduleType != null)
{
var moduleobject = Activator.CreateInstance(moduleType);
SecurityAccessLevelEnum SecurityAccessLevel = (SecurityAccessLevelEnum)moduleType.GetProperty("SecurityAccessLevel").GetValue(moduleobject, null);
SecurityAccessLevel SecurityAccessLevel = (SecurityAccessLevel)moduleType.GetProperty("SecurityAccessLevel").GetValue(moduleobject, null);
switch (SecurityAccessLevel)
{
case SecurityAccessLevelEnum.Anonymous:
case SecurityAccessLevel.Anonymous:
authorized = true;
break;
case SecurityAccessLevelEnum.View:
authorized = UserService.IsAuthorized(PageState.User, ModuleState.ViewPermissions);
case SecurityAccessLevel.View:
authorized = UserSecurity.IsAuthorized(PageState.User, "View", ModuleState.Permissions);
break;
case SecurityAccessLevelEnum.Edit:
authorized = UserService.IsAuthorized(PageState.User, ModuleState.EditPermissions);
case SecurityAccessLevel.Edit:
authorized = UserSecurity.IsAuthorized(PageState.User, "Edit", ModuleState.Permissions);
break;
case SecurityAccessLevelEnum.Admin:
authorized = UserService.IsAuthorized(PageState.User, Constants.AdminRole);
case SecurityAccessLevel.Admin:
authorized = UserSecurity.IsAuthorized(PageState.User, Constants.AdminRole);
break;
case SecurityAccessLevelEnum.Host:
authorized = PageState.User.IsSuperUser;
case SecurityAccessLevel.Host:
authorized = UserSecurity.IsAuthorized(PageState.User, Constants.HostRole);
break;
}
}
}
}
}

View File

@ -0,0 +1,59 @@
@using Oqtane.Modules
@namespace Oqtane.Modules.Controls
@inherits ModuleBase
@if (text != "")
{
@((MarkupString)@text)
}
@code {
[Parameter]
public string CreatedBy { get; set; }
[Parameter]
public DateTime CreatedOn { get; set; }
[Parameter]
public string ModifiedBy { get; set; }
[Parameter]
public DateTime ModifiedOn { get; set; }
[Parameter]
public string Style { get; set; }
string text = "";
protected override void OnParametersSet()
{
text = "";
if (!String.IsNullOrEmpty(CreatedBy) || CreatedOn != null)
{
text += "<p style=\"" + Style + "\">Created ";
if (!String.IsNullOrEmpty(CreatedBy))
{
text += " by <b>" + CreatedBy + "</b>";
}
if (CreatedOn != null)
{
text += " on <b>" + CreatedOn.ToString("MMM dd yyyy HH:mm:ss") + "</b>";
}
text += "</p>";
}
if (!String.IsNullOrEmpty(ModifiedBy) || ModifiedOn != null)
{
text += "<p style=\"" + Style + "\">Last modified ";
if (!String.IsNullOrEmpty(ModifiedBy))
{
text += " by <b>" + ModifiedBy + "</b>";
}
if (ModifiedOn != null)
{
text += " on <b>" + ModifiedOn.ToString("MMM dd yyyy HH:mm:ss") + "</b>";
}
text += "</p>";
}
}
}

View File

@ -0,0 +1,45 @@
@namespace Oqtane.Modules.Controls
@if (multiple)
{
<input type="file" id="@fileid" name="file" accept="@filter" multiple />
}
else
{
<input type="file" id="@fileid" name="file" accept="@filter" />
}
<span id="@progressinfoid"></span> <progress id="@progressbarid" style="visibility: hidden;"></progress>
@code {
[Parameter]
public string Name { get; set; } // optional - can be used for managing multiple file upload controls on a page
[Parameter]
public string Filter { get; set; } // optional - for restricting types of files that can be selected
[Parameter]
public string Multiple { get; set; } // optional - enable multiple file uploads
string fileid = "";
string progressinfoid = "";
string progressbarid = "";
string filter = "*";
bool multiple = false;
protected override void OnInitialized()
{
fileid = Name + "FileInput";
progressinfoid = Name + "ProgressInfo";
progressbarid = Name + "ProgressBar";
if (!string.IsNullOrEmpty(Filter))
{
filter = Filter;
}
if (!string.IsNullOrEmpty(Multiple))
{
multiple = bool.Parse(Multiple);
}
}
}

View File

@ -0,0 +1,39 @@
@using Oqtane.Modules
@namespace Oqtane.Modules.Controls
@inherits ModuleBase
@if (Message != "")
{
<div class="@type">@Message</div>
<br />
<br />
}
@code {
[Parameter]
public string Message { get; set; }
[Parameter]
public MessageType Type { get; set; }
string type = "alert alert-danger";
protected override void OnInitialized()
{
switch (Type)
{
case MessageType.Success:
type = "alert alert-success";
break;
case MessageType.Info:
type = "alert alert-info";
break;
case MessageType.Warning:
type = "alert alert-warning";
break;
case MessageType.Error:
type = "alert alert-danger";
break;
}
}
}

View File

@ -0,0 +1,213 @@
@using Oqtane.Services
@using Oqtane.Modules
@using Oqtane.Models
@using Oqtane.Security
@using Oqtane.Shared
@namespace Oqtane.Modules.Controls
@inherits ModuleBase
@inject IRoleService RoleService
@inject IUserService UserService
@if (roles != null)
{
<br />
<table class="table">
<tbody>
<tr>
<th>Role</th>
@foreach (PermissionString permission in permissions)
{
<th style="text-align: center;">@permission.PermissionName @EntityName</th>
}
</tr>
@foreach (Role role in roles)
{
<tr>
<td>@role.Name</td>
@foreach (PermissionString permission in permissions)
{
var p = permission;
<td style="text-align: center;">
<TriStateCheckBox Value=@GetPermissionValue(p.Permissions, role.Name) Disabled=@GetPermissionDisabled(role.Name) OnChange="@(e => PermissionChanged(e, p.PermissionName, role.Name))" />
</td>
}
</tr>
}
</tbody>
</table>
@if (@users.Count != 0)
{
<table class="table">
<thead>
<tr>
<th>User</th>
@foreach (PermissionString permission in permissions)
{
<th style="text-align: center;">@permission.PermissionName @EntityName</th>
}
</tr>
</thead>
<tbody>
@foreach (User user in users)
{
string userid = "[" + user.UserId.ToString() + "]";
<tr>
<td>@user.DisplayName</td>
@foreach (PermissionString permission in permissions)
{
var p = permission;
<td style="text-align: center;">
<TriStateCheckBox Value=@GetPermissionValue(p.Permissions, userid) Disabled=@GetPermissionDisabled(userid) OnChange="@(e => PermissionChanged(e, p.PermissionName, userid))" />
</td>
}
</tr>
}
</tbody>
</table>
}
<table class="table">
<tbody>
<tr>
<td style="text-align: right;"><label for="Username" class="control-label">User: </label></td>
<td><input type="text" name="Username" class="form-control" placeholder="Enter Username" @bind="@username" /></td>
<td style="text-align: left;"><button type="button" class="btn btn-primary" @onclick="@AddUser">Add</button></td>
</tr>
</tbody>
</table>
<br />
<ModuleMessage Type="MessageType.Error" Message="@message" />
}
@code {
[Parameter]
public string EntityName { get; set; }
[Parameter]
public string Permissions { get; set; }
string permissionnames = "";
List<Role> roles;
List<PermissionString> permissions = new List<PermissionString>();
List<User> users = new List<User>();
string username = "";
string message = "";
protected override async Task OnInitializedAsync()
{
permissionnames = PageState.ModuleDefinitions.Find(item => item.ModuleDefinitionName == ModuleState.ModuleDefinitionName).Permissions;
if (string.IsNullOrEmpty(permissionnames))
{
permissionnames = "View,Edit";
}
roles = await RoleService.GetRolesAsync(ModuleState.SiteId);
roles.Insert(0, new Role { Name = Constants.AllUsersRole });
foreach (string permissionname in permissionnames.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries))
{
permissions.Add(new PermissionString { PermissionName = permissionname, Permissions = "" });
}
foreach (PermissionString permissionstring in UserSecurity.GetPermissionStrings(Permissions))
{
if (permissions.Find(item => item.PermissionName == permissionstring.PermissionName) != null)
{
permissions[permissions.FindIndex(item => item.PermissionName == permissionstring.PermissionName)].Permissions = permissionstring.Permissions;
}
if (permissionstring.Permissions.Contains("["))
{
foreach (string user in permissionstring.Permissions.Split(new char[] { '[' }, StringSplitOptions.RemoveEmptyEntries))
{
if (user.Contains("]"))
{
int userid = int.Parse(user.Substring(0, user.IndexOf("]")));
if (users.Where(item => item.UserId == userid).FirstOrDefault() == null)
{
users.Add(await UserService.GetUserAsync(userid, ModuleState.SiteId));
}
}
}
}
}
}
private bool? GetPermissionValue(string Permissions, string SecurityKey)
{
if ((";" + Permissions + ";").Contains(";" + "!" + SecurityKey + ";"))
{
return false; // deny permission
}
else
{
if ((";" + Permissions + ";").Contains(";" + SecurityKey + ";"))
{
return true; // grant permission
}
else
{
return null; // not specified
}
}
}
private bool GetPermissionDisabled(string RoleName)
{
if (RoleName == Constants.AdminRole)
{
return true;
}
else
{
return false;
}
}
private async Task AddUser()
{
if (users.Where(item => item.Username == username).FirstOrDefault() == null)
{
try
{
User user = await UserService.GetUserAsync(username, ModuleState.SiteId);
if (user != null)
{
users.Add(user);
}
}
catch
{
message = "Username Does Not Exist";
}
}
username = "";
}
private void PermissionChanged(bool? Value, string PermissionName, string SecurityId)
{
bool? selected = Value;
PermissionString permission = permissions.Find(item => item.PermissionName == PermissionName);
if (permission != null)
{
List<string> ids = permission.Permissions.Split(';').ToList();
ids.Remove(SecurityId); // remove grant permission
ids.Remove("!" + SecurityId); // remove deny permission
switch (selected)
{
case true:
ids.Add(SecurityId); // add grant permission
break;
case false:
ids.Add("!" + SecurityId); // add deny permission
break;
case null:
break; // permission not specified
}
permissions[permissions.FindIndex(item => item.PermissionName == PermissionName)].Permissions = string.Join(";", ids.ToArray());
}
}
public string GetPermissions()
{
return UserSecurity.SetPermissionStrings(permissions);
}
}

View File

@ -0,0 +1,62 @@
@namespace Oqtane.Modules.Controls
<img src="@src" title="@title" disabled=@Disabled @onclick="SetValue" />
@code {
[Parameter]
public bool? Value { get; set; }
[Parameter]
public bool Disabled { get; set; }
[Parameter]
public Action<bool?> OnChange { get; set; }
bool? value = null;
string title;
string src = "";
protected override void OnInitialized()
{
value = Value;
SetImage();
}
private void SetValue()
{
switch (value)
{
case true:
value = false;
break;
case false:
value = null;
break;
case null:
value = true;
break;
}
SetImage();
OnChange(value);
}
private void SetImage()
{
switch (value)
{
case true:
src = "images/checked.png";
title = "Permission Granted";
break;
case false:
src = "images/unchecked.png";
title = "Permission Denied";
break;
case null:
src = "images/null.png";
title = "";
break;
}
StateHasChanged();
}
}

View File

@ -1,9 +1,11 @@
@using Oqtane.Modules
@namespace Oqtane.Modules.Counter
@inherits ModuleBase
Current count: @currentCount
<br />
<button class="btn btn-primary" @onclick="@IncrementCount">Click me</button>
<br /><br />
<button type="button" class="btn btn-primary" @onclick="@IncrementCount">Click me</button>
<br />
<br />
@code {
int currentCount = 0;

View File

@ -1,16 +1,22 @@
using Oqtane.Modules;
using System.Collections.Generic;
namespace Oqtane.Client.Modules.Counter
namespace Oqtane.Modules.Counter
{
public class Module : IModule
{
public string Name { get { return "Counter"; } }
public string Description { get { return "Increments a counter"; } }
public string Version { get { return "1.0.0"; } }
public string Owner { get { return ""; } }
public string Url { get { return ""; } }
public string Contact { get { return ""; } }
public string License { get { return ""; } }
public string Dependencies { get { return ""; } }
public Dictionary<string, string> Properties
{
get
{
Dictionary<string, string> properties = new Dictionary<string, string>
{
{ "Name", "Counter" },
{ "Description", "Increments a counter" },
{ "Version", "1.0.0" }
};
return properties;
}
}
}
}

View File

@ -1,15 +1,18 @@
@using Microsoft.AspNetCore.Components.Routing
@using Oqtane.Modules
@using Oqtane.Client.Modules.HtmlText.Services
@using Oqtane.Shared.Modules.HtmlText.Models
@using Oqtane.Modules.Controls
@using Oqtane.Modules.HtmlText.Services
@using Oqtane.Modules.HtmlText.Models
@using System.Net.Http;
@using Oqtane.Shared;
@namespace Oqtane.Modules.HtmlText
@inherits ModuleBase
@inject IUriHelper UriHelper
@inject HttpClient http
@inject SiteState sitestate
<form>
<ModuleMessage Message="@message" />
<table class="form-group">
<tr>
<td>
@ -20,31 +23,50 @@
</td>
</tr>
</table>
<button class="btn btn-success" @onclick="@SaveContent">Save</button>
<button type="button" class="btn btn-success" @onclick="@SaveContent">Save</button>
<NavLink class="btn btn-secondary" href="@NavigateUrl()">Cancel</NavLink>
</form>
<br />
<br />
<AuditInfo CreatedBy="@createdby" CreatedOn="@createdon" ModifiedBy="@modifiedby" ModifiedOn="@modifiedon"></AuditInfo>
@code {
public override SecurityAccessLevelEnum SecurityAccessLevel { get { return SecurityAccessLevelEnum.Edit; } }
public override SecurityAccessLevel SecurityAccessLevel { get { return SecurityAccessLevel.Edit; } }
public override string Title { get { return "Edit Html/Text"; } }
HtmlTextInfo htmltext;
string message = "";
string content;
string createdby;
DateTime createdon;
string modifiedby;
DateTime modifiedon;
protected override async Task OnInitAsync()
protected override async Task OnInitializedAsync()
{
try
{
HtmlTextService htmltextservice = new HtmlTextService(http, sitestate, UriHelper);
List<HtmlTextInfo> htmltextlist = await htmltextservice.GetHtmlTextAsync(ModuleState.ModuleId);
if (htmltextlist != null)
HtmlTextInfo htmltext = await htmltextservice.GetHtmlTextAsync(ModuleState.ModuleId);
if (htmltext != null)
{
htmltext = htmltextlist.FirstOrDefault();
content = htmltext.Content;
createdby = htmltext.CreatedBy;
createdon = htmltext.CreatedOn;
modifiedby = htmltext.ModifiedBy;
modifiedon = htmltext.ModifiedOn;
}
}
catch (Exception ex)
{
message = ex.Message;
}
}
private async Task SaveContent()
{
try
{
HtmlTextService htmltextservice = new HtmlTextService(http, sitestate, UriHelper);
HtmlTextInfo htmltext = await htmltextservice.GetHtmlTextAsync(ModuleState.ModuleId);
if (htmltext != null)
{
htmltext.Content = content;
@ -57,6 +79,12 @@
htmltext.Content = content;
await htmltextservice.AddHtmlTextAsync(htmltext);
}
UriHelper.NavigateTo(NavigateUrl(), true);
PageState.Reload = Constants.ReloadPage;
UriHelper.NavigateTo(NavigateUrl());
}
catch (Exception ex)
{
message = ex.Message;
}
}
}

View File

@ -1,28 +1,42 @@
@using Oqtane.Client.Modules.HtmlText.Services
@using Oqtane.Modules.HtmlText.Services
@using Oqtane.Modules
@using Oqtane.Shared.Modules.HtmlText.Models
@using Oqtane.Modules.HtmlText.Models
@using System.Net.Http;
@using Oqtane.Client.Modules.Controls
@using Oqtane.Modules.Controls
@using Oqtane.Shared;
@namespace Oqtane.Modules.HtmlText
@inherits ModuleBase
@inject IUriHelper UriHelper
@inject HttpClient http
@inject SiteState sitestate
<ModuleMessage Message="@message" />
@((MarkupString)content)
<br /><ActionLink Action="Edit" /><br /><br />
<br />
<ActionLink Action="Edit" />
<br />
<br />
@code {
string message = "";
string content;
protected override async Task OnInitAsync()
protected override async Task OnParametersSetAsync()
{
try
{
HtmlTextService htmltextservice = new HtmlTextService(http, sitestate, UriHelper);
List<HtmlTextInfo> htmltext = await htmltextservice.GetHtmlTextAsync(ModuleState.ModuleId);
HtmlTextInfo htmltext = await htmltextservice.GetHtmlTextAsync(ModuleState.ModuleId);
if (htmltext != null)
{
content = htmltext.FirstOrDefault().Content;
content = htmltext.Content;
}
}
catch (Exception ex)
{
message = ex.Message;
}
}
}

View File

@ -1,16 +1,22 @@
using Oqtane.Modules;
using System.Collections.Generic;
namespace Oqtane.Client.Modules.HtmlText
namespace Oqtane.Modules.HtmlText
{
public class Module : IModule
{
public string Name { get { return "HtmlText"; } }
public string Description { get { return "Renders HTML or Text"; } }
public string Version { get { return "1.0.0"; } }
public string Owner { get { return ""; } }
public string Url { get { return ""; } }
public string Contact { get { return ""; } }
public string License { get { return ""; } }
public string Dependencies { get { return ""; } }
public Dictionary<string, string> Properties
{
get
{
Dictionary<string, string> properties = new Dictionary<string, string>
{
{ "Name", "HtmlText" },
{ "Description", "Renders HTML or Text" },
{ "Version", "1.0.0" }
};
return properties;
}
}
}
}

View File

@ -4,10 +4,10 @@ using System.Threading.Tasks;
using System.Net.Http;
using Microsoft.AspNetCore.Components;
using Oqtane.Services;
using Oqtane.Shared.Modules.HtmlText.Models;
using Oqtane.Modules.HtmlText.Models;
using Oqtane.Shared;
namespace Oqtane.Client.Modules.HtmlText.Services
namespace Oqtane.Modules.HtmlText.Services
{
public class HtmlTextService : ServiceBase, IHtmlTextService
{
@ -27,28 +27,24 @@ namespace Oqtane.Client.Modules.HtmlText.Services
get { return CreateApiUrl(sitestate.Alias, urihelper.GetAbsoluteUri(), "HtmlText"); }
}
public async Task<List<HtmlTextInfo>> GetHtmlTextAsync(int ModuleId)
public async Task<HtmlTextInfo> GetHtmlTextAsync(int ModuleId)
{
List<HtmlTextInfo> htmltext = await http.GetJsonAsync<List<HtmlTextInfo>>(apiurl);
htmltext = htmltext
.Where(item => item.ModuleId == ModuleId)
.ToList();
return htmltext;
return await http.GetJsonAsync<HtmlTextInfo>(apiurl + "/" + ModuleId.ToString() + "?entityid=" + ModuleId.ToString());
}
public async Task AddHtmlTextAsync(HtmlTextInfo htmltext)
{
await http.PostJsonAsync(apiurl, htmltext);
await http.PostJsonAsync(apiurl + "?entityid=" + htmltext.ModuleId.ToString(), htmltext);
}
public async Task UpdateHtmlTextAsync(HtmlTextInfo htmltext)
{
await http.PutJsonAsync(apiurl + "/" + htmltext.HtmlTextId.ToString(), htmltext);
await http.PutJsonAsync(apiurl + "/" + htmltext.HtmlTextId.ToString() + "?entityid=" + htmltext.ModuleId.ToString(), htmltext);
}
public async Task DeleteHtmlTextAsync(int HtmlTextId)
public async Task DeleteHtmlTextAsync(int ModuleId)
{
await http.DeleteAsync(apiurl + "/" + HtmlTextId.ToString());
await http.DeleteAsync(apiurl + "/" + ModuleId.ToString() + "?entityid=" + ModuleId.ToString());
}
}
}

View File

@ -1,17 +1,17 @@
using System.Collections.Generic;
using System.Threading.Tasks;
using Oqtane.Shared.Modules.HtmlText.Models;
using Oqtane.Modules.HtmlText.Models;
namespace Oqtane.Client.Modules.HtmlText.Services
namespace Oqtane.Modules.HtmlText.Services
{
public interface IHtmlTextService
{
Task<List<HtmlTextInfo>> GetHtmlTextAsync(int ModuleId);
Task<HtmlTextInfo> GetHtmlTextAsync(int ModuleId);
Task AddHtmlTextAsync(HtmlTextInfo htmltext);
Task UpdateHtmlTextAsync(HtmlTextInfo htmltext);
Task DeleteHtmlTextAsync(int HtmlTextId);
Task DeleteHtmlTextAsync(int ModuleId);
}
}

View File

@ -1,14 +1,9 @@
namespace Oqtane.Modules
using System.Collections.Generic;
namespace Oqtane.Modules
{
public interface IModule
{
string Name { get; }
string Description { get; }
string Version { get; }
string Owner { get; }
string Url { get; }
string Contact { get; }
string License { get; }
string Dependencies { get; }
Dictionary<string, string> Properties { get; }
}
}

View File

@ -2,8 +2,9 @@
{
public interface IModuleControl
{
string Title { get; }
SecurityAccessLevelEnum SecurityAccessLevel { get; }
string Actions { get; } // can be specified as a comma delimited set of values
SecurityAccessLevel SecurityAccessLevel { get; } // defines the security access level for this control - defaults to View
string Title { get; } // title to display for this control - defaults to module title
string Actions { get; } // allows for routing by configuration rather than by convention ( comma delimited ) - defaults to using component file name
bool UseAdminContainer { get; } // container for embedding module control - defaults to true
}
}

View File

@ -0,0 +1,10 @@
namespace Oqtane.Modules
{
public enum MessageType
{
Success,
Info,
Warning,
Error
}
}

View File

@ -12,40 +12,52 @@ namespace Oqtane.Modules
[CascadingParameter]
protected Module ModuleState { get; set; }
public virtual string Title { get { return ""; } }
public virtual SecurityAccessLevel SecurityAccessLevel { get { return SecurityAccessLevel.View; } set { } } // default security
public virtual SecurityAccessLevelEnum SecurityAccessLevel { get { return SecurityAccessLevelEnum.View; } set { } } // default security
public virtual string Title { get { return ""; } }
public virtual string Actions { get { return ""; } }
public virtual bool UseAdminContainer { get { return true; } }
public string NavigateUrl()
{
return Utilities.NavigateUrl(PageState);
}
public string NavigateUrl(bool reload)
{
return Utilities.NavigateUrl(PageState, reload);
return NavigateUrl(PageState.Page.Path);
}
public string NavigateUrl(string path)
{
return Utilities.NavigateUrl(PageState, path);
return NavigateUrl(path, "");
}
public string NavigateUrl(string path, bool reload)
public string NavigateUrl(string path, string parameters)
{
return Utilities.NavigateUrl(PageState, path, reload);
return Utilities.NavigateUrl(PageState.Alias.Path, path, parameters);
}
public string EditUrl(string action)
{
return Utilities.EditUrl(PageState, ModuleState, action, "");
return EditUrl(ModuleState.ModuleId, action);
}
public string EditUrl(string action, string parameters)
{
return Utilities.EditUrl(PageState, ModuleState, action, parameters);
return EditUrl(ModuleState.ModuleId, action, parameters);
}
public string EditUrl(int moduleid, string action)
{
return EditUrl(moduleid, action, "");
}
public string EditUrl(int moduleid, string action, string parameters)
{
return EditUrl(PageState.Page.Path, moduleid, action, parameters);
}
public string EditUrl(string path, int moduleid, string action, string parameters)
{
return Utilities.EditUrl(PageState.Alias.Path, path, moduleid, action, parameters);
}
}
}

View File

@ -1,5 +1,6 @@
@using Oqtane.Modules
@using Oqtane.Client.Modules.Weather.Services
@using Oqtane.Modules.Weather.Services
@namespace Oqtane.Modules.Weather
@inherits ModuleBase
@if (forecasts == null)
@ -34,7 +35,7 @@ else
@code {
WeatherForecast[] forecasts;
protected override async Task OnInitAsync()
protected override async Task OnInitializedAsync()
{
WeatherForecastService forecastservice = new WeatherForecastService();
forecasts = await forecastservice.GetForecastAsync(DateTime.Now);

View File

@ -1,6 +1,6 @@
using System;
namespace Oqtane.Client.Modules.Weather
namespace Oqtane.Modules.Weather
{
public class WeatherForecast
{

View File

@ -1,16 +1,22 @@
using Oqtane.Modules;
using System.Collections.Generic;
namespace Oqtane.Client.Modules.Weather
namespace Oqtane.Modules.Weather
{
public class Module : IModule
{
public string Name { get { return "Weather"; } }
public string Description { get { return "Displays random weather using a service"; } }
public string Version { get { return "1.0.0"; } }
public string Owner { get { return ""; } }
public string Url { get { return ""; } }
public string Contact { get { return ""; } }
public string License { get { return ""; } }
public string Dependencies { get { return ""; } }
public Dictionary<string, string> Properties
{
get
{
Dictionary<string, string> properties = new Dictionary<string, string>
{
{ "Name", "Weather" },
{ "Description", "Displays random weather using a service" },
{ "Version", "1.0.0" }
};
return properties;
}
}
}
}

View File

@ -1,7 +1,7 @@
using System;
using System.Threading.Tasks;
namespace Oqtane.Client.Modules.Weather.Services
namespace Oqtane.Modules.Weather.Services
{
public interface IWeatherForecastService
{

View File

@ -3,7 +3,7 @@ using System;
using System.Linq;
using System.Threading.Tasks;
namespace Oqtane.Client.Modules.Weather.Services
namespace Oqtane.Modules.Weather.Services
{
public class WeatherForecastService : IWeatherForecastService
{

View File

@ -27,8 +27,9 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Blazor" Version="3.0.0-preview6.19307.2" />
<PackageReference Include="Microsoft.AspNetCore.Blazor.Build" Version="3.0.0-preview6.19307.2" PrivateAssets="all" />
<PackageReference Include="Microsoft.AspNetCore.Blazor" Version="3.0.0-preview8.19405.7" />
<PackageReference Include="Microsoft.AspNetCore.Blazor.Build" Version="3.0.0-preview8.19405.7" PrivateAssets="all" />
<PackageReference Include="Microsoft.AspNetCore.Blazor.HttpClient" Version="3.0.0-preview8.19405.7" />
</ItemGroup>
<ItemGroup>

View File

@ -21,7 +21,7 @@
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"applicationUrl": "http://localhost:14246/"
"applicationUrl": "http://localhost:44358/"
}
}
}

View File

@ -4,29 +4,40 @@ using System.Security.Claims;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Components;
using Oqtane.Models;
using Oqtane.Services;
using Oqtane.Shared;
namespace Oqtane.Providers
{
public class IdentityAuthenticationStateProvider : AuthenticationStateProvider
{
private readonly IUriHelper urihelper;
private readonly SiteState sitestate;
public IdentityAuthenticationStateProvider(IUriHelper urihelper)
public IdentityAuthenticationStateProvider(IUriHelper urihelper, SiteState sitestate)
{
this.urihelper = urihelper;
this.sitestate = sitestate;
}
public override async Task<AuthenticationState> GetAuthenticationStateAsync()
{
// hack: create a new HttpClient rather than relying on the registered service as the AuthenticationStateProvider is initialized prior to IUriHelper ( https://github.com/aspnet/AspNetCore/issues/11867 )
HttpClient http = new HttpClient();
Uri uri = new Uri(urihelper.GetAbsoluteUri());
string apiurl = uri.Scheme + "://" + uri.Authority + "/~/api/User/authenticate";
string apiurl = ServiceBase.CreateApiUrl(sitestate.Alias, urihelper.GetAbsoluteUri(), "User") + "/authenticate";
User user = await http.GetJsonAsync<User>(apiurl);
var identity = user.IsAuthenticated
? new ClaimsIdentity(new[] { new Claim(ClaimTypes.Name, user.Username) }, "Identity.Application")
: new ClaimsIdentity();
ClaimsIdentity identity = new ClaimsIdentity();
if (user.IsAuthenticated)
{
identity = new ClaimsIdentity("Identity.Application");
identity.AddClaim(new Claim(ClaimTypes.Name, user.Username));
identity.AddClaim(new Claim(ClaimTypes.PrimarySid, user.UserId.ToString()));
foreach (string role in user.Roles.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries))
{
identity.AddClaim(new Claim(ClaimTypes.Role, role));
}
}
return new AuthenticationState(new ClaimsPrincipal(identity));
}

View File

@ -37,14 +37,14 @@ namespace Oqtane.Services
return await http.GetJsonAsync<Alias>(apiurl + "/" + AliasId.ToString());
}
public async Task AddAliasAsync(Alias alias)
public async Task<Alias> AddAliasAsync(Alias alias)
{
await http.PostJsonAsync(apiurl, alias);
return await http.PostJsonAsync<Alias>(apiurl, alias);
}
public async Task UpdateAliasAsync(Alias alias)
public async Task<Alias> UpdateAliasAsync(Alias alias)
{
await http.PutJsonAsync(apiurl + "/" + alias.AliasId.ToString(), alias);
return await http.PutJsonAsync<Alias>(apiurl + "/" + alias.AliasId.ToString(), alias);
}
public async Task DeleteAliasAsync(int AliasId)
{

View File

@ -0,0 +1,37 @@
using System.Threading.Tasks;
using Microsoft.AspNetCore.Components;
using Microsoft.JSInterop;
using Oqtane.Shared;
namespace Oqtane.Services
{
public class FileService : ServiceBase, IFileService
{
private readonly SiteState sitestate;
private readonly IUriHelper urihelper;
private readonly IJSRuntime jsRuntime;
public FileService(SiteState sitestate, IUriHelper urihelper, IJSRuntime jsRuntime)
{
this.sitestate = sitestate;
this.urihelper = urihelper;
this.jsRuntime = jsRuntime;
}
private string apiurl
{
get { return CreateApiUrl(sitestate.Alias, urihelper.GetAbsoluteUri(), "File"); }
}
public async Task UploadFilesAsync(string Folder)
{
await UploadFilesAsync(Folder, "");
}
public async Task UploadFilesAsync(string Folder, string FileUploadName)
{
var interop = new Interop(jsRuntime);
await interop.UploadFiles(apiurl + "/upload", Folder, FileUploadName);
}
}
}

View File

@ -1,29 +0,0 @@
using Oqtane.Models;
using System.Collections.Generic;
using System.Threading.Tasks;
namespace Oqtane.Services
{
public interface IUserService
{
Task<List<User>> GetUsersAsync();
Task<User> GetUserAsync(int UserId);
Task<User> GetUserAsync(string Username);
Task AddUserAsync(User user);
Task UpdateUserAsync(User user);
Task DeleteUserAsync(int UserId);
Task<User> GetCurrentUserAsync();
Task<User> LoginUserAsync(User user);
Task LogoutUserAsync();
bool IsAuthorized(User user, string accesscontrollist);
}
}

View File

@ -10,9 +10,9 @@ namespace Oqtane.Services
Task<Alias> GetAliasAsync(int AliasId);
Task AddAliasAsync(Alias alias);
Task<Alias> AddAliasAsync(Alias Alias);
Task UpdateAliasAsync(Alias alias);
Task<Alias> UpdateAliasAsync(Alias Alias);
Task DeleteAliasAsync(int AliasId);
}

View File

@ -0,0 +1,12 @@
using Oqtane.Models;
using System.Collections.Generic;
using System.Threading.Tasks;
namespace Oqtane.Services
{
public interface IFileService
{
Task UploadFilesAsync(string Folder);
Task UploadFilesAsync(string Folder, string FileUploadName);
}
}

View File

@ -7,5 +7,6 @@ namespace Oqtane.Services
public interface IModuleDefinitionService
{
Task<List<ModuleDefinition>> GetModuleDefinitionsAsync();
Task InstallModulesAsync();
}
}

View File

@ -9,8 +9,8 @@ namespace Oqtane.Services
Task<List<Module>> GetModulesAsync(int PageId);
Task<List<Module>> GetModulesAsync(int SiteId, string ModuleDefinitionName);
Task<Module> GetModuleAsync(int ModuleId);
Task AddModuleAsync(Module module);
Task UpdateModuleAsync(Module module);
Task<Module> AddModuleAsync(Module Module);
Task<Module> UpdateModuleAsync(Module Module);
Task DeleteModuleAsync(int ModuleId);
}
}

View File

@ -7,8 +7,10 @@ namespace Oqtane.Services
public interface IPageModuleService
{
Task<List<PageModule>> GetPageModulesAsync();
Task AddPageModuleAsync(PageModule pagemodule);
Task UpdatePageModuleAsync(PageModule pagemodule);
Task<PageModule> GetPageModuleAsync(int PageModuleId);
Task<PageModule> AddPageModuleAsync(PageModule PageModule);
Task<PageModule> UpdatePageModuleAsync(PageModule PageModule);
Task UpdatePageModuleOrderAsync(int PageId, string Pane);
Task DeletePageModuleAsync(int PageModuleId);
}
}

View File

@ -8,8 +8,9 @@ namespace Oqtane.Services
{
Task<List<Page>> GetPagesAsync(int SiteId);
Task<Page> GetPageAsync(int PageId);
Task AddPageAsync(Page page);
Task UpdatePageAsync(Page page);
Task<Page> AddPageAsync(Page Page);
Task<Page> UpdatePageAsync(Page Page);
Task UpdatePageOrderAsync(int SiteId, int? ParentId);
Task DeletePageAsync(int PageId);
}
}

View File

@ -0,0 +1,21 @@
using Oqtane.Models;
using System.Collections.Generic;
using System.Threading.Tasks;
namespace Oqtane.Services
{
public interface IProfileService
{
Task<List<Profile>> GetProfilesAsync();
Task<List<Profile>> GetProfilesAsync(int SiteId);
Task<Profile> GetProfileAsync(int ProfileId);
Task<Profile> AddProfileAsync(Profile Profile);
Task<Profile> UpdateProfileAsync(Profile Profile);
Task DeleteProfileAsync(int ProfileId);
}
}

View File

@ -0,0 +1,21 @@
using Oqtane.Models;
using System.Collections.Generic;
using System.Threading.Tasks;
namespace Oqtane.Services
{
public interface IRoleService
{
Task<List<Role>> GetRolesAsync();
Task<List<Role>> GetRolesAsync(int SiteId);
Task<Role> GetRoleAsync(int RoleId);
Task<Role> AddRoleAsync(Role Role);
Task<Role> UpdateRoleAsync(Role Role);
Task DeleteRoleAsync(int RoleId);
}
}

View File

@ -0,0 +1,51 @@
using Oqtane.Models;
using System.Collections.Generic;
using System.Threading.Tasks;
namespace Oqtane.Services
{
public interface ISettingService
{
Task<Dictionary<string, string>> GetHostSettingsAsync();
Task UpdateHostSettingsAsync(Dictionary<string, string> HostSettings);
Task<Dictionary<string, string>> GetSiteSettingsAsync(int SiteId);
Task UpdateSiteSettingsAsync(Dictionary<string, string> SiteSettings, int SiteId);
Task<Dictionary<string, string>> GetPageSettingsAsync(int PageId);
Task UpdatePageSettingsAsync(Dictionary<string, string> PageSettings, int PageId);
Task<Dictionary<string, string>> GetPageModuleSettingsAsync(int PageModuleId);
Task UpdatePageModuleSettingsAsync(Dictionary<string, string> PageModuleSettings, int PageModuleId);
Task<Dictionary<string, string>> GetModuleSettingsAsync(int ModuleId);
Task UpdateModuleSettingsAsync(Dictionary<string, string> ModuleSettings, int ModuleId);
Task<Dictionary<string, string>> GetUserSettingsAsync(int UserId);
Task UpdateUserSettingsAsync(Dictionary<string, string> UserSettings, int UserId);
Task<Dictionary<string, string>> GetSettingsAsync(string EntityName, int EntityId);
Task UpdateSettingsAsync(Dictionary<string, string> Settings, string EntityName, int EntityId);
Task<Setting> GetSettingAsync(int SettingId);
Task<Setting> AddSettingAsync(Setting Setting);
Task<Setting> UpdateSettingAsync(Setting Setting);
Task DeleteSettingAsync(int SettingId);
string GetSetting(Dictionary<string, string> Settings, string SettingName, string DefaultValue);
Dictionary<string, string> SetSetting(Dictionary<string, string> Settings, string SettingName, string SettingValue);
}
}

View File

@ -10,9 +10,9 @@ namespace Oqtane.Services
Task<Site> GetSiteAsync(int SiteId);
Task AddSiteAsync(Site site);
Task<Site> AddSiteAsync(Site Site);
Task UpdateSiteAsync(Site site);
Task<Site> UpdateSiteAsync(Site Site);
Task DeleteSiteAsync(int SiteId);
}

View File

@ -0,0 +1,16 @@
using Oqtane.Models;
using System.Collections.Generic;
using System.Threading.Tasks;
namespace Oqtane.Services
{
public interface IUserRoleService
{
Task<List<UserRole>> GetUserRolesAsync();
Task<List<UserRole>> GetUserRolesAsync(int UserId);
Task<UserRole> GetUserRoleAsync(int UserRoleId);
Task<UserRole> AddUserRoleAsync(UserRole UserRole);
Task<UserRole> UpdateUserRoleAsync(UserRole UserRole);
Task DeleteUserRoleAsync(int UserRoleId);
}
}

View File

@ -0,0 +1,25 @@
using Oqtane.Models;
using System.Collections.Generic;
using System.Threading.Tasks;
namespace Oqtane.Services
{
public interface IUserService
{
Task<List<User>> GetUsersAsync(int SiteId);
Task<User> GetUserAsync(int UserId, int SiteId);
Task<User> GetUserAsync(string Username, int SiteId);
Task<User> AddUserAsync(User User);
Task<User> UpdateUserAsync(User User);
Task DeleteUserAsync(int UserId);
Task<User> LoginUserAsync(User User, bool SetCookie, bool IsPersistent);
Task LogoutUserAsync();
}
}

View File

@ -30,13 +30,15 @@ namespace Oqtane.Services
public async Task<List<ModuleDefinition>> GetModuleDefinitionsAsync()
{
// get list of modules from the server
List<ModuleDefinition> moduledefinitions = await http.GetJsonAsync<List<ModuleDefinition>>(apiurl);
// get list of loaded assemblies
// get list of loaded assemblies on the client ( in the client-side hosting module the browser client has its own app domain )
Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
foreach (ModuleDefinition moduledefinition in moduledefinitions)
{
// if a module has dependencies, check if they are loaded
if (moduledefinition.Dependencies != "")
{
foreach (string dependency in moduledefinition.Dependencies.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries))
@ -50,6 +52,7 @@ namespace Oqtane.Services
}
}
}
// check if the module assembly is loaded
if (assemblies.Where(item => item.FullName.StartsWith(moduledefinition.AssemblyName + ",")).FirstOrDefault() == null)
{
// download assembly from server and load
@ -60,5 +63,10 @@ namespace Oqtane.Services
return moduledefinitions.OrderBy(item => item.Name).ToList();
}
public async Task InstallModulesAsync()
{
await http.GetJsonAsync<List<string>>(apiurl + "/install");
}
}
}

View File

@ -46,14 +46,14 @@ namespace Oqtane.Services
return await http.GetJsonAsync<Module>(apiurl + "/" + ModuleId.ToString());
}
public async Task AddModuleAsync(Module module)
public async Task<Module> AddModuleAsync(Module Module)
{
await http.PostJsonAsync(apiurl, module);
return await http.PostJsonAsync<Module>(apiurl, Module);
}
public async Task UpdateModuleAsync(Module module)
public async Task<Module> UpdateModuleAsync(Module Module)
{
await http.PutJsonAsync(apiurl + "/" + module.ModuleId.ToString(), module);
return await http.PutJsonAsync<Module>(apiurl + "/" + Module.ModuleId.ToString(), Module);
}
public async Task DeleteModuleAsync(int ModuleId)

View File

@ -23,7 +23,7 @@ namespace Oqtane.Services
private string apiurl
{
get { return CreateApiUrl(sitestate.Alias, "PageModule", urihelper.GetAbsoluteUri()); }
get { return CreateApiUrl(sitestate.Alias, urihelper.GetAbsoluteUri(), "PageModule"); }
}
public async Task<List<PageModule>> GetPageModulesAsync()
@ -31,14 +31,24 @@ namespace Oqtane.Services
return await http.GetJsonAsync<List<PageModule>>(apiurl);
}
public async Task AddPageModuleAsync(PageModule pagemodule)
public async Task<PageModule> GetPageModuleAsync(int PageModuleId)
{
await http.PostJsonAsync(apiurl, pagemodule);
return await http.GetJsonAsync<PageModule>(apiurl + "/" + PageModuleId.ToString());
}
public async Task UpdatePageModuleAsync(PageModule pagemodule)
public async Task<PageModule> AddPageModuleAsync(PageModule PageModule)
{
await http.PutJsonAsync(apiurl + "/" + pagemodule.PageModuleId.ToString(), pagemodule);
return await http.PostJsonAsync<PageModule>(apiurl, PageModule);
}
public async Task<PageModule> UpdatePageModuleAsync(PageModule PageModule)
{
return await http.PutJsonAsync<PageModule>(apiurl + "/" + PageModule.PageModuleId.ToString(), PageModule);
}
public async Task UpdatePageModuleOrderAsync(int PageId, string Pane)
{
await http.PutJsonAsync(apiurl + "/?pageid=" + PageId.ToString() + "&pane=" + Pane, null);
}
public async Task DeletePageModuleAsync(int PageModuleId)

View File

@ -5,6 +5,7 @@ using System.Net.Http;
using Microsoft.AspNetCore.Components;
using System.Collections.Generic;
using Oqtane.Shared;
using System;
namespace Oqtane.Services
{
@ -29,7 +30,8 @@ namespace Oqtane.Services
public async Task<List<Page>> GetPagesAsync(int SiteId)
{
List<Page> pages = await http.GetJsonAsync<List<Page>>(apiurl + "?siteid=" + SiteId.ToString());
return pages.OrderBy(item => item.Order).ToList();
pages = GetPagesHierarchy(pages);
return pages;
}
public async Task<Page> GetPageAsync(int PageId)
@ -37,18 +39,55 @@ namespace Oqtane.Services
return await http.GetJsonAsync<Page>(apiurl + "/" + PageId.ToString());
}
public async Task AddPageAsync(Page page)
public async Task<Page> AddPageAsync(Page Page)
{
await http.PostJsonAsync(apiurl, page);
return await http.PostJsonAsync<Page>(apiurl, Page);
}
public async Task UpdatePageAsync(Page page)
public async Task<Page> UpdatePageAsync(Page Page)
{
await http.PutJsonAsync(apiurl + "/" + page.PageId.ToString(), page);
return await http.PutJsonAsync<Page>(apiurl + "/" + Page.PageId.ToString(), Page);
}
public async Task UpdatePageOrderAsync(int SiteId, int? ParentId)
{
await http.PutJsonAsync(apiurl + "/?siteid=" + SiteId.ToString() + "&parentid=" + ((ParentId == null) ? "" : ParentId.ToString()), null);
}
public async Task DeletePageAsync(int PageId)
{
await http.DeleteAsync(apiurl + "/" + PageId.ToString());
}
private static List<Page> GetPagesHierarchy(List<Page> Pages)
{
List<Page> hierarchy = new List<Page>();
Action<List<Page>, Page> GetPath = null;
GetPath = (List<Page> pages, Page page) =>
{
IEnumerable<Page> children;
int level;
if (page == null)
{
level = -1;
children = Pages.Where(item => item.ParentId == null);
}
else
{
level = page.Level;
children = Pages.Where(item => item.ParentId == page.PageId);
}
foreach (Page child in children)
{
child.Level = level + 1;
child.HasChildren = Pages.Where(item => item.ParentId == child.PageId).Any();
hierarchy.Add(child);
GetPath(pages, child);
}
};
Pages = Pages.OrderBy(item => item.Order).ToList();
GetPath(Pages, null);
return hierarchy;
}
}
}

View File

@ -0,0 +1,59 @@
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 ProfileService : ServiceBase, IProfileService
{
private readonly HttpClient http;
private readonly SiteState sitestate;
private readonly IUriHelper urihelper;
public ProfileService(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(), "Profile"); }
}
public async Task<List<Profile>> GetProfilesAsync()
{
return await http.GetJsonAsync<List<Profile>>(apiurl);
}
public async Task<List<Profile>> GetProfilesAsync(int SiteId)
{
List<Profile> Profiles = await http.GetJsonAsync<List<Profile>>(apiurl + "?siteid=" + SiteId.ToString());
return Profiles.OrderBy(item => item.ViewOrder).ToList();
}
public async Task<Profile> GetProfileAsync(int ProfileId)
{
return await http.GetJsonAsync<Profile>(apiurl + "/" + ProfileId.ToString());
}
public async Task<Profile> AddProfileAsync(Profile Profile)
{
return await http.PostJsonAsync<Profile>(apiurl, Profile);
}
public async Task<Profile> UpdateProfileAsync(Profile Profile)
{
return await http.PutJsonAsync<Profile>(apiurl + "/" + Profile.SiteId.ToString(), Profile);
}
public async Task DeleteProfileAsync(int ProfileId)
{
await http.DeleteAsync(apiurl + "/" + ProfileId.ToString());
}
}
}

View File

@ -0,0 +1,60 @@
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 RoleService : ServiceBase, IRoleService
{
private readonly HttpClient http;
private readonly SiteState sitestate;
private readonly IUriHelper urihelper;
public RoleService(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(), "Role"); }
}
public async Task<List<Role>> GetRolesAsync()
{
List<Role> Roles = await http.GetJsonAsync<List<Role>>(apiurl);
return Roles.OrderBy(item => item.Name).ToList();
}
public async Task<List<Role>> GetRolesAsync(int SiteId)
{
List<Role> Roles = await http.GetJsonAsync<List<Role>>(apiurl + "?siteid=" + SiteId.ToString());
return Roles.OrderBy(item => item.Name).ToList();
}
public async Task<Role> GetRoleAsync(int RoleId)
{
return await http.GetJsonAsync<Role>(apiurl + "/" + RoleId.ToString());
}
public async Task<Role> AddRoleAsync(Role Role)
{
return await http.PostJsonAsync<Role>(apiurl, Role);
}
public async Task<Role> UpdateRoleAsync(Role Role)
{
return await http.PutJsonAsync<Role>(apiurl + "/" + Role.SiteId.ToString(), Role);
}
public async Task DeleteRoleAsync(int RoleId)
{
await http.DeleteAsync(apiurl + "/" + RoleId.ToString());
}
}
}

View File

@ -8,7 +8,7 @@ namespace Oqtane.Services
public class ServiceBase
{
public string CreateApiUrl(Alias alias, string absoluteUri, string serviceName)
public static string CreateApiUrl(Alias alias, string absoluteUri, string serviceName)
{
string apiurl = "";
if (alias != null)

View File

@ -0,0 +1,168 @@
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 SettingService : ServiceBase, ISettingService
{
private readonly HttpClient http;
private readonly SiteState sitestate;
private readonly IUriHelper urihelper;
public SettingService(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(), "Setting"); }
}
public async Task<Dictionary<string, string>> GetHostSettingsAsync()
{
return await GetSettingsAsync("Host", -1);
}
public async Task UpdateHostSettingsAsync(Dictionary<string, string> HostSettings)
{
await UpdateSettingsAsync(HostSettings, "Host", -1);
}
public async Task<Dictionary<string, string>> GetSiteSettingsAsync(int SiteId)
{
return await GetSettingsAsync("Site", SiteId);
}
public async Task UpdateSiteSettingsAsync(Dictionary<string, string> SiteSettings, int SiteId)
{
await UpdateSettingsAsync(SiteSettings, "Site", SiteId);
}
public async Task<Dictionary<string, string>> GetPageSettingsAsync(int PageId)
{
return await GetSettingsAsync("Page", PageId);
}
public async Task UpdatePageSettingsAsync(Dictionary<string, string> PageSettings, int PageId)
{
await UpdateSettingsAsync(PageSettings, "Page", PageId);
}
public async Task<Dictionary<string, string>> GetPageModuleSettingsAsync(int PageModuleId)
{
return await GetSettingsAsync("PageModule", PageModuleId);
}
public async Task UpdatePageModuleSettingsAsync(Dictionary<string, string> PageModuleSettings, int PageModuleId)
{
await UpdateSettingsAsync(PageModuleSettings, "PageModule", PageModuleId);
}
public async Task<Dictionary<string, string>> GetModuleSettingsAsync(int ModuleId)
{
return await GetSettingsAsync("Module", ModuleId);
}
public async Task UpdateModuleSettingsAsync(Dictionary<string, string> ModuleSettings, int ModuleId)
{
await UpdateSettingsAsync(ModuleSettings, "Module", ModuleId);
}
public async Task<Dictionary<string, string>> GetUserSettingsAsync(int UserId)
{
return await GetSettingsAsync("User", UserId);
}
public async Task UpdateUserSettingsAsync(Dictionary<string, string> UserSettings, int UserId)
{
await UpdateSettingsAsync(UserSettings, "User", UserId);
}
public async Task<Dictionary<string, string>> GetSettingsAsync(string EntityName, int EntityId)
{
Dictionary<string, string> dictionary = new Dictionary<string, string>();
List<Setting> Settings = await http.GetJsonAsync<List<Setting>>(apiurl + "?entityname=" + EntityName + "&entityid=" + EntityId.ToString());
foreach(Setting setting in Settings.OrderBy(item => item.SettingName).ToList())
{
dictionary.Add(setting.SettingName, setting.SettingValue);
}
return dictionary;
}
public async Task UpdateSettingsAsync(Dictionary<string, string> Settings, string EntityName, int EntityId)
{
List<Setting> settings = await http.GetJsonAsync<List<Setting>>(apiurl + "?entityname=" + EntityName + "&entityid=" + EntityId.ToString());
foreach (KeyValuePair<string, string> kvp in Settings)
{
Setting setting = settings.Where(item => item.SettingName == kvp.Key).FirstOrDefault();
if (setting == null)
{
setting = new Setting();
setting.EntityName = EntityName;
setting.EntityId = EntityId;
setting.SettingName = kvp.Key;
setting.SettingValue = kvp.Value;
setting = await AddSettingAsync(setting);
}
else
{
setting.SettingValue = kvp.Value;
setting = await UpdateSettingAsync(setting);
}
}
}
public async Task<Setting> GetSettingAsync(int SettingId)
{
return await http.GetJsonAsync<Setting>(apiurl + "/" + SettingId.ToString());
}
public async Task<Setting> AddSettingAsync(Setting Setting)
{
return await http.PostJsonAsync<Setting>(apiurl, Setting);
}
public async Task<Setting> UpdateSettingAsync(Setting Setting)
{
return await http.PutJsonAsync<Setting>(apiurl + "/" + Setting.SettingId.ToString(), Setting);
}
public async Task DeleteSettingAsync(int SettingId)
{
await http.DeleteAsync(apiurl + "/" + SettingId.ToString());
}
public string GetSetting(Dictionary<string, string> Settings, string SettingName, string DefaultValue)
{
string value = DefaultValue;
if (Settings.ContainsKey(SettingName))
{
value = Settings[SettingName];
}
return value;
}
public Dictionary<string, string> SetSetting(Dictionary<string, string> Settings, string SettingName, string SettingValue)
{
if (Settings.ContainsKey(SettingName))
{
Settings[SettingName] = SettingValue;
}
else
{
Settings.Add(SettingName, SettingValue);
}
return Settings;
}
}
}

View File

@ -37,14 +37,14 @@ namespace Oqtane.Services
return await http.GetJsonAsync<Site>(apiurl + "/" + SiteId.ToString());
}
public async Task AddSiteAsync(Site site)
public async Task<Site> AddSiteAsync(Site Site)
{
await http.PostJsonAsync(apiurl, site);
return await http.PostJsonAsync<Site>(apiurl, Site);
}
public async Task UpdateSiteAsync(Site site)
public async Task<Site> UpdateSiteAsync(Site Site)
{
await http.PutJsonAsync(apiurl + "/" + site.SiteId.ToString(), site);
return await http.PutJsonAsync<Site>(apiurl + "/" + Site.SiteId.ToString(), Site);
}
public async Task DeleteSiteAsync(int SiteId)
{

View File

@ -0,0 +1,59 @@
using Oqtane.Models;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Components;
using Oqtane.Shared;
namespace Oqtane.Services
{
public class UserRoleService : ServiceBase, IUserRoleService
{
private readonly HttpClient http;
private readonly SiteState sitestate;
private readonly IUriHelper urihelper;
public UserRoleService(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(), "UserRole"); }
}
public async Task<List<UserRole>> GetUserRolesAsync()
{
return await http.GetJsonAsync<List<UserRole>>(apiurl);
}
public async Task<List<UserRole>> GetUserRolesAsync(int UserId)
{
return await http.GetJsonAsync<List<UserRole>>(apiurl + "?userid=" + UserId.ToString());
}
public async Task<UserRole> GetUserRoleAsync(int UserRoleId)
{
return await http.GetJsonAsync<UserRole>(apiurl + "/" + UserRoleId.ToString());
}
public async Task<UserRole> AddUserRoleAsync(UserRole UserRole)
{
return await http.PostJsonAsync<UserRole>(apiurl, UserRole);
}
public async Task<UserRole> UpdateUserRoleAsync(UserRole UserRole)
{
return await http.PutJsonAsync<UserRole>(apiurl + "/" + UserRole.UserRoleId.ToString(), UserRole);
}
public async Task DeleteUserRoleAsync(int UserRoleId)
{
await http.DeleteAsync(apiurl + "/" + UserRoleId.ToString());
}
}
}

View File

@ -27,44 +27,39 @@ namespace Oqtane.Services
get { return CreateApiUrl(sitestate.Alias, urihelper.GetAbsoluteUri(), "User"); }
}
public async Task<List<User>> GetUsersAsync()
public async Task<List<User>> GetUsersAsync(int SiteId)
{
List<User> users = await http.GetJsonAsync<List<User>>(apiurl);
List<User> users = await http.GetJsonAsync<List<User>>(apiurl + "?siteid=" + SiteId.ToString());
return users.OrderBy(item => item.DisplayName).ToList();
}
public async Task<User> GetUserAsync(int UserId)
public async Task<User> GetUserAsync(int UserId, int SiteId)
{
return await http.GetJsonAsync<User>(apiurl + "/" + UserId.ToString());
return await http.GetJsonAsync<User>(apiurl + "/" + UserId.ToString() + "?siteid=" + SiteId.ToString());
}
public async Task<User> GetUserAsync(string Username)
public async Task<User> GetUserAsync(string Username, int SiteId)
{
return await http.GetJsonAsync<User>(apiurl + "/name/" + Username);
return await http.GetJsonAsync<User>(apiurl + "/name/" + Username + "?siteid=" + SiteId.ToString());
}
public async Task AddUserAsync(User user)
public async Task<User> AddUserAsync(User User)
{
await http.PostJsonAsync(apiurl, user);
return await http.PostJsonAsync<User>(apiurl, User);
}
public async Task UpdateUserAsync(User user)
public async Task<User> UpdateUserAsync(User User)
{
await http.PutJsonAsync(apiurl + "/" + user.UserId.ToString(), user);
return await http.PutJsonAsync<User>(apiurl + "/" + User.UserId.ToString(), User);
}
public async Task DeleteUserAsync(int UserId)
{
await http.DeleteAsync(apiurl + "/" + UserId.ToString());
}
public async Task<User> GetCurrentUserAsync()
public async Task<User> LoginUserAsync(User User, bool SetCookie, bool IsPersistent)
{
return await http.GetJsonAsync<User>(apiurl + "/current");
}
public async Task<User> LoginUserAsync(User user)
{
return await http.PostJsonAsync<User>(apiurl + "/login", user);
return await http.PostJsonAsync<User>(apiurl + "/login?setcookie=" + SetCookie.ToString() + "&persistent =" + IsPersistent.ToString(), User);
}
public async Task LogoutUserAsync()
@ -72,78 +67,5 @@ namespace Oqtane.Services
// best practices recommend post is preferrable to get for logout
await http.PostJsonAsync(apiurl + "/logout", null);
}
// ACLs are stored in the format "!rolename1;![userid1];rolename2;rolename3;[userid2];[userid3]" where "!" designates Deny permissions
public bool IsAuthorized(User user, string accesscontrollist)
{
bool isAllowed = false;
if (user != null)
{
//super user always has full access
isAllowed = user.IsSuperUser;
}
if (!isAllowed)
{
if (accesscontrollist != null)
{
foreach (string permission in accesscontrollist.Split(new[] { ';' }))
{
bool? allowed = VerifyPermission(user, permission);
if (allowed.HasValue)
{
isAllowed = allowed.Value;
break;
}
}
}
}
return isAllowed;
}
private bool? VerifyPermission(User user, string permission)
{
bool? allowed = null;
//permissions strings are encoded with deny permissions at the beginning and grant permissions at the end for optimal performance
if (!String.IsNullOrEmpty(permission))
{
// deny permission
if (permission.StartsWith("!"))
{
string denyRole = permission.Replace("!", "");
if (denyRole == Constants.AllUsersRole || IsAllowed(user, denyRole))
{
allowed = false;
}
}
else // grant permission
{
if (permission == Constants.AllUsersRole || IsAllowed(user, permission))
{
allowed = true;
}
}
}
return allowed;
}
private bool IsAllowed(User user, string permission)
{
if (user != null)
{
if ("[" + user.UserId + "]" == permission)
{
return true;
}
var roles = user.Roles;
if (roles != null)
{
return roles.IndexOf(";" + permission + ";") != -1;
}
}
return false;
}
}
}

View File

@ -1,17 +0,0 @@
namespace Oqtane.Shared
{
public class Constants
{
public const string DefaultPage = "Oqtane.Client.Shared.Theme, Oqtane.Client";
public const string DefaultContainer = "Oqtane.Client.Shared.Container, Oqtane.Client";
public const string DefaultAdminContainer = "Oqtane.Client.Themes.AdminContainer, Oqtane.Client";
public const string DefaultSettingsControl = "Oqtane.Client.Modules.Admin.ModuleSettings.Index, Oqtane.Client";
public const string PageManagementModule = "Oqtane.Client.Modules.Admin.Pages, Oqtane.Client";
public const string DefaultControl = "Index";
public const string AdminPane = "Admin";
public const string AllUsersRole = "All Users";
public const string AdminRole = "Administrators";
}
}

View File

@ -1,5 +1,7 @@
@using Oqtane.Models
@using Oqtane.Shared
@using Oqtane.Modules
@namespace Oqtane.Shared
<CascadingValue Value="@ModuleState">
@DynamicComponent
@ -10,15 +12,21 @@
protected PageState PageState { get; set; }
[Parameter]
private Module Module { get; set; }
Module ModuleState;
string container;
public Module Module { get; set; }
RenderFragment DynamicComponent { get; set; }
protected override void OnInit()
Module ModuleState;
protected override void OnParametersSet()
{
ModuleState = Module; // passed in from Pane component
string container = ModuleState.ContainerType;
if (PageState.ModuleId != -1 && PageState.Control != "" && ModuleState.UseAdminContainer)
{
container = Constants.DefaultAdminContainer;
}
DynamicComponent = builder =>
{
Type containerType = Type.GetType(container);
@ -30,18 +38,10 @@
else
{
// container does not exist with type specified
builder.OpenComponent(0, Type.GetType(Constants.ModuleMessageControl));
builder.AddAttribute(1, "Message", "Error Loading Module Container " + container);
builder.CloseComponent();
}
};
}
protected override Task OnParametersSetAsync()
{
ModuleState = Module; // passed in from Pane component
container = ModuleState.ContainerType;
if (PageState.ModuleId != -1 && PageState.Control != "")
{
container = Constants.DefaultAdminContainer;
}
return Task.CompletedTask;
}
}

View File

@ -1,5 +1,7 @@
@using Oqtane.Services
@using Oqtane.Models
@using Oqtane.Shared
@namespace Oqtane.Shared
@inject IUriHelper UriHelper
@inject IInstallationService InstallationService
@inject IUserService UserService
@ -82,10 +84,10 @@
<tbody>
<tr>
<td>
<label for="Title" class="control-label" style="font-weight: bold">Username: </label>
<label for="Title" class="control-label" style="font-weight: bold">Email: </label>
</td>
<td>
<input type="text" id="Email" class="form-control" @bind="@HostUsername" />
<input type="text" id="Email" class="form-control" @bind="@Email" />
</td>
</tr>
<tr>
@ -102,7 +104,7 @@
</div>
<div class="row">
<div class="mx-auto text-center">
<button class="btn btn-success" @onclick="@Install">Install Now</button><br /><br />
<button type="button" class="btn btn-success" @onclick="@Install">Install Now</button><br /><br />
@((MarkupString)@Message)
</div>
<div class="loading" style="@LoadingDisplay"></div>
@ -110,14 +112,12 @@
</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 Email = "";
private string HostPassword = "";
private string Message = "";
@ -165,12 +165,14 @@ private async Task Install()
if (response.Success)
{
User user = new User();
user.Username = HostUsername;
user.DisplayName = HostUsername;
user.SiteId = 1;
user.Username = Email;
user.DisplayName = Email;
user.Email = Email;
user.IsHost = true;
user.Password = HostPassword;
user.IsSuperUser = true;
user.Roles = "";
await UserService.AddUserAsync(user);
user = await UserService.AddUserAsync(user);
UriHelper.NavigateTo("", true);
}
else

View File

@ -85,5 +85,20 @@ namespace Oqtane.Shared
return Task.CompletedTask;
}
}
public Task UploadFiles(string posturl, string folder, string name)
{
try
{
jsRuntime.InvokeAsync<string>(
"interop.uploadFiles",
posturl, folder, name);
return Task.CompletedTask;
}
catch
{
return Task.CompletedTask;
}
}
}
}

View File

@ -1,5 +1,7 @@
@using Oqtane.Models
@using Oqtane.Shared
@using Oqtane.Modules
@namespace Oqtane.Shared
@DynamicComponent
@ -12,7 +14,7 @@
RenderFragment DynamicComponent { get; set; }
protected override void OnInit()
protected override void OnParametersSet()
{
DynamicComponent = builder =>
{
@ -21,7 +23,11 @@
{
typename = Constants.DefaultSettingsControl;
}
Type moduleType = Type.GetType(typename);
Type moduleType = null;
if (typename != null)
{
moduleType = Type.GetType(typename);
}
if (moduleType != null)
{
builder.OpenComponent(0, moduleType);
@ -29,7 +35,10 @@
}
else
{
// module control does not exist with typename specified
// module does not exist with typename specified
builder.OpenComponent(0, Type.GetType(Constants.ModuleMessageControl));
builder.AddAttribute(1, "Message", "Error Loading Component For Module " + ModuleState.ModuleDefinitionName);
builder.CloseComponent();
}
};
}

View File

@ -19,5 +19,8 @@ namespace Oqtane.Shared
public Dictionary<string, string> QueryString { get; set; }
public int ModuleId { get; set; }
public string Control { get; set; }
public bool EditMode { get; set; }
public bool DesignMode { get; set; }
public int Reload { get; set; }
}
}

View File

@ -3,13 +3,18 @@
@using Oqtane.Modules
@using Oqtane.Models
@using Oqtane.Shared
@using Oqtane.Security
@using System.Linq
@namespace Oqtane.Shared
@inject IUserService UserService
@inject IModuleService ModuleService
@inject IModuleDefinitionService ModuleDefinitionService
<div class="@paneadminborder">
@if (panetitle != "")
{
@((MarkupString)panetitle)
}
@DynamicComponent
</div>
@ -18,20 +23,25 @@
protected PageState PageState { get; set; }
[Parameter]
private string Name { get; set; }
public string Name { get; set; }
RenderFragment DynamicComponent { get; set; }
string paneadminborder = "";
string panetitle = "";
protected override void OnInit()
protected override void OnParametersSet()
{
if (UserService.IsAuthorized(PageState.User, PageState.Page.EditPermissions) && Name != Constants.AdminPane)
if (PageState.DesignMode && UserSecurity.IsAuthorized(PageState.User, "Edit", PageState.Page.Permissions) && Name != Constants.AdminPane)
{
paneadminborder = "pane-admin-border";
panetitle = "<div class=\"pane-admin-title\">" + Name + " Pane</div>";
}
else
{
paneadminborder = "";
panetitle = "";
}
DynamicComponent = builder =>
{
@ -50,38 +60,38 @@
Type moduleType = Type.GetType(typename);
if (moduleType != null)
{
var moduleobject = Activator.CreateInstance(moduleType);
// verify security access level for this module control
SecurityAccessLevelEnum SecurityAccessLevel = (SecurityAccessLevelEnum)moduleType.GetProperty("SecurityAccessLevel").GetValue(moduleobject, null);
bool authorized = false;
switch (SecurityAccessLevel)
if (PageState.Control == "Settings")
{
case SecurityAccessLevelEnum.Anonymous:
authorized = UserSecurity.IsAuthorized(PageState.User, "Edit", PageState.Page.Permissions);
}
else
{
// verify security access level for this module control
switch (module.SecurityAccessLevel)
{
case SecurityAccessLevel.Anonymous:
authorized = true;
break;
case SecurityAccessLevelEnum.View:
authorized = UserService.IsAuthorized(PageState.User, module.ViewPermissions);
case SecurityAccessLevel.View:
authorized = UserSecurity.IsAuthorized(PageState.User, "View", module.Permissions);
break;
case SecurityAccessLevelEnum.Edit:
authorized = UserService.IsAuthorized(PageState.User, module.EditPermissions);
case SecurityAccessLevel.Edit:
authorized = UserSecurity.IsAuthorized(PageState.User, "Edit", module.Permissions);
break;
case SecurityAccessLevelEnum.Admin:
authorized = UserService.IsAuthorized(PageState.User, Constants.AdminRole);
case SecurityAccessLevel.Admin:
authorized = UserSecurity.IsAuthorized(PageState.User, Constants.AdminRole);
break;
case SecurityAccessLevelEnum.Host:
authorized = PageState.User.IsSuperUser;
case SecurityAccessLevel.Host:
authorized = UserSecurity.IsAuthorized(PageState.User, Constants.HostRole);
break;
}
}
if (authorized)
{
if (PageState.Control != "Settings")
if (PageState.Control != "Settings" && module.ControlTitle != "")
{
// get module control title
string title = (string)moduleType.GetProperty("Title").GetValue(moduleobject);
if (title != "")
{
module.Title = title;
}
module.Title = module.ControlTitle;
}
builder.OpenComponent(0, Type.GetType(Constants.DefaultContainer));
builder.AddAttribute(1, "Module", module);
@ -103,7 +113,7 @@
if (module != null && module.Pane == Name)
{
// check if user is authorized to view module
if (UserService.IsAuthorized(PageState.User, module.ViewPermissions))
if (UserSecurity.IsAuthorized(PageState.User, "View", module.Permissions))
{
builder.OpenComponent(0, Type.GetType(Constants.DefaultContainer));
builder.AddAttribute(1, "Module", module);
@ -116,10 +126,11 @@
foreach (Module module in PageState.Modules.Where(item => item.Pane == Name).OrderBy(x => x.Order).ToArray())
{
// check if user is authorized to view module
if (UserService.IsAuthorized(PageState.User, module.ViewPermissions))
if (UserSecurity.IsAuthorized(PageState.User, "View", module.Permissions))
{
builder.OpenComponent(0, Type.GetType(Constants.DefaultContainer));
builder.AddAttribute(1, "Module", module);
builder.SetKey(module.PageModuleId);
builder.CloseComponent();
}
}

View File

@ -1,5 +1,6 @@
@using System
@using Oqtane.Shared
@namespace Oqtane.Shared
@DynamicComponent
@ -9,7 +10,7 @@
RenderFragment DynamicComponent { get; set; }
protected override void OnInit()
protected override void OnParametersSet()
{
DynamicComponent = builder =>
{

View File

@ -1,17 +1,18 @@
@using System
@using Oqtane.Services
@using Oqtane.Models
@using Oqtane.Modules
@using System.Linq
@using System.Collections.Generic
@using Oqtane.Shared
@using Microsoft.JSInterop
@using Oqtane.Security
@using Microsoft.AspNetCore.Components.Routing
@namespace Oqtane.Shared
@inject AuthenticationStateProvider AuthenticationStateProvider
@inject SiteState SiteState
@inject IUriHelper UriHelper
@inject INavigationInterception NavigationInterception
@inject IComponentContext ComponentContext
@inject IJSRuntime jsRuntime
@inject IAliasService AliasService
@inject ITenantService TenantService
@inject ISiteService SiteService
@ -26,9 +27,11 @@
@code {
[CascadingParameter] PageState PageState { get; set; }
[CascadingParameter]
PageState PageState { get; set; }
[Parameter] Action<PageState> OnStateChange { get; set; }
[Parameter]
public Action<PageState> OnStateChange { get; set; }
PageState pagestate;
RenderFragment DynamicComponent { get; set; }
@ -36,14 +39,14 @@ RenderFragment DynamicComponent { get; set; }
string _absoluteUri;
bool _navigationInterceptionEnabled;
protected override void OnInit()
protected override void OnInitialized()
{
_absoluteUri = UriHelper.GetAbsoluteUri();
UriHelper.OnLocationChanged += OnLocationChanged;
DynamicComponent = builder =>
{
if (pagestate != null)
if (PageState != null)
{
builder.OpenComponent(0, Type.GetType(Constants.DefaultPage));
builder.CloseComponent();
@ -59,9 +62,17 @@ public void Dispose()
protected override async Task OnParametersSetAsync()
{
if (PageState == null)
{
// misconfigured api calls should not be processed through the router
if (!_absoluteUri.Contains("~/api/"))
{
await Refresh();
}
else
{
System.Diagnostics.Debug.WriteLine(this.GetType().FullName + ": Error: API call to " + _absoluteUri + " is not mapped to a Controller");
}
}
}
private async Task Refresh()
@ -75,67 +86,52 @@ private async Task Refresh()
Page page;
User user;
List<Module> modules;
int moduleid = -1;
string control = "";
bool editmode = false;
bool designmode = false;
int reload = 0;
bool reload = false;
if (PageState == null)
if (PageState != null)
{
reload = PageState.Reload;
editmode = PageState.EditMode;
designmode = PageState.DesignMode;
}
if (PageState == null || reload == Constants.ReloadApplication)
{
moduledefinitions = await ModuleDefinitionService.GetModuleDefinitionsAsync();
themes = await ThemeService.GetThemesAsync();
aliases = await AliasService.GetAliasesAsync();
alias = null;
}
else
{
moduledefinitions = PageState.ModuleDefinitions;
themes = PageState.Themes;
aliases = PageState.Aliases;
alias = PageState.Alias;
}
// check if site has changed
if (alias == null || GetAlias(_absoluteUri, aliases).Name != alias.Name)
{
alias = GetAlias(_absoluteUri, aliases);
SiteState.Alias = alias; // set state for services
reload = true;
reload = Constants.ReloadSite;
}
if (PageState == null || reload == true)
if (PageState == null || reload <= Constants.ReloadSite)
{
moduledefinitions = await ModuleDefinitionService.GetModuleDefinitionsAsync();
themes = await ThemeService.GetThemesAsync();
site = await SiteService.GetSiteAsync(alias.SiteId);
}
else
{
moduledefinitions = PageState.ModuleDefinitions;
themes = PageState.Themes;
site = PageState.Site;
}
if (site != null || reload == true)
if (site != null)
{
string path = new Uri(_absoluteUri).PathAndQuery.Substring(1);
if (path.EndsWith("/")) { path = path.Substring(0, path.Length - 1); }
if (alias.Path != "")
{
path = path.Replace(alias.Path, "");
if (path.StartsWith("/")) { path = path.Substring(1); }
}
Dictionary<string, string> querystring = ParseQueryString(path);
if (querystring.ContainsKey("reload"))
{
reload = true;
}
user = null;
if (PageState == null || reload == true)
{
var authState = await AuthenticationStateProvider.GetAuthenticationStateAsync();
if (authState.User.Identity.IsAuthenticated)
{
user = await UserService.GetUserAsync(authState.User.Identity.Name);
}
}
else
{
user = PageState.User;
}
if (PageState == null || reload == true)
if (PageState == null || reload >= Constants.ReloadSite)
{
pages = await PageService.GetPagesAsync(site.SiteId);
}
@ -144,12 +140,48 @@ private async Task Refresh()
pages = PageState.Pages;
}
// get Url path and querystring
string path = new Uri(_absoluteUri).PathAndQuery.Substring(1);
// parse querystring and remove
Dictionary<string, string> querystring = new Dictionary<string, string>();
if (path.IndexOf("?") != -1)
{
querystring = ParseQueryString(path);
path = path.Substring(0, path.IndexOf("?"));
}
if (PageState == null || reload == true)
// format path and remove alias
path = path.Replace("//", "/");
if (!path.EndsWith("/")) { path += "/"; }
if (alias.Path != "")
{
path = path.Replace(alias.Path + "/", "");
}
// extract admin route elements from path
string[] segments = path.Split(new[] { '/' }, StringSplitOptions.RemoveEmptyEntries);
int result;
if (segments.Length >= 2 && int.TryParse(segments[segments.Length - 2], out result))
{
// path has moduleid and control specification ie. page/moduleid/control/
control = segments[segments.Length - 1];
moduleid = result;
path = path.Replace(moduleid.ToString() + "/" + control + "/", "");
}
else
{
if (segments.Length >= 2 && int.TryParse(segments[segments.Length - 2], out result))
{
// path has only moduleid specification ie. page/moduleid/
moduleid = result;
path = path.Replace(moduleid.ToString() + "/", "");
}
}
// remove trailing slash so it can be used as a key for Pages
if (path.EndsWith("/")) path = path.Substring(0, path.Length - 1);
if (PageState == null || reload >= Constants.ReloadPage)
{
page = pages.Where(item => item.Path == path).FirstOrDefault();
}
@ -157,16 +189,33 @@ private async Task Refresh()
{
page = PageState.Page;
}
// check if page has changed
if (page.Path != path)
{
page = pages.Where(item => item.Path == path).FirstOrDefault();
reload = true;
reload = Constants.ReloadPage;
editmode = page.EditMode;
designmode = false;
}
user = null;
if (PageState == null || reload >= Constants.ReloadPage)
{
var authState = await AuthenticationStateProvider.GetAuthenticationStateAsync();
if (authState.User.Identity.IsAuthenticated)
{
user = await UserService.GetUserAsync(authState.User.Identity.Name, site.SiteId);
}
}
else
{
user = PageState.User;
}
if (page != null)
{
// check if user is authorized to view page
if (UserService.IsAuthorized(user, page.ViewPermissions))
if (UserSecurity.IsAuthorized(user, "View", page.Permissions))
{
pagestate = new PageState();
pagestate.ModuleDefinitions = moduledefinitions;
@ -179,23 +228,15 @@ private async Task Refresh()
pagestate.User = user;
pagestate.Uri = new Uri(_absoluteUri, UriKind.Absolute);
pagestate.QueryString = querystring;
pagestate.ModuleId = -1;
pagestate.Control = "";
pagestate.ModuleId = moduleid;
pagestate.Control = control;
if (querystring.ContainsKey("mid"))
{
pagestate.ModuleId = int.Parse(querystring["mid"]);
}
if (querystring.ContainsKey("ctl"))
{
pagestate.Control = querystring["ctl"];
}
if (PageState != null && (PageState.ModuleId != pagestate.ModuleId || PageState.Control != pagestate.Control))
{
reload = true;
reload = Constants.ReloadPage;
}
if (PageState == null || reload == true)
if (PageState == null || reload >= Constants.ReloadPage)
{
modules = await ModuleService.GetModulesAsync(page.PageId);
modules = ProcessModules(modules, moduledefinitions, pagestate.Control, page.Panes);
@ -205,6 +246,9 @@ private async Task Refresh()
modules = PageState.Modules;
}
pagestate.Modules = modules;
pagestate.EditMode = editmode;
pagestate.DesignMode = designmode;
pagestate.Reload = Constants.ReloadReset;
OnStateChange?.Invoke(pagestate);
}
@ -245,7 +289,7 @@ private Dictionary<string, string> ParseQueryString(string path)
Dictionary<string, string> querystring = new Dictionary<string, string>();
if (path.IndexOf("?") != -1)
{
foreach (string kvp in path.Substring(path.IndexOf("?") + 1).Split('&'))
foreach (string kvp in path.Substring(path.IndexOf("?") + 1).Split(new[] { '&' }, StringSplitOptions.RemoveEmptyEntries))
{
if (kvp != "")
{
@ -283,7 +327,7 @@ private List<Module> ProcessModules(List<Module> modules, List<ModuleDefinition>
string typename = moduledefinition.ControlTypeTemplate;
if (moduledefinition.ControlTypeRoutes != "")
{
foreach (string route in moduledefinition.ControlTypeRoutes.Split(';'))
foreach (string route in moduledefinition.ControlTypeRoutes.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries))
{
if (route.StartsWith(control + "="))
{
@ -292,6 +336,22 @@ private List<Module> ProcessModules(List<Module> modules, List<ModuleDefinition>
}
}
module.ModuleType = typename.Replace("{Control}", control);
// get IModuleControl properties
typename = module.ModuleType;
if (control == "Settings")
{
typename = Constants.DefaultSettingsControl;
}
Type moduletype = Type.GetType(typename);
if (moduletype != null)
{
var moduleobject = Activator.CreateInstance(moduletype);
module.SecurityAccessLevel = (SecurityAccessLevel)moduletype.GetProperty("SecurityAccessLevel").GetValue(moduleobject, null);
module.ControlTitle = (string)moduletype.GetProperty("Title").GetValue(moduleobject);
module.Actions = (string)moduletype.GetProperty("Actions").GetValue(moduleobject);
module.UseAdminContainer = (bool)moduletype.GetProperty("UseAdminContainer").GetValue(moduleobject);
}
}
// ensure module's pane exists in current page and if not, assign it to the Admin pane

View File

@ -1,4 +1,6 @@
@using Oqtane.Shared
@using Oqtane.Modules
@namespace Oqtane.Shared
@DynamicComponent
@ -7,7 +9,7 @@
RenderFragment DynamicComponent { get; set; }
protected override void OnInit()
protected override void OnParametersSet()
{
DynamicComponent = builder =>
{
@ -20,6 +22,9 @@
else
{
// theme does not exist with type specified
builder.OpenComponent(0, Type.GetType(Constants.ModuleMessageControl));
builder.AddAttribute(1, "Message", "Error Loading Page Theme " + PageState.Page.ThemeType);
builder.CloseComponent();
}
};
}

View File

@ -1,57 +1,58 @@
using System;
using Oqtane.Models;
using Oqtane.Models;
using System;
using System.Collections.Generic;
using System.Linq;
namespace Oqtane.Shared
{
public class Utilities
{
public static string NavigateUrl(PageState pagestate)
{
return NavigateUrl(pagestate, pagestate.Page.Path, false);
}
public static string NavigateUrl(PageState pagestate, bool reload)
public static string NavigateUrl(string alias, string path, string parameters)
{
return NavigateUrl(pagestate, pagestate.Page.Path, reload);
string url = "";
if (alias != "")
{
url += alias + "/";
}
public static string NavigateUrl(PageState pagestate, string path)
if (path != "" && path != "/")
{
return NavigateUrl(pagestate, path, false);
url += path + "/";
}
public static string NavigateUrl(PageState pagestate, string path, bool reload)
if (url.EndsWith("/"))
{
string url = pagestate.Alias.Path + "/" + path;
if (reload)
{
if (url.Contains("?"))
{
url += "&reload=true";
url = url.Substring(0, url.Length - 1);
}
else
if (!string.IsNullOrEmpty(parameters))
{
url += "?reload=true";
url += "?" + parameters;
}
if (!url.StartsWith("/"))
{
url = "/" + url;
}
return url;
}
public static string EditUrl(PageState pagestate, Module modulestate, string action)
public static string EditUrl(string alias, string path, int moduleid, string action, string parameters)
{
return EditUrl(pagestate, modulestate, action, "");
string url = NavigateUrl(alias, path, "");
if (url == "/") url = "";
if (moduleid != -1)
{
url += "/" + moduleid.ToString();
}
public static string EditUrl(PageState pagestate, Module modulestate, string action, string parameters)
if (moduleid != -1 && action != "")
{
string url = pagestate.Alias.Path + "/" + pagestate.Page.Path + "?mid=" + modulestate.ModuleId.ToString();
if (action != "")
{
url += "&ctl=" + action;
url += "/" + action;
}
if (!string.IsNullOrEmpty(parameters))
{
url += "&" + parameters;
url += "?" + parameters;
}
if (!url.StartsWith("/"))
{
url = "/" + url;
}
return url;
}

View File

@ -46,7 +46,11 @@ namespace Oqtane.Client
services.AddScoped<IModuleService, ModuleService>();
services.AddScoped<IPageModuleService, PageModuleService>();
services.AddScoped<IUserService, UserService>();
services.AddScoped<IProfileService, ProfileService>();
services.AddScoped<IRoleService, RoleService>();
services.AddScoped<IUserRoleService, UserRoleService>();
services.AddScoped<ISettingService, SettingService>();
services.AddScoped<IFileService, FileService>();
// dynamically register module contexts and repository services
Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
@ -57,7 +61,7 @@ namespace Oqtane.Client
.ToArray();
foreach (Type implementationtype in implementationtypes)
{
Type servicetype = Type.GetType(implementationtype.FullName.Replace(implementationtype.Name, "I" + implementationtype.Name));
Type servicetype = Type.GetType(implementationtype.AssemblyQualifiedName.Replace(implementationtype.Name, "I" + implementationtype.Name));
if (servicetype != null)
{
services.AddScoped(servicetype, implementationtype); // traditional service interface

View File

@ -1,7 +1,6 @@
@using Oqtane.Shared
@using Oqtane.Themes
@using Oqtane.Client.Themes.Controls
@using Oqtane.Client.Shared
@using Oqtane.Themes.Controls
@namespace Oqtane.Themes
@inherits ContainerBase
<div id="modal" class="modal" style="display: block">
<div class="modal-content">
@ -23,7 +22,7 @@
@code {
string closeurl;
protected override void OnInit()
protected override void OnInitialized()
{
closeurl = NavigateUrl();
}

View File

@ -16,32 +16,37 @@ namespace Oqtane.Themes
public string NavigateUrl()
{
return Utilities.NavigateUrl(PageState);
}
public string NavigateUrl(bool reload)
{
return Utilities.NavigateUrl(PageState, reload);
return NavigateUrl(PageState.Page.Path);
}
public string NavigateUrl(string path)
{
return Utilities.NavigateUrl(PageState, path);
return NavigateUrl(path, "");
}
public string NavigateUrl(string path, bool reload)
public string NavigateUrl(string path, string parameters)
{
return Utilities.NavigateUrl(PageState, path, reload);
return Utilities.NavigateUrl(PageState.Alias.Path, path, parameters);
}
public string EditUrl(string action)
{
return Utilities.EditUrl(PageState, ModuleState, action, "");
}
public string EditUrl(string action, string parameters)
{
return Utilities.EditUrl(PageState, ModuleState, action, parameters);
}
return EditUrl(ModuleState.ModuleId, action, parameters);
}
public string EditUrl(int moduleid, string action)
{
return EditUrl(moduleid, action, "");
}
public string EditUrl(int moduleid, string action, string parameters)
{
return EditUrl(PageState.Page.Path, moduleid, action, parameters);
}
public string EditUrl(string path, int moduleid, string action, string parameters)
{
return Utilities.EditUrl(PageState.Alias.Path, path, moduleid, action, parameters);
}
}
}

View File

@ -3,6 +3,8 @@
@using Oqtane.Models
@using Oqtane.Themes
@using Oqtane.Shared
@using Oqtane.Security
@namespace Oqtane.Themes.Controls
@inherits ThemeObjectBase
@inject IUriHelper UriHelper
@inject IUserService UserService
@ -11,6 +13,8 @@
@inject IModuleService ModuleService
@inject IPageModuleService PageModuleService
@if (UserSecurity.IsAuthorized(PageState.User, "Edit", PageState.Page.Permissions))
{
<div id="actions" class="overlay">
<a href="javascript:void(0)" class="closebtn" onclick="closeActions()">x</a>
<div class="overlay-content">
@ -44,7 +48,7 @@
<label for="Pane" class="control-label" style="color: white !important;">Pane: </label>
<select class="form-control" @bind="@pane">
<option value="">&lt;Select Pane&gt;</option>
@foreach (string pane in PageState.Page.Panes.Split(';'))
@foreach (string pane in PageState.Page.Panes.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries))
{
<option value="@pane">@pane Pane</option>
}
@ -68,10 +72,24 @@
</div>
</div>
</div>
<span class="oi oi-menu" style="@display" onclick="openActions()"></span>
@if (PageState.EditMode)
{
<button type="button" class="btn btn-outline-primary active" data-toggle="button" aria-pressed="true" autocomplete="off" @onclick="EditMode">
<span class="oi oi-pencil"></span>
</button>
}
else
{
<button type="button" class="btn btn-outline-primary" data-toggle="button" aria-pressed="false" autocomplete="off" @onclick="EditMode">
<span class="oi oi-pencil"></span>
</button>
}
<span class="oi oi-menu" onclick="openActions()"></span>
}
@code {
string display = "display: none";
List<ModuleDefinition> moduledefinitions;
Dictionary<string, string> containers = new Dictionary<string, string>();
int pagemanagementmoduleid = -1;
@ -80,7 +98,9 @@
string title = "";
string containertype;
protected override async Task OnInitAsync()
protected override async Task OnInitializedAsync()
{
if (UserSecurity.IsAuthorized(PageState.User, "Edit", PageState.Page.Permissions))
{
moduledefinitions = PageState.ModuleDefinitions;
containers = ThemeService.GetContainerTypes(PageState.Themes);
@ -89,19 +109,17 @@
{
pagemanagementmoduleid = modules.FirstOrDefault().ModuleId;
}
if (UserService.IsAuthorized(PageState.User, PageState.Page.EditPermissions))
{
display = "display: inline";
}
}
private async Task AddModule()
{
if (UserSecurity.IsAuthorized(PageState.User, "Edit", PageState.Page.Permissions))
{
Module module = new Module();
module.SiteId = PageState.Site.SiteId;
module.ModuleDefinitionName = moduledefinitionname;
module.ViewPermissions = PageState.Page.ViewPermissions;
module.EditPermissions = PageState.Page.EditPermissions;
module.Permissions = PageState.Page.Permissions;
await ModuleService.AddModuleAsync(module);
List<Module> modules = await ModuleService.GetModulesAsync(PageState.Site.SiteId, moduledefinitionname);
@ -116,10 +134,14 @@
}
pagemodule.Title = title;
pagemodule.Pane = pane;
pagemodule.Order = 0;
pagemodule.Order = int.MaxValue;
pagemodule.ContainerType = containertype;
await PageModuleService.AddPageModuleAsync(pagemodule);
UriHelper.NavigateTo(NavigateUrl(true));
await PageModuleService.UpdatePageModuleOrderAsync(pagemodule.PageId, pagemodule.Pane);
PageState.Reload = Constants.ReloadPage;
UriHelper.NavigateTo(NavigateUrl());
}
}
private string PageUrl(string action)
@ -130,16 +152,35 @@
switch (action)
{
case "Add":
url = "admin/pages?mid=" + pagemanagementmoduleid.ToString() + "&ctl=" + action;
url = EditUrl("admin/pages", pagemanagementmoduleid, action, "");
break;
case "Edit":
url = "admin/pages?mid=" + pagemanagementmoduleid.ToString() + "&ctl=" + action + "&id=" + PageState.Page.PageId.ToString();
url = EditUrl("admin/pages", pagemanagementmoduleid, action, "id=" + PageState.Page.PageId.ToString());
break;
case "Delete":
url = "admin/pages?mid=" + pagemanagementmoduleid.ToString() + "&ctl=" + action + "&id=" + PageState.Page.PageId.ToString();
url = EditUrl("admin/pages", pagemanagementmoduleid, action, "id=" + PageState.Page.PageId.ToString());
break;
}
}
return url;
}
private void EditMode()
{
if (UserSecurity.IsAuthorized(PageState.User, "Edit", PageState.Page.Permissions))
{
if (PageState.EditMode)
{
PageState.EditMode = false;
PageState.DesignMode = false;
}
else
{
PageState.EditMode = true;
PageState.DesignMode = true;
}
PageState.Reload = Constants.ReloadPage;
UriHelper.NavigateTo(NavigateUrl(PageState.Page.Path, "edit=" + PageState.EditMode.ToString().ToLower()));
}
}
}

View File

@ -2,8 +2,8 @@
@using Oqtane.Services
@using Oqtane.Providers
@using Oqtane.Shared
@using Oqtane.Models
@using Microsoft.JSInterop
@namespace Oqtane.Themes.Controls
@inherits ThemeObjectBase
@inject IUriHelper UriHelper
@inject IUserService UserService
@ -26,7 +26,12 @@
@code {
private void LoginUser()
{
UriHelper.NavigateTo(NavigateUrl("login?returnurl=" + PageState.Page.Path));
string returnurl = PageState.Alias.Path;
if (PageState.Page.Path != "/")
{
returnurl += "/" + PageState.Page.Path;
}
UriHelper.NavigateTo("login?returnurl=" + returnurl);
}
private async Task LogoutUser()
@ -38,13 +43,16 @@
{
// server-side Blazor
var interop = new Interop(jsRuntime);
await interop.SubmitForm("/logout/", "");
string antiforgerytoken = await interop.GetElementByName("__RequestVerificationToken");
var fields = new { __RequestVerificationToken = antiforgerytoken, returnurl = (PageState.Alias.Path + "/" + PageState.Page.Path) };
await interop.SubmitForm("/logout/", fields);
}
else
{
// client-side Blazor
authstateprovider.NotifyAuthenticationChanged();
UriHelper.NavigateTo(NavigateUrl("login", true));
PageState.Reload = Constants.ReloadSite;
UriHelper.NavigateTo(NavigateUrl(PageState.Page.Path, "logout"));
}
}
}

View File

@ -1,4 +1,5 @@
@using Oqtane.Themes
@namespace Oqtane.Themes.Controls
@inherits ThemeObjectBase
@((MarkupString)logo)
@ -6,11 +7,12 @@
@code {
string logo = "";
protected override void OnInit()
protected override Task OnParametersSetAsync()
{
if (PageState.Site.Logo != "")
{
logo = "<a href=\"" + PageState.Alias.Url + "\"><img src=\"/Sites/" + PageState.Site.SiteId.ToString() + "/" + PageState.Site.Logo + "\" alt=\"" + PageState.Site.Name + "\"/></a>";
}
logo = "<a href=\"" + PageState.Alias.Url + "\"><img src=\"" + PageState.Alias.SiteRootUrl + PageState.Site.Logo + "\" alt=\"" + PageState.Site.Name + "\"/></a>";
}
return Task.CompletedTask;
}
}

View File

@ -2,6 +2,8 @@
@using Oqtane.Themes
@using Oqtane.Services
@using Oqtane.Models;
@using Oqtane.Security
@namespace Oqtane.Themes.Controls
@inherits ThemeObjectBase
@inject IPageService PageService
@inject IUserService UserService
@ -18,11 +20,11 @@
}
@foreach (var p in pages)
{
if (p.IsNavigation && UserService.IsAuthorized(PageState.User, p.ViewPermissions))
if (p.IsNavigation && UserSecurity.IsAuthorized(PageState.User, "View", p.Permissions))
{
string url = NavigateUrl(p.Path);
<li class="nav-item px-3">
<NavLink class="nav-link" href="@url" Match="NavLinkMatch.All">
<NavLink @key="@p.PageId" class="nav-link" href="@url" Match="NavLinkMatch.All">
<span class="oi @p.Icon" aria-hidden="true"></span> @p.Name
</NavLink>
</li>
@ -34,13 +36,13 @@
List<Page> pages;
Page parent = null;
protected override void OnInit()
protected override Task OnParametersSetAsync()
{
// if current page has no children
if (PageState.Pages.Where(item => item.ParentId == PageState.Page.PageId).FirstOrDefault() == null)
{
// display list of pages which have same parent as current page
pages = PageState.Pages.Where(item => item.ParentId == PageState.Page.ParentId).ToList();
pages = PageState.Pages.Where(item => item.ParentId == PageState.Page.ParentId).OrderBy(item => item.Order).ToList();
// if current page has parent
if (PageState.Page.ParentId != null)
{
@ -50,9 +52,10 @@
else
{
// display list of pages which are children of current page
pages = PageState.Pages.Where(item => item.ParentId == PageState.Page.PageId).ToList();
pages = PageState.Pages.Where(item => item.ParentId == PageState.Page.PageId).OrderBy(item => item.Order).ToList();
// current page is parent
parent = PageState.Pages.Where(item => item.ParentId == PageState.Page.ParentId).FirstOrDefault();
}
return Task.CompletedTask;
}
}

View File

@ -0,0 +1,68 @@
@using Microsoft.AspNetCore.Components.Routing
@using Oqtane.Themes
@using Oqtane.Services
@using Oqtane.Models;
@using Oqtane.Security
@namespace Oqtane.Themes.Controls
@inherits ThemeObjectBase
@inject IUserService UserService
@if (menu != "")
{
@((MarkupString)menu)
}
@code {
string menu = "";
protected override void OnInitialized()
{
int level = -1;
int securitylevel = int.MaxValue;
menu = "<ul class=\"nav flex-column\">\n";
foreach (Page p in PageState.Pages.Where(item => item.IsNavigation))
{
for (int l = p.Level; l < level; l++)
{
menu += "</ul>\n";
menu += "</div>\n";
}
if (UserSecurity.IsAuthorized(PageState.User, "View", p.Permissions) && p.Level <= securitylevel)
{
securitylevel = int.MaxValue;
if (p.HasChildren)
{
menu += "<li class=\"nav-item px-3\">\n";
menu += "<a class=\"nav-link collapsed\" href=\"#submenu" + p.PageId.ToString() + "\" data-toggle=\"collapse\" data-target=\"#submenu" + p.PageId.ToString() + "\">";
menu += "<span class=\"oi " + p.Icon + "\" aria-hidden=\"true\"></span>" + p.Name;
menu += "</a>\n";
menu += "<div class=\"collapse\" id=\"submenu" + p.PageId.ToString() + "\" aria-expanded=\"false\">\n";
menu += "<ul class=\"nav flex-column\">\n";
}
else
{
menu += "<li class=\"nav-item px-3\">\n";
menu += "<a class=\"nav-link\" href=\"" + NavigateUrl(p.Path) + "\">";
menu += "<span class=\"oi " + p.Icon + "\" aria-hidden=\"true\"></span>" + p.Name;
menu += "</a>\n";
menu += "</li>\n";
}
level = p.Level;
}
else
{
if (securitylevel == int.MaxValue)
{
securitylevel = p.Level;
}
}
}
for (int l = 0; l < level; l++)
{
menu += "</ul>\n";
menu += "</div>\n";
}
menu += "</ul>";
}
}

View File

@ -1,13 +1,18 @@
@using Oqtane.Themes
@using Oqtane.Services
@using Oqtane.Models
@using Oqtane.Shared
@using Oqtane.Security
@namespace Oqtane.Themes.Controls
@inherits ContainerBase
@inject IUriHelper UriHelper
@inject IUserService UserService
@inject IPageModuleService PageModuleService
<div class="dropdown" style="@display">
<button class="btn dropdown-toggle" type="button" id="dropdownMenuButton" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"></button>
@if (PageState.DesignMode && UserSecurity.IsAuthorized(PageState.User, "Edit", ModuleState.Permissions))
{
<div class="dropdown">
<button type="button" class="btn dropdown-toggle" id="dropdownMenuButton" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"></button>
<div class="dropdown-menu" aria-labelledby="dropdownMenuButton">
@foreach (var action in actions)
{
@ -15,23 +20,33 @@
}
</div>
</div>
}
@code {
string display = "display: none";
List<ActionViewModel> actions;
protected override void OnInit()
protected override void OnParametersSet()
{
if (PageState.EditMode && UserSecurity.IsAuthorized(PageState.User, "Edit", ModuleState.Permissions))
{
actions = new List<ActionViewModel>();
if (ModuleState.PaneModuleIndex > 0)
{
actions.Add(new ActionViewModel { Action = "up", Name = "Move Up" });
actions.Add(new ActionViewModel { Action = "<<", Name = "Move To Top" });
}
if (ModuleState.PaneModuleIndex > 0)
{
actions.Add(new ActionViewModel { Action = "<", Name = "Move Up" });
}
if (ModuleState.PaneModuleIndex < (ModuleState.PaneModuleCount - 1))
{
actions.Add(new ActionViewModel { Action = "down", Name = "Move Down" });
actions.Add(new ActionViewModel { Action = ">", Name = "Move Down" });
}
foreach (string pane in PageState.Page.Panes.Split(';'))
if (ModuleState.PaneModuleIndex < (ModuleState.PaneModuleCount - 1))
{
actions.Add(new ActionViewModel { Action = ">>", Name = "Move To Bottom" });
}
foreach (string pane in PageState.Page.Panes.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries))
{
if (pane != ModuleState.Pane)
{
@ -40,48 +55,57 @@
}
actions.Add(new ActionViewModel { Action = "settings", Name = "Settings" });
actions.Add(new ActionViewModel { Action = "delete", Name = "Delete" });
if (UserService.IsAuthorized(PageState.User, ModuleState.EditPermissions))
{
display = "display: inline";
}
}
protected async Task ModuleAction(string action)
{
PageModule pagemodule = new PageModule();
pagemodule.PageModuleId = ModuleState.PageModuleId;
pagemodule.PageId = ModuleState.PageId;
pagemodule.ModuleId = ModuleState.ModuleId;
pagemodule.Title = ModuleState.Title;
pagemodule.Pane = ModuleState.Pane;
pagemodule.Order = ModuleState.Order;
pagemodule.ContainerType = ModuleState.ContainerType;
if (PageState.EditMode && UserSecurity.IsAuthorized(PageState.User, "Edit", ModuleState.Permissions))
{
PageModule pagemodule = await PageModuleService.GetPageModuleAsync(ModuleState.PageModuleId);
string path = PageState.Page.Path + "?reload=true";
string url = NavigateUrl();
switch (action)
{
case "up":
pagemodule.Order += -1;
case "<<":
pagemodule.Order = 0;
await PageModuleService.UpdatePageModuleAsync(pagemodule);
await PageModuleService.UpdatePageModuleOrderAsync(pagemodule.PageId, pagemodule.Pane);
break;
case "down":
pagemodule.Order += 1;
case "<":
pagemodule.Order -= 3;
await PageModuleService.UpdatePageModuleAsync(pagemodule);
await PageModuleService.UpdatePageModuleOrderAsync(pagemodule.PageId, pagemodule.Pane);
break;
case ">":
pagemodule.Order += 3;
await PageModuleService.UpdatePageModuleAsync(pagemodule);
await PageModuleService.UpdatePageModuleOrderAsync(pagemodule.PageId, pagemodule.Pane);
break;
case ">>":
pagemodule.Order = int.MaxValue;
await PageModuleService.UpdatePageModuleAsync(pagemodule);
await PageModuleService.UpdatePageModuleOrderAsync(pagemodule.PageId, pagemodule.Pane);
break;
case "settings":
if (path == "") { path += "/"; }
path = PageState.Page.Path + "?mid=" + pagemodule.ModuleId.ToString() + "&ctl=Settings";
url = EditUrl(pagemodule.ModuleId, "Settings");
break;
case "delete":
await PageModuleService.DeletePageModuleAsync(pagemodule.PageModuleId);
await PageModuleService.UpdatePageModuleOrderAsync(pagemodule.PageId, pagemodule.Pane);
break;
default: // move to pane
string pane = pagemodule.Pane;
pagemodule.Pane = action;
pagemodule.Order = int.MaxValue; // add to bottom of pane
await PageModuleService.UpdatePageModuleAsync(pagemodule);
await PageModuleService.UpdatePageModuleOrderAsync(pagemodule.PageId, pagemodule.Pane);
await PageModuleService.UpdatePageModuleOrderAsync(pagemodule.PageId, pane);
break;
}
UriHelper.NavigateTo(NavigateUrl(path));
PageState.Reload = Constants.ReloadPage;
UriHelper.NavigateTo(url);
}
}
public class ActionViewModel

View File

@ -1,4 +1,5 @@
@using Oqtane.Themes
@namespace Oqtane.Themes.Controls
@inherits ContainerBase
@title
@ -6,12 +7,13 @@
@code {
string title = "";
protected override void OnInit()
protected override Task OnParametersSetAsync()
{
title = ModuleState.Title;
if (PageState.Control == "Settings")
{
title = PageState.Control;
}
return Task.CompletedTask;
}
}

View File

@ -1,4 +1,5 @@
@using Oqtane.Themes
@namespace Oqtane.Themes.Controls
@inherits ThemeObjectBase
@inject IUriHelper UriHelper
@ -7,7 +8,7 @@
<text>...</text>
</Authorizing>
<Authorized>
<button type="button" class="btn btn-primary" @onclick="@RegisterUser">@context.User.Identity.Name</button>
<button type="button" class="btn btn-primary" @onclick="@UpdateProfile">@context.User.Identity.Name</button>
</Authorized>
<NotAuthorized>
<button type="button" class="btn btn-primary" @onclick="@RegisterUser">Register</button>
@ -21,6 +22,11 @@
{
UriHelper.NavigateTo(NavigateUrl("register"));
}
private void UpdateProfile()
{
UriHelper.NavigateTo(NavigateUrl("profile"));
}
}

View File

@ -1,6 +1,6 @@
@using Oqtane.Themes
@using Oqtane.Client.Themes.Controls
@using Oqtane.Client.Shared
@using Oqtane.Themes.Controls
@using Oqtane.Shared
@namespace Oqtane.Themes
@inherits ContainerBase
<div class="container">
<div class="row px-4">

View File

@ -1,15 +1,10 @@
using System;
using System.Collections.Generic;
namespace Oqtane.Themes
{
public interface ITheme
{
string Name { get; }
string Version { get; }
string Owner { get; }
string Url { get; }
string Contact { get; }
string License { get; }
string Dependencies { get; }
Dictionary<string, string> Properties { get; }
}
}

View File

@ -1,6 +1,7 @@
@using Oqtane.Themes
@using Oqtane.Client.Themes.Controls
@using Oqtane.Client.Shared
@using Oqtane.Themes.Controls
@using Oqtane.Shared
@namespace Oqtane.Themes.Theme1
@inherits ContainerBase
<div class="container">
<div class="row px-4">

View File

@ -1,13 +1,20 @@
namespace Oqtane.Themes.Theme1
using System.Collections.Generic;
namespace Oqtane.Themes.Theme1
{
public class Theme : ITheme
{
public string Name { get { return "Theme1"; } }
public string Version { get { return "1.0.0"; } }
public string Owner { get { return ""; } }
public string Url { get { return ""; } }
public string Contact { get { return ""; } }
public string License { get { return ""; } }
public string Dependencies { get { return ""; } }
public Dictionary<string, string> Properties
{
get
{
Dictionary<string, string> properties = new Dictionary<string, string>
{
{ "Name", "Theme1" },
{ "Version", "1.0.0" }
};
return properties;
}
}
}
}

View File

@ -1,6 +1,7 @@
@using Oqtane.Themes
@using Oqtane.Client.Themes.Controls
@using Oqtane.Client.Shared
@using Oqtane.Themes.Controls
@using Oqtane.Shared
@namespace Oqtane.Themes.Theme1
@inherits ThemeBase
<div class="sidebar">

Some files were not shown because too many files have changed in this diff Show More