Merge pull request #286 from chlupac/Naming

Naming conventions
This commit is contained in:
Shaun Walker 2020-03-14 20:07:10 -04:00 committed by GitHub
commit a39b70242c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
15 changed files with 267 additions and 247 deletions

View File

@ -70,7 +70,9 @@
string _permissions;
string _pageId;
#pragma warning disable 649
PermissionGrid _permissionGrid;
#pragma warning restore 649
RenderFragment DynamicComponent { get; set; }
object _settings;

View File

@ -24,18 +24,18 @@
@code {
public override SecurityAccessLevel SecurityAccessLevel { get { return SecurityAccessLevel.Admin; } }
private async Task DeletePage(Page Page)
private async Task DeletePage(Page page)
{
try
{
Page.IsDeleted = true;
await PageService.UpdatePageAsync(Page);
await logger.LogInformation("Page Deleted {Page}", Page);
page.IsDeleted = true;
await PageService.UpdatePageAsync(page);
await logger.LogInformation("Page Deleted {Page}", page);
NavigationManager.NavigateTo(NavigateUrl("admin/pages"));
}
catch (Exception ex)
{
await logger.LogError(ex, "Error Deleting Page {Page} {Error}", Page, ex.Message);
await logger.LogError(ex, "Error Deleting Page {Page} {Error}", page, ex.Message);
AddModuleMessage("Error Deleting Page", MessageType.Error);
}
}

View File

@ -9,7 +9,7 @@
<label class="control-label">Name: </label>
</td>
<td>
<input class="form-control" @bind="@name" />
<input class="form-control" @bind="@_name" />
</td>
</tr>
<tr>
@ -17,7 +17,7 @@
<label class="control-label">Title: </label>
</td>
<td>
<input class="form-control" @bind="@title" />
<input class="form-control" @bind="@_title" />
</td>
</tr>
<tr>
@ -25,7 +25,7 @@
<label class="control-label">Description: </label>
</td>
<td>
<textarea class="form-control" @bind="@description" rows="5" />
<textarea class="form-control" @bind="@_description" rows="5"></textarea>
</td>
</tr>
<tr>
@ -33,7 +33,7 @@
<label class="control-label">Category: </label>
</td>
<td>
<input class="form-control" @bind="@category" />
<input class="form-control" @bind="@_category" />
</td>
</tr>
<tr>
@ -41,7 +41,7 @@
<label class="control-label">Order: </label>
</td>
<td>
<input class="form-control" @bind="@vieworder" />
<input class="form-control" @bind="@_vieworder" />
</td>
</tr>
<tr>
@ -49,7 +49,7 @@
<label class="control-label">Length: </label>
</td>
<td>
<input class="form-control" @bind="@maxlength" />
<input class="form-control" @bind="@_maxlength" />
</td>
</tr>
<tr>
@ -57,7 +57,7 @@
<label class="control-label">Default Value: </label>
</td>
<td>
<input class="form-control" @bind="@defaultvalue" />
<input class="form-control" @bind="@_defaultvalue" />
</td>
</tr>
<tr>
@ -65,7 +65,7 @@
<label class="control-label">Required? </label>
</td>
<td>
<select class="form-control" @bind="@isrequired">
<select class="form-control" @bind="@_isrequired">
<option value="True">Yes</option>
<option value="False">No</option>
</select>
@ -76,7 +76,7 @@
<label class="control-label">Private? </label>
</td>
<td>
<select class="form-control" @bind="@isprivate">
<select class="form-control" @bind="@_isprivate">
<option value="True">Yes</option>
<option value="False">No</option>
</select>
@ -90,16 +90,16 @@
public override SecurityAccessLevel SecurityAccessLevel { get { return SecurityAccessLevel.Admin; } }
public override string Actions { get { return "Add,Edit"; } }
int profileid = -1;
string name = "";
string title = "";
string description = "";
string category = "";
string vieworder = "0";
string maxlength = "0";
string defaultvalue = "";
string isrequired = "False";
string isprivate = "False";
int _profileid = -1;
string _name = "";
string _title = "";
string _description = "";
string _category = "";
string _vieworder = "0";
string _maxlength = "0";
string _defaultvalue = "";
string _isrequired = "False";
string _isprivate = "False";
protected override async Task OnInitializedAsync()
{
@ -107,25 +107,25 @@
{
if (PageState.QueryString.ContainsKey("id"))
{
profileid = Int32.Parse(PageState.QueryString["id"]);
Profile profile = await ProfileService.GetProfileAsync(profileid);
_profileid = Int32.Parse(PageState.QueryString["id"]);
Profile profile = await ProfileService.GetProfileAsync(_profileid);
if (profile != null)
{
name = profile.Name;
title = profile.Title;
description = profile.Description;
category = profile.Category;
vieworder = profile.ViewOrder.ToString();
maxlength = profile.MaxLength.ToString();
defaultvalue = profile.DefaultValue;
isrequired = profile.IsRequired.ToString();
isprivate = profile.IsPrivate.ToString();
_name = profile.Name;
_title = profile.Title;
_description = profile.Description;
_category = profile.Category;
_vieworder = profile.ViewOrder.ToString();
_maxlength = profile.MaxLength.ToString();
_defaultvalue = profile.DefaultValue;
_isrequired = profile.IsRequired.ToString();
_isprivate = profile.IsPrivate.ToString();
}
}
}
catch (Exception ex)
{
await logger.LogError(ex, "Error Loading Profile {ProfileId} {Error}", profileid, ex.Message);
await logger.LogError(ex, "Error Loading Profile {ProfileId} {Error}", _profileid, ex.Message);
AddModuleMessage("Error Loading Profile", MessageType.Error);
}
}
@ -135,30 +135,30 @@
try
{
Profile profile;
if (profileid != -1)
if (_profileid != -1)
{
profile = await ProfileService.GetProfileAsync(profileid);
profile = await ProfileService.GetProfileAsync(_profileid);
}
else
{
profile = new Profile();
}
profile.Name = name;
profile.Title = title;
profile.Description = description;
profile.Category = category;
profile.ViewOrder = int.Parse(vieworder);
profile.MaxLength = int.Parse(maxlength);
profile.DefaultValue = defaultvalue;
profile.IsRequired = (isrequired == null ? false : Boolean.Parse(isrequired));
profile.IsPrivate = (isprivate == null ? false : Boolean.Parse(isprivate));
profile.Name = _name;
profile.Title = _title;
profile.Description = _description;
profile.Category = _category;
profile.ViewOrder = int.Parse(_vieworder);
profile.MaxLength = int.Parse(_maxlength);
profile.DefaultValue = _defaultvalue;
profile.IsRequired = (_isrequired == null ? false : Boolean.Parse(_isrequired));
profile.IsPrivate = (_isprivate == null ? false : Boolean.Parse(_isprivate));
profile = await ProfileService.UpdateProfileAsync(profile);
await logger.LogInformation("Profile Saved {Profile}", profile);
NavigationManager.NavigateTo(NavigateUrl());
}
catch (Exception ex)
{
await logger.LogError(ex, "Error Saving Profile {ProfleId} {Error}", profileid, ex.Message);
await logger.LogError(ex, "Error Saving Profile {ProfleId} {Error}", _profileid, ex.Message);
AddModuleMessage("Error Saving Profile", MessageType.Error);
}
}

View File

@ -2,7 +2,7 @@
@inherits ModuleBase
@inject IProfileService ProfileService
@if (Profiles == null)
@if (_profiles == null)
{
<p><em>Loading...</em></p>
}
@ -10,7 +10,7 @@ else
{
<ActionLink Action="Add" Security="SecurityAccessLevel.Admin" Text="Add Profile" />
<Pager Items="@Profiles">
<Pager Items="@_profiles">
<Header>
<th>&nbsp;</th>
<th>&nbsp;</th>
@ -27,25 +27,25 @@ else
@code {
public override SecurityAccessLevel SecurityAccessLevel { get { return SecurityAccessLevel.Admin; } }
List<Profile> Profiles;
List<Profile> _profiles;
protected override async Task OnInitializedAsync()
{
Profiles = await ProfileService.GetProfilesAsync(PageState.Site.SiteId);
_profiles = await ProfileService.GetProfilesAsync(PageState.Site.SiteId);
}
private async Task DeleteProfile(int ProfileId)
private async Task DeleteProfile(int profileId)
{
try
{
await ProfileService.DeleteProfileAsync(ProfileId);
await logger.LogInformation("Profile Deleted {ProfileId}", ProfileId);
await ProfileService.DeleteProfileAsync(profileId);
await logger.LogInformation("Profile Deleted {ProfileId}", profileId);
AddModuleMessage("Profile Deleted", MessageType.Success);
}
catch (Exception ex)
{
await logger.LogError(ex, "Error Deleting Profile {ProfileId} {Error}", ProfileId, ex.Message);
await logger.LogError(ex, "Error Deleting Profile {ProfileId} {Error}", profileId, ex.Message);
AddModuleMessage("Error Deleting Profile", MessageType.Error);
}
}
}
}

View File

@ -23,14 +23,14 @@
<div class="tab-content">
<div id="Pages" class="tab-pane fade show active" role="tabpanel">
@if (pages == null)
@if (_pages == null)
{
<br />
<p>No Deleted Pages</p>
}
else
{
<Pager Items="@pages">
<Pager Items="@_pages">
<Header>
<th>&nbsp;</th>
<th>&nbsp;</th>
@ -49,14 +49,14 @@
}
</div>
<div id="Modules" class="tab-pane fade" role="tabpanel">
@if (modules == null)
@if (_modules == null)
{
<br />
<p>No Deleted Modules</p>
}
else
{
<Pager Items="@modules">
<Pager Items="@_modules">
<Header>
<th>&nbsp;</th>
<th>&nbsp;</th>
@ -83,8 +83,8 @@
@code {
public override SecurityAccessLevel SecurityAccessLevel { get { return SecurityAccessLevel.Admin; } }
List<Page> pages;
List<Module> modules;
List<Page> _pages;
List<Module> _modules;
protected override async Task OnInitializedAsync()
{
@ -101,84 +101,84 @@
private async Task Load()
{
pages = await PageService.GetPagesAsync(PageState.Site.SiteId);
pages = pages.Where(item => item.IsDeleted).ToList();
_pages = await PageService.GetPagesAsync(PageState.Site.SiteId);
_pages = _pages.Where(item => item.IsDeleted).ToList();
modules = await ModuleService.GetModulesAsync(PageState.Site.SiteId);
modules = modules.Where(item => item.IsDeleted).ToList();
_modules = await ModuleService.GetModulesAsync(PageState.Site.SiteId);
_modules = _modules.Where(item => item.IsDeleted).ToList();
}
private async Task RestorePage(Page Page)
private async Task RestorePage(Page page)
{
try
{
Page.IsDeleted = false;
await PageService.UpdatePageAsync(Page);
await logger.LogInformation("Page Restored {Page}", Page);
page.IsDeleted = false;
await PageService.UpdatePageAsync(page);
await logger.LogInformation("Page Restored {Page}", page);
await Load();
StateHasChanged();
NavigationManager.NavigateTo(NavigateUrl());
}
catch (Exception ex)
{
await logger.LogError(ex, "Error Restoring Deleted Page {Page} {Error}", Page, ex.Message);
await logger.LogError(ex, "Error Restoring Deleted Page {Page} {Error}", page, ex.Message);
AddModuleMessage("Error Restoring Deleted Page", MessageType.Error);
}
}
private async Task DeletePage(Page Page)
private async Task DeletePage(Page page)
{
try
{
await PageService.DeletePageAsync(Page.PageId);
await logger.LogInformation("Page Permanently Deleted {Page}", Page);
await PageService.DeletePageAsync(page.PageId);
await logger.LogInformation("Page Permanently Deleted {Page}", page);
await Load();
StateHasChanged();
NavigationManager.NavigateTo(NavigateUrl());
}
catch (Exception ex)
{
await logger.LogError(ex, "Error Permanently Deleting Page {Page} {Error}", Page, ex.Message);
await logger.LogError(ex, "Error Permanently Deleting Page {Page} {Error}", page, ex.Message);
AddModuleMessage(ex.Message, MessageType.Error);
}
}
private async Task RestoreModule(Module Module)
private async Task RestoreModule(Module module)
{
try
{
PageModule pagemodule = await PageModuleService.GetPageModuleAsync(Module.PageModuleId);
PageModule pagemodule = await PageModuleService.GetPageModuleAsync(module.PageModuleId);
pagemodule.IsDeleted = false;
await PageModuleService.UpdatePageModuleAsync(pagemodule);
await logger.LogInformation("Module Restored {Module}", Module);
await logger.LogInformation("Module Restored {Module}", module);
await Load();
StateHasChanged();
}
catch (Exception ex)
{
await logger.LogError(ex, "Error Restoring Deleted Module {Module} {Error}", Module, ex.Message);
await logger.LogError(ex, "Error Restoring Deleted Module {Module} {Error}", module, ex.Message);
AddModuleMessage("Error Restoring Deleted Module", MessageType.Error);
}
}
private async Task DeleteModule(Module Module)
private async Task DeleteModule(Module module)
{
try
{
await PageModuleService.DeletePageModuleAsync(Module.PageModuleId);
await PageModuleService.DeletePageModuleAsync(module.PageModuleId);
// check if there are any remaining module instances in the site
modules = await ModuleService.GetModulesAsync(PageState.Site.SiteId);
if (!modules.Exists(item => item.ModuleId == Module.ModuleId))
_modules = await ModuleService.GetModulesAsync(PageState.Site.SiteId);
if (!_modules.Exists(item => item.ModuleId == module.ModuleId))
{
await ModuleService.DeleteModuleAsync(Module.ModuleId);
await ModuleService.DeleteModuleAsync(module.ModuleId);
}
await logger.LogInformation("Module Permanently Deleted {Module}", Module);
await logger.LogInformation("Module Permanently Deleted {Module}", module);
await Load();
StateHasChanged();
}
catch (Exception ex)
{
await logger.LogError(ex, "Error Permanently Deleting Module {Module} {Error}", Module, ex.Message);
await logger.LogError(ex, "Error Permanently Deleting Module {Module} {Error}", module, ex.Message);
AddModuleMessage("Error Permanently Deleting Module", MessageType.Error);
}
}

View File

@ -3,31 +3,31 @@
@inject NavigationManager NavigationManager
@inject IUserService UserService
@if (Message != "")
@if (_message != "")
{
<ModuleMessage Message="@Message" Type="MessageType.Info" />
<ModuleMessage Message="@_message" Type="MessageType.Info" />
}
<div class="container">
<div class="form-group">
<label for="Username" class="control-label">Username: </label>
<input type="text" class="form-control" placeholder="Username" @bind="@Username" />
<input type="text" class="form-control" placeholder="Username" @bind="@_username" id="Username"/>
</div>
<div class="form-group">
<label for="Password" class="control-label">Password: </label>
<input type="password" class="form-control" placeholder="Password" @bind="@Password" />
<input type="password" class="form-control" placeholder="Password" @bind="@_password" id="Password"/>
</div>
<div class="form-group">
<label for="Password" class="control-label">Confirm Password: </label>
<input type="password" class="form-control" placeholder="Password" @bind="@Confirm" />
<label for="Confirm" class="control-label">Confirm Password: </label>
<input type="password" class="form-control" placeholder="Password" @bind="@_confirm"id="Confirm" />
</div>
<div class="form-group">
<label for="Username" class="control-label">Email: </label>
<input type="text" class="form-control" placeholder="Email" @bind="@Email" />
<label for="Email" class="control-label">Email: </label>
<input type="text" class="form-control" placeholder="Email" @bind="@_email" id="Email"/>
</div>
<div class="form-group">
<label for="DisplayName" class="control-label">Full Name: </label>
<input type="text" class="form-control" placeholder="Full Name" @bind="@DisplayName" />
<input type="text" class="form-control" placeholder="Full Name" @bind="@_displayName" id="DisplayName"/>
</div>
<button type="button" class="btn btn-primary" @onclick="Register">Register</button>
<button type="button" class="btn btn-secondary" @onclick="Cancel">Cancel</button>
@ -36,38 +36,40 @@
@code {
public override SecurityAccessLevel SecurityAccessLevel { get { return SecurityAccessLevel.Anonymous; } }
string Message = "Please Note That Registration Requires A Valid Email Address In Order To Verify Your Identity";
string Username = "";
string Password = "";
string Confirm = "";
string Email = "";
string DisplayName = "";
string _message = "Please Note That Registration Requires A Valid Email Address In Order To Verify Your Identity";
string _username = "";
string _password = "";
string _confirm = "";
string _email = "";
string _displayName = "";
private async Task Register()
{
try
{
Message = "";
if (Username != "" && Password != "" && Confirm != "" && Email != "")
_message = "";
if (_username != "" && _password != "" && _confirm != "" && _email != "")
{
if (Password == Confirm)
if (_password == _confirm)
{
User user = new User();
user.SiteId = PageState.Site.SiteId;
user.Username = Username;
user.DisplayName = (DisplayName == "" ? Username : DisplayName);
user.Email = Email;
user.Password = Password;
User user = new User
{
SiteId = PageState.Site.SiteId,
Username = _username,
DisplayName = (_displayName == "" ? _username : _displayName),
Email = _email,
Password = _password
};
user = await UserService.AddUserAsync(user);
if (user != null)
{
await logger.LogInformation("User Created {Username} {Email}", Username, Email);
await logger.LogInformation("User Created {Username} {Email}", _username, _email);
AddModuleMessage("User Account Created. Please Check Your Email For Verification Instructions.", MessageType.Info);
}
else
{
await logger.LogError("Error Adding User {Username} {Email}", Username, Email);
await logger.LogError("Error Adding User {Username} {Email}", _username, _email);
AddModuleMessage("Error Adding User. Please Ensure Password Meets Complexity Requirements And Username Is Not Already In Use.", MessageType.Error);
}
}
@ -83,7 +85,7 @@
}
catch (Exception ex)
{
await logger.LogError(ex, "Error Adding User {Username} {Email} {Error}", Username, Email, ex.Message);
await logger.LogError(ex, "Error Adding User {Username} {Email} {Error}", _username, _email, ex.Message);
AddModuleMessage("Error Adding User", MessageType.Error);
}
}

View File

@ -17,7 +17,7 @@
<label class="control-label">Description: </label>
</td>
<td>
<textarea class="form-control" @bind="@description" rows="5" />
<textarea class="form-control" @bind="@description" rows="5"></textarea>
</td>
</tr>
<tr>

View File

@ -9,7 +9,7 @@
<label class="control-label">Name: </label>
</td>
<td>
<input class="form-control" @bind="@name" />
<input class="form-control" @bind="@_name" />
</td>
</tr>
<tr>
@ -17,7 +17,7 @@
<label class="control-label">Description: </label>
</td>
<td>
<textarea class="form-control" @bind="@description" rows="5" />
<textarea class="form-control" @bind="@_description" rows="5"></textarea>
</td>
</tr>
<tr>
@ -25,7 +25,7 @@
<label class="control-label">Auto Assigned? </label>
</td>
<td>
<select class="form-control" @bind="@isautoassigned">
<select class="form-control" @bind="@_isautoassigned">
<option value="True">Yes</option>
<option value="False">No</option>
</select>
@ -36,7 +36,7 @@
<label class="control-label">System Role? </label>
</td>
<td>
<select class="form-control" @bind="@issystem">
<select class="form-control" @bind="@_issystem">
<option value="True">Yes</option>
<option value="False">No</option>
</select>
@ -49,40 +49,40 @@
@code {
public override SecurityAccessLevel SecurityAccessLevel { get { return SecurityAccessLevel.Admin; } }
int roleid;
string name = "";
string description = "";
string isautoassigned = "False";
string issystem = "False";
int _roleid;
string _name = "";
string _description = "";
string _isautoassigned = "False";
string _issystem = "False";
protected override async Task OnInitializedAsync()
{
try
{
roleid = Int32.Parse(PageState.QueryString["id"]);
Role role = await RoleService.GetRoleAsync(roleid);
_roleid = Int32.Parse(PageState.QueryString["id"]);
Role role = await RoleService.GetRoleAsync(_roleid);
if (role != null)
{
name = role.Name;
description = role.Description;
isautoassigned = role.IsAutoAssigned.ToString();
issystem = role.IsSystem.ToString();
_name = role.Name;
_description = role.Description;
_isautoassigned = role.IsAutoAssigned.ToString();
_issystem = role.IsSystem.ToString();
}
}
catch (Exception ex)
{
await logger.LogError(ex, "Error Loading Role {RoleId} {Error}", roleid, ex.Message);
await logger.LogError(ex, "Error Loading Role {RoleId} {Error}", _roleid, ex.Message);
AddModuleMessage("Error Loading Role", MessageType.Error);
}
}
private async Task SaveRole()
{
Role role = await RoleService.GetRoleAsync(roleid);
role.Name = name;
role.Description = description;
role.IsAutoAssigned = (isautoassigned == null ? false : Boolean.Parse(isautoassigned));
role.IsSystem = (issystem == null ? false : Boolean.Parse(issystem));
Role role = await RoleService.GetRoleAsync(_roleid);
role.Name = _name;
role.Description = _description;
role.IsAutoAssigned = (_isautoassigned != null && Boolean.Parse(_isautoassigned));
role.IsSystem = (_issystem != null && Boolean.Parse(_issystem));
try
{

View File

@ -2,7 +2,7 @@
@inherits ModuleBase
@inject IRoleService RoleService
@if (Roles == null)
@if (_roles == null)
{
<p><em>Loading...</em></p>
}
@ -10,7 +10,7 @@ else
{
<ActionLink Action="Add" Text="Add Role" />
<Pager Items="@Roles">
<Pager Items="@_roles">
<Header>
<th>&nbsp;</th>
<th>&nbsp;</th>
@ -27,25 +27,25 @@ else
@code {
public override SecurityAccessLevel SecurityAccessLevel { get { return SecurityAccessLevel.Admin; } }
List<Role> Roles;
List<Role> _roles;
protected override async Task OnParametersSetAsync()
{
Roles = await RoleService.GetRolesAsync(PageState.Site.SiteId);
_roles = await RoleService.GetRolesAsync(PageState.Site.SiteId);
}
private async Task DeleteRole(Role Role)
private async Task DeleteRole(Role role)
{
try
{
await RoleService.DeleteRoleAsync(Role.RoleId);
await logger.LogInformation("Role Deleted {Role}", Role);
await RoleService.DeleteRoleAsync(role.RoleId);
await logger.LogInformation("Role Deleted {Role}", role);
StateHasChanged();
}
catch (Exception ex)
{
await logger.LogError(ex, "Error Deleting Role {Role} {Error}", Role, ex.Message);
await logger.LogError(ex, "Error Deleting Role {Role} {Error}", role, ex.Message);
AddModuleMessage("Error Deleting Role", MessageType.Error);
}
}
}
}

View File

@ -31,7 +31,7 @@
<label class="control-label">Aliases: </label>
</td>
<td>
<textarea class="form-control" @bind="@urls" rows="3" />
<textarea class="form-control" @bind="@urls" rows="3"></textarea>
</td>
</tr>
<tr>

View File

@ -7,7 +7,7 @@
@inject IThemeService ThemeService
@inject IUserService UserService
@if (tenants == null)
@if (_tenants == null)
{
<p><em>Loading...</em></p>
}
@ -21,7 +21,7 @@ else
<td>
<select class="form-control" @onchange="(e => TenantChanged(e))">
<option value="-1">&lt;Select Tenant&gt;</option>
@foreach (Tenant tenant in tenants)
@foreach (Tenant tenant in _tenants)
{
<option value="@tenant.TenantId">@tenant.Name</option>
}
@ -33,7 +33,7 @@ else
<label class="control-label">Name: </label>
</td>
<td>
<input class="form-control" @bind="@name" />
<input class="form-control" @bind="@_name" />
</td>
</tr>
<tr>
@ -41,7 +41,7 @@ else
<label class="control-label">Aliases: </label>
</td>
<td>
<textarea class="form-control" @bind="@urls" rows="3" />
<textarea class="form-control" @bind="@_urls" rows="3"></textarea>
</td>
</tr>
<tr>
@ -51,7 +51,7 @@ else
<td>
<select class="form-control" @onchange="(e => ThemeChanged(e))">
<option value="">&lt;Select Theme&gt;</option>
@foreach (KeyValuePair<string, string> item in themes)
@foreach (KeyValuePair<string, string> item in _themes)
{
<option value="@item.Key">@item.Value</option>
}
@ -63,9 +63,9 @@ else
<label class="control-label">Default Layout: </label>
</td>
<td>
<select class="form-control" @bind="@layouttype">
<select class="form-control" @bind="@_layouttype">
<option value="">&lt;Select Layout&gt;</option>
@foreach (KeyValuePair<string, string> panelayout in panelayouts)
@foreach (KeyValuePair<string, string> panelayout in _panelayouts)
{
<option value="@panelayout.Key">@panelayout.Value</option>
}
@ -77,23 +77,23 @@ else
<label class="control-label">Default Container: </label>
</td>
<td>
<select class="form-control" @bind="@containertype">
<select class="form-control" @bind="@_containertype">
<option value="">&lt;Select Container&gt;</option>
@foreach (KeyValuePair<string, string>container in containers)
@foreach (KeyValuePair<string, string>container in _containers)
{
<option value="@container.Key">@container.Value</option>
}
</select>
</td>
</tr>
@if (!isinitialized)
@if (!_isinitialized)
{
<tr>
<td>
<label class="control-label">Host Username:</label>
</td>
<td>
<input class="form-control" @bind="@username" readonly />
<input class="form-control" @bind="@_username" readonly />
</td>
</tr>
<tr>
@ -101,7 +101,7 @@ else
<label class="control-label">Host Password:</label>
</td>
<td>
<input type="password" class="form-control" @bind="@password" />
<input type="password" class="form-control" @bind="@_password" />
</td>
</tr>
}
@ -113,50 +113,50 @@ else
@code {
public override SecurityAccessLevel SecurityAccessLevel { get { return SecurityAccessLevel.Host; } }
Dictionary<string, string> themes = new Dictionary<string, string>();
Dictionary<string, string> panelayouts = new Dictionary<string, string>();
Dictionary<string, string> containers = new Dictionary<string, string>();
Dictionary<string, string> _themes = new Dictionary<string, string>();
Dictionary<string, string> _panelayouts = new Dictionary<string, string>();
Dictionary<string, string> _containers = new Dictionary<string, string>();
List<Theme> Themes;
List<Tenant> tenants;
string tenantid = "-1";
string name = "";
string urls = "";
string themetype = "";
string layouttype = "";
string containertype = "";
bool isinitialized = true;
string username = "";
string password = "";
List<Theme> _themeList;
List<Tenant> _tenants;
string _tenantid = "-1";
string _name = "";
string _urls = "";
string _themetype = "";
string _layouttype = "";
string _containertype = "";
bool _isinitialized = true;
string _username = "";
string _password = "";
protected override async Task OnInitializedAsync()
{
Themes = await ThemeService.GetThemesAsync();
tenants = await TenantService.GetTenantsAsync();
urls = PageState.Alias.Name;
themes = ThemeService.GetThemeTypes(Themes);
containers = ThemeService.GetContainerTypes(Themes);
username = Constants.HostUser;
_themeList = await ThemeService.GetThemesAsync();
_tenants = await TenantService.GetTenantsAsync();
_urls = PageState.Alias.Name;
_themes = ThemeService.GetThemeTypes(_themeList);
_containers = ThemeService.GetContainerTypes(_themeList);
_username = Constants.HostUser;
}
private async void TenantChanged(ChangeEventArgs e)
{
try
{
tenantid = (string)e.Value;
if (tenantid != "-1")
_tenantid = (string)e.Value;
if (_tenantid != "-1")
{
Tenant tenant = tenants.Where(item => item.TenantId == int.Parse(tenantid)).FirstOrDefault();
Tenant tenant = _tenants.Where(item => item.TenantId == int.Parse(_tenantid)).FirstOrDefault();
if (tenant != null)
{
isinitialized = tenant.IsInitialized;
_isinitialized = tenant.IsInitialized;
StateHasChanged();
}
}
}
catch (Exception ex)
{
await logger.LogError(ex, "Error Loading Tenant {TenantId} {Error}", tenantid, ex.Message);
await logger.LogError(ex, "Error Loading Tenant {TenantId} {Error}", _tenantid, ex.Message);
AddModuleMessage("Error Loading Tenant", MessageType.Error);
}
}
@ -165,31 +165,31 @@ else
{
try
{
themetype = (string)e.Value;
if (themetype != "")
_themetype = (string)e.Value;
if (_themetype != "")
{
panelayouts = ThemeService.GetPaneLayoutTypes(Themes, themetype);
_panelayouts = ThemeService.GetPaneLayoutTypes(_themeList, _themetype);
}
else
{
panelayouts = new Dictionary<string, string>();
_panelayouts = new Dictionary<string, string>();
}
StateHasChanged();
}
catch (Exception ex)
{
await logger.LogError(ex, "Error Loading Pane Layouts For Theme {ThemeType} {Error}", themetype, ex.Message);
await logger.LogError(ex, "Error Loading Pane Layouts For Theme {ThemeType} {Error}", _themetype, ex.Message);
AddModuleMessage("Error Loading Pane Layouts For Theme", MessageType.Error);
}
}
private async Task SaveSite()
{
if (tenantid != "-1" && name != "" && urls != "" && !string.IsNullOrEmpty(themetype) && (panelayouts.Count == 0 || !string.IsNullOrEmpty(layouttype)) && !string.IsNullOrEmpty(containertype))
if (_tenantid != "-1" && _name != "" && _urls != "" && !string.IsNullOrEmpty(_themetype) && (_panelayouts.Count == 0 || !string.IsNullOrEmpty(_layouttype)) && !string.IsNullOrEmpty(_containertype))
{
bool unique = true;
List<Alias> aliases = await AliasService.GetAliasesAsync();
foreach (string name in urls.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries))
foreach (string name in _urls.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries))
{
if (aliases.Exists(item => item.Name == name))
{
@ -200,12 +200,12 @@ else
{
bool isvalid = true;
if (!isinitialized)
if (!_isinitialized)
{
User user = new User();
user.SiteId = PageState.Site.SiteId;
user.Username = username;
user.Password = password;
user.Username = _username;
user.Password = _password;
user = await UserService.LoginUserAsync(user, false, false);
isvalid = user.IsAuthenticated;
}
@ -215,24 +215,24 @@ else
ShowProgressIndicator();
aliases = new List<Alias>();
urls = urls.Replace("\n", ",");
foreach (string name in urls.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries))
_urls = _urls.Replace("\n", ",");
foreach (string name in _urls.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries))
{
Alias alias = new Alias();
alias.Name = name;
alias.TenantId = int.Parse(tenantid);
alias.TenantId = int.Parse(_tenantid);
alias.SiteId = -1;
alias = await AliasService.AddAliasAsync(alias);
aliases.Add(alias);
}
Site site = new Site();
site.TenantId = int.Parse(tenantid);
site.Name = name;
site.TenantId = int.Parse(_tenantid);
site.Name = _name;
site.LogoFileId = null;
site.DefaultThemeType = themetype;
site.DefaultLayoutType = (layouttype == null ? "" : layouttype);
site.DefaultContainerType = containertype;
site.DefaultThemeType = _themetype;
site.DefaultLayoutType = (_layouttype == null ? "" : _layouttype);
site.DefaultContainerType = _containertype;
site = await SiteService.AddSiteAsync(site, aliases[0]);
foreach (Alias alias in aliases)
@ -241,19 +241,19 @@ else
await AliasService.UpdateAliasAsync(alias);
}
if (!isinitialized)
if (!_isinitialized)
{
User user = new User();
user.SiteId = site.SiteId;
user.Username = username;
user.Password = password;
user.Username = _username;
user.Password = _password;
user.Email = PageState.User.Email;
user.DisplayName = PageState.User.DisplayName;
user = await UserService.AddUserAsync(user, aliases[0]);
if (user != null)
{
Tenant tenant = tenants.Where(item => item.TenantId == int.Parse(tenantid)).FirstOrDefault();
Tenant tenant = _tenants.FirstOrDefault(item => item.TenantId == int.Parse(_tenantid));
tenant.IsInitialized = true;
await TenantService.UpdateTenantAsync(tenant);
}
@ -265,7 +265,7 @@ else
}
else
{
await logger.LogError("Invalid Password Entered For Host {Username}", username);
await logger.LogError("Invalid Password Entered For Host {Username}", _username);
AddModuleMessage("Invalid Host Password", MessageType.Error);
}
}

View File

@ -11,6 +11,7 @@
@inject IModuleService ModuleService
@inject IModuleDefinitionService ModuleDefinitionService
@inject ILogService LogService
@using System.Diagnostics.CodeAnalysis
@implements IHandleAfterRender
@DynamicComponent
@ -65,6 +66,7 @@
}
}
[SuppressMessage("ReSharper", "StringIndexOfIsCultureSpecific.1")]
private async Task Refresh()
{
Alias alias = null;

View File

@ -1,5 +1,5 @@
@namespace Oqtane.UI
@inject IJSRuntime jsRuntime
@inject IJSRuntime JsRuntime
@DynamicComponent

View File

@ -49,11 +49,11 @@ namespace Oqtane.Controllers
name = WebUtility.UrlDecode(name);
List<Alias> aliases = _aliases.GetAliases().ToList();
Alias alias = null;
alias = aliases.Where(item => item.Name == name).FirstOrDefault();
if (alias == null && name.Contains("/"))
alias = aliases.FirstOrDefault(item => item.Name == name);
if (name != null && (alias == null && name.Contains("/")))
{
// lookup alias without folder name
alias = aliases.Find(item => item.Name == name.Substring(0, name.IndexOf("/")));
alias = aliases.Find(item => item.Name == name.Substring(0, name.IndexOf("/", StringComparison.Ordinal)));
}
if (alias == null && aliases.Count > 0)
{
@ -71,27 +71,27 @@ namespace Oqtane.Controllers
// POST api/<controller>
[HttpPost]
[Authorize(Roles = Constants.AdminRole)]
public Alias Post([FromBody] Alias Alias)
public Alias Post([FromBody] Alias alias)
{
if (ModelState.IsValid)
{
Alias = _aliases.AddAlias(Alias);
_logger.Log(LogLevel.Information, this, LogFunction.Create, "Alias Added {Alias}", Alias);
alias = _aliases.AddAlias(alias);
_logger.Log(LogLevel.Information, this, LogFunction.Create, "Alias Added {Alias}", alias);
}
return Alias;
return alias;
}
// PUT api/<controller>/5
[HttpPut("{id}")]
[Authorize(Roles = Constants.AdminRole)]
public Alias Put(int id, [FromBody] Alias Alias)
public Alias Put(int id, [FromBody] Alias alias)
{
if (ModelState.IsValid)
{
Alias = _aliases.UpdateAlias(Alias);
_logger.Log(LogLevel.Information, this, LogFunction.Update, "Alias Updated {Alias}", Alias);
alias = _aliases.UpdateAlias(alias);
_logger.Log(LogLevel.Information, this, LogFunction.Update, "Alias Updated {Alias}", alias);
}
return Alias;
return alias;
}
// DELETE api/<controller>/5

View File

@ -61,14 +61,15 @@ namespace Oqtane.Controllers
{
foreach (string file in Directory.GetFiles(folder))
{
files.Add(new Models.File { Name = Path.GetFileName(file), Extension = Path.GetExtension(file).Replace(".","") });
files.Add(new Models.File {Name = Path.GetFileName(file), Extension = Path.GetExtension(file)?.Replace(".", "")});
}
}
}
}
return files;
}
// GET: api/<controller>/siteId/folderPath
[HttpGet("{siteId}/{path}")]
public IEnumerable<Models.File> Get(int siteId, string path)
@ -95,6 +96,7 @@ namespace Oqtane.Controllers
HttpContext.Response.StatusCode = 401;
return null;
}
return files;
}
@ -103,7 +105,7 @@ namespace Oqtane.Controllers
public Models.File Get(int id)
{
Models.File file = _files.GetFile(id);
if (_userPermissions.IsAuthorized(User,PermissionNames.View, file.Folder.Permissions))
if (_userPermissions.IsAuthorized(User, PermissionNames.View, file.Folder.Permissions))
{
return file;
}
@ -118,20 +120,21 @@ namespace Oqtane.Controllers
// PUT api/<controller>/5
[HttpPut("{id}")]
[Authorize(Roles = Constants.RegisteredRole)]
public Models.File Put(int id, [FromBody] Models.File File)
public Models.File Put(int id, [FromBody] Models.File file)
{
if (ModelState.IsValid && _userPermissions.IsAuthorized(User, EntityNames.Folder, File.Folder.FolderId, PermissionNames.Edit))
if (ModelState.IsValid && _userPermissions.IsAuthorized(User, EntityNames.Folder, file.Folder.FolderId, PermissionNames.Edit))
{
File = _files.UpdateFile(File);
_logger.Log(LogLevel.Information, this, LogFunction.Update, "File Updated {File}", File);
file = _files.UpdateFile(file);
_logger.Log(LogLevel.Information, this, LogFunction.Update, "File Updated {File}", file);
}
else
{
_logger.Log(LogLevel.Error, this, LogFunction.Update, "User Not Authorized To Update File {File}", File);
_logger.Log(LogLevel.Error, this, LogFunction.Update, "User Not Authorized To Update File {File}", file);
HttpContext.Response.StatusCode = 401;
File = null;
file = null;
}
return File;
return file;
}
// DELETE api/<controller>/5
@ -149,6 +152,7 @@ namespace Oqtane.Controllers
{
System.IO.File.Delete(filepath);
}
_logger.Log(LogLevel.Information, this, LogFunction.Delete, "File Deleted {File}", file);
}
else
@ -164,11 +168,11 @@ namespace Oqtane.Controllers
{
Models.File file = null;
Folder folder = _folders.GetFolder(int.Parse(folderid));
if (folder != null && _userPermissions.IsAuthorized(User,PermissionNames.Edit, folder.Permissions))
if (folder != null && _userPermissions.IsAuthorized(User, PermissionNames.Edit, folder.Permissions))
{
string folderpath = GetFolderPath(folder);
CreateDirectory(folderpath);
string filename = url.Substring(url.LastIndexOf("/") + 1);
string filename = url.Substring(url.LastIndexOf("/", StringComparison.Ordinal) + 1);
// check for allowable file extensions
if (Constants.UploadableFiles.Contains(Path.GetExtension(filename).Replace(".", "")))
{
@ -180,6 +184,7 @@ namespace Oqtane.Controllers
{
System.IO.File.Delete(folderpath + filename);
}
client.DownloadFile(url, folderpath + filename);
_files.AddFile(CreateFile(filename, folder.FolderId, folderpath + filename));
}
@ -199,9 +204,10 @@ namespace Oqtane.Controllers
HttpContext.Response.StatusCode = 401;
file = null;
}
return file;
}
// POST api/<controller>/upload
[HttpPost("upload")]
public async Task UploadFile(string folder, IFormFile file)
@ -213,9 +219,9 @@ namespace Oqtane.Controllers
if (int.TryParse(folder, out folderid))
{
Folder Folder = _folders.GetFolder(folderid);
if (Folder != null && _userPermissions.IsAuthorized(User,PermissionNames.Edit, Folder.Permissions))
if (Folder != null && _userPermissions.IsAuthorized(User, PermissionNames.Edit, Folder.Permissions))
{
folderpath = GetFolderPath(Folder);
folderpath = GetFolderPath(Folder);
}
}
else
@ -225,6 +231,7 @@ namespace Oqtane.Controllers
folderpath = GetFolderPath(folder);
}
}
if (folderpath != "")
{
CreateDirectory(folderpath);
@ -232,6 +239,7 @@ namespace Oqtane.Controllers
{
await file.CopyToAsync(stream);
}
string upload = await MergeFile(folderpath, file.FileName);
if (upload != "" && folderid != -1)
{
@ -252,19 +260,19 @@ namespace Oqtane.Controllers
// parse the filename which is in the format of filename.ext.part_x_y
string token = ".part_";
string parts = Path.GetExtension(filename).Replace(token, ""); // returns "x_y"
int totalparts = int.Parse(parts.Substring(parts.IndexOf("_") + 1));
filename = filename.Substring(0, filename.IndexOf(token)); // base filename
string[] fileparts = Directory.GetFiles(folder, filename + token + "*"); // list of all file parts
string parts = Path.GetExtension(filename)?.Replace(token, ""); // returns "x_y"
int totalparts = int.Parse(parts?.Substring(parts.IndexOf("_") + 1));
filename = filename?.Substring(0, filename.IndexOf(token)); // base filename
string[] fileParts = Directory.GetFiles(folder, filename + token + "*"); // list of all file parts
// if all of the file parts exist ( note that file parts can arrive out of order )
if (fileparts.Length == totalparts && CanAccessFiles(fileparts))
if (fileParts.Length == totalparts && CanAccessFiles(fileParts))
{
// merge file parts
bool success = true;
using (var stream = new FileStream(Path.Combine(folder, filename + ".tmp"), FileMode.Create))
{
foreach (string filepart in fileparts)
foreach (string filepart in fileParts)
{
try
{
@ -283,13 +291,13 @@ namespace Oqtane.Controllers
// delete file parts and rename file
if (success)
{
foreach (string filepart in fileparts)
foreach (string filepart in fileParts)
{
System.IO.File.Delete(filepart);
}
// check for allowable file extensions
if (!Constants.UploadableFiles.Contains(Path.GetExtension(filename).Replace(".", "")))
if (!Constants.UploadableFiles.Contains(Path.GetExtension(filename)?.Replace(".", "")))
{
System.IO.File.Delete(Path.Combine(folder, filename + ".tmp"));
}
@ -300,17 +308,19 @@ namespace Oqtane.Controllers
{
System.IO.File.Delete(Path.Combine(folder, filename));
}
// rename file now that the entire process is completed
System.IO.File.Move(Path.Combine(folder, filename + ".tmp"), Path.Combine(folder, filename));
_logger.Log(LogLevel.Information, this, LogFunction.Create, "File Uploaded {File}", Path.Combine(folder, filename));
}
merged = filename;
}
}
// clean up file parts which are more than 2 hours old ( which can happen if a prior file upload failed )
fileparts = Directory.GetFiles(folder, "*" + token + "*");
foreach (string filepart in fileparts)
fileParts = Directory.GetFiles(folder, "*" + token + "*");
foreach (string filepart in fileParts)
{
DateTime createddate = System.IO.File.GetCreationTime(filepart).ToUniversalTime();
if (createddate < DateTime.UtcNow.AddHours(-2))
@ -339,7 +349,7 @@ namespace Oqtane.Controllers
locked = false;
}
catch // file is locked by another process
{
{
Thread.Sleep(1000); // wait 1 second
}
finally
@ -349,13 +359,16 @@ namespace Oqtane.Controllers
stream.Close();
}
}
attempts += 1;
}
if (locked && canaccess)
{
canaccess = false;
}
}
return canaccess;
}
@ -364,7 +377,7 @@ namespace Oqtane.Controllers
public IActionResult Download(int id)
{
Models.File file = _files.GetFile(id);
if (file != null && _userPermissions.IsAuthorized(User,PermissionNames.View, file.Folder.Permissions))
if (file != null && _userPermissions.IsAuthorized(User, PermissionNames.View, file.Folder.Permissions))
{
string filepath = GetFolderPath(file.Folder) + file.Name;
if (System.IO.File.Exists(filepath))
@ -402,7 +415,7 @@ namespace Oqtane.Controllers
if (!Directory.Exists(folderpath))
{
string path = "";
string[] folders = folderpath.Split(new char[] { '\\' }, StringSplitOptions.RemoveEmptyEntries);
string[] folders = folderpath.Split(new char[] {'\\'}, StringSplitOptions.RemoveEmptyEntries);
foreach (string folder in folders)
{
path += folder + "\\";
@ -422,7 +435,7 @@ namespace Oqtane.Controllers
FileInfo fileinfo = new FileInfo(filepath);
file.Extension = fileinfo.Extension.ToLower().Replace(".", "");
file.Size = (int)fileinfo.Length;
file.Size = (int) fileinfo.Length;
file.ImageHeight = 0;
file.ImageWidth = 0;
@ -434,6 +447,7 @@ namespace Oqtane.Controllers
file.ImageHeight = image.Height;
file.ImageWidth = image.Width;
}
stream.Close();
}