User management improvements

This commit is contained in:
Shaun Walker
2019-10-02 14:43:40 -04:00
parent 0de2250ada
commit 12c73decd0
18 changed files with 533 additions and 82 deletions

View File

@ -135,8 +135,6 @@
DateTime? deletedon;
string isdeleted;
PermissionGrid permissiongrid;
protected override void OnInitialized()
{
try

View File

@ -10,10 +10,18 @@
<table class="table table-borderless">
<tr>
<td>
<label for="Name" class="control-label">Name: </label>
<label for="Name" class="control-label">Username: </label>
</td>
<td>
<input class="form-control" @bind="@displayname" />
<input class="form-control" @bind="@username" readonly />
</td>
</tr>
<tr>
<td>
<label for="Name" class="control-label">Password: </label>
</td>
<td>
<input type="password" class="form-control" @bind="@password" />
</td>
</tr>
<tr>
@ -26,10 +34,10 @@
</tr>
<tr>
<td>
<label for="Name" class="control-label">Password: </label>
<label for="Name" class="control-label">Full Name: </label>
</td>
<td>
<input type="password" class="form-control" @bind="@password" />
<input class="form-control" @bind="@displayname" />
</td>
</tr>
@ -64,9 +72,10 @@
@code {
public override SecurityAccessLevel SecurityAccessLevel { get { return SecurityAccessLevel.View; } }
string displayname = "";
string email = "";
string username = "";
string password = "";
string email = "";
string displayname = "";
List<Profile> profiles;
Dictionary<string, string> settings;
string category = "";
@ -77,8 +86,9 @@
{
if (PageState.User != null)
{
displayname = PageState.User.DisplayName;
username = PageState.User.Username;
email = PageState.User.Email;
displayname = PageState.User.DisplayName;
profiles = await ProfileService.GetProfilesAsync(ModuleState.SiteId);
settings = await SettingService.GetUserSettingsAsync(PageState.User.UserId);
}
@ -103,13 +113,14 @@
try
{
User user = PageState.User;
user.DisplayName = displayname;
user.Email = email;
user.Username = username;
user.Password = password;
user.Email = email;
user.DisplayName = displayname;
await UserService.UpdateUserAsync(user);
await SettingService.UpdateUserSettingsAsync(settings, PageState.User.UserId);
NavigationManager.NavigateTo("");
NavigationManager.NavigateTo(NavigateUrl(""));
}
catch (Exception ex)
{

View File

@ -5,12 +5,16 @@
<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="@Email" />
<label for="Username" class="control-label">Username: </label>
<input type="text" class="form-control" placeholder="Username" @bind="@Username" />
</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" />
<input type="password" class="form-control" placeholder="Password" @bind="@Password" />
</div>
<div class="form-group">
<label for="Username" class="control-label">Email: </label>
<input type="text" class="form-control" placeholder="Username" @bind="@Email" />
</div>
<button type="button" class="btn btn-primary" @onclick="RegisterUser">Register</button>
<button type="button" class="btn btn-secondary" @onclick="Cancel">Cancel</button>
@ -19,23 +23,38 @@
@code {
public override SecurityAccessLevel SecurityAccessLevel { get { return SecurityAccessLevel.Anonymous; } }
public string Email { get; set; } = "";
public string Password { get; set; } = "";
string Username = "";
string Password = "";
string Email = "";
private async Task RegisterUser()
{
User user = new User();
user.SiteId = PageState.Site.SiteId;
user.Username = Email;
user.DisplayName = Email;
user.Email = Email;
user.Password = Password;
await UserService.AddUserAsync(user);
NavigationManager.NavigateTo("");
try
{
if (Username != "" && Password != "" && Email != "")
{
User user = new User();
user.SiteId = PageState.Site.SiteId;
user.Username = Username;
user.DisplayName = Username;
user.Email = Email;
user.Password = Password;
await UserService.AddUserAsync(user);
NavigationManager.NavigateTo(NavigateUrl(""));
}
else
{
ModuleInstance.AddModuleMessage("You Must Provide A Username, Password, and Email Address", MessageType.Warning);
}
}
catch (Exception ex)
{
ModuleInstance.AddModuleMessage(ex.Message, MessageType.Error);
}
}
private void Cancel()
{
NavigationManager.NavigateTo(NavigateUrl("")); // navigate to home
NavigationManager.NavigateTo(NavigateUrl(""));
}
}

View File

@ -121,6 +121,6 @@ else
alias.SiteId = site.SiteId;
await AliasService.AddAliasAsync(alias);
NavigationManager.NavigateTo(url, true);
NavigationManager.NavigateTo("http://" + url, true);
}
}

View File

@ -0,0 +1,89 @@
@namespace Oqtane.Modules.Admin.Sites
@inherits ModuleBase
@inject NavigationManager NavigationManager
@inject ISiteService SiteService
@inject IThemeService ThemeService
@if (themes == null)
{
<p><em>Loading...</em></p>
}
else
{
<table class="table table-borderless">
<tr>
<td>
<label for="Name" class="control-label">Name: </label>
</td>
<td>
<input class="form-control" @bind="@name" readonly />
</td>
</tr>
<tr>
<td>
<label for="Name" class="control-label">Logo: </label>
</td>
<td>
<input class="form-control" @bind="@logo" readonly />
</td>
</tr>
<tr>
<td>
<label for="Name" class="control-label">Default Theme: </label>
</td>
<td>
<select class="form-control" @bind="@themetype" readonly>
<option value="">&lt;Select Theme&gt;</option>
@foreach (KeyValuePair<string, string> item in themes)
{
<option value="@item.Key">@item.Value</option>
}
</select>
</td>
</tr>
<tr>
<td>
<label for="Name" class="control-label">Default Layout: </label>
</td>
<td>
<select class="form-control" @bind="@layouttype" readonly>
<option value="">&lt;Select Layout&gt;</option>
@foreach (KeyValuePair<string, string> panelayout in panelayouts)
{
<option value="@panelayout.Key">@panelayout.Value</option>
}
</select>
</td>
</tr>
</table>
<button type="button" class="btn btn-success" @onclick="DeleteSite">Delete</button>
<NavLink class="btn btn-secondary" href="@NavigateUrl()">Cancel</NavLink>
}
@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>();
string name = "";
string logo = "";
string themetype;
string layouttype;
protected override void OnInitialized()
{
themes = ThemeService.GetThemeTypes(PageState.Themes);
panelayouts = ThemeService.GetPaneLayoutTypes(PageState.Themes);
name = PageState.Site.Name;
logo = PageState.Site.Logo;
themetype = PageState.Site.DefaultThemeType;
layouttype = PageState.Site.DefaultLayoutType;
}
private async Task DeleteSite()
{
await SiteService.DeleteSiteAsync(PageState.Site.SiteId);
NavigationManager.NavigateTo(NavigateUrl());
}
}

View File

@ -0,0 +1,95 @@
@namespace Oqtane.Modules.Admin.Sites
@inherits ModuleBase
@inject NavigationManager NavigationManager
@inject ISiteService SiteService
@inject IThemeService ThemeService
@if (themes == null)
{
<p><em>Loading...</em></p>
}
else
{
<table class="table table-borderless">
<tr>
<td>
<label for="Name" class="control-label">Name: </label>
</td>
<td>
<input class="form-control" @bind="@name" />
</td>
</tr>
<tr>
<td>
<label for="Name" class="control-label">Logo: </label>
</td>
<td>
<input class="form-control" @bind="@logo" />
</td>
</tr>
<tr>
<td>
<label for="Name" class="control-label">Default Theme: </label>
</td>
<td>
<select class="form-control" @bind="@themetype">
<option value="">&lt;Select Theme&gt;</option>
@foreach (KeyValuePair<string, string> item in themes)
{
<option value="@item.Key">@item.Value</option>
}
</select>
</td>
</tr>
<tr>
<td>
<label for="Name" class="control-label">Default Layout: </label>
</td>
<td>
<select class="form-control" @bind="@layouttype">
<option value="">&lt;Select Layout&gt;</option>
@foreach (KeyValuePair<string, string> panelayout in panelayouts)
{
<option value="@panelayout.Key">@panelayout.Value</option>
}
</select>
</td>
</tr>
</table>
<button type="button" class="btn btn-success" @onclick="SaveSite">Save</button>
<NavLink class="btn btn-secondary" href="@NavigateUrl()">Cancel</NavLink>
}
@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>();
string name = "";
string logo = "";
string themetype;
string layouttype;
protected override void OnInitialized()
{
themes = ThemeService.GetThemeTypes(PageState.Themes);
panelayouts = ThemeService.GetPaneLayoutTypes(PageState.Themes);
name = PageState.Site.Name;
logo = PageState.Site.Logo;
themetype = PageState.Site.DefaultThemeType;
layouttype = PageState.Site.DefaultLayoutType;
}
private async Task SaveSite()
{
Site site = PageState.Site;
site.Name = name;
site.Logo = (logo == null ? "" : logo);
site.DefaultThemeType = themetype;
site.DefaultLayoutType = (layouttype == null ? "" : layouttype);
site = await SiteService.UpdateSiteAsync(site);
NavigationManager.NavigateTo(NavigateUrl());
}
}

View File

@ -10,10 +10,18 @@
<table class="table table-borderless">
<tr>
<td>
<label for="Name" class="control-label">Name: </label>
<label for="Name" class="control-label">Username: </label>
</td>
<td>
<input class="form-control" @bind="@displayname" />
<input class="form-control" @bind="@username" />
</td>
</tr>
<tr>
<td>
<label for="Name" class="control-label">Password: </label>
</td>
<td>
<input type="password" class="form-control" @bind="@password" />
</td>
</tr>
<tr>
@ -26,10 +34,10 @@
</tr>
<tr>
<td>
<label for="Name" class="control-label">Password: </label>
<label for="Name" class="control-label">Full Name: </label>
</td>
<td>
<input type="password" class="form-control" @bind="@password" />
<input class="form-control" @bind="@displayname" />
</td>
</tr>
@ -62,9 +70,10 @@
@code {
public override SecurityAccessLevel SecurityAccessLevel { get { return SecurityAccessLevel.Admin; } }
string displayname = "";
string email = "";
string username = "";
string password = "";
string email = "";
string displayname = "";
List<Profile> profiles;
Dictionary<string, string> settings;
string category = "";
@ -87,13 +96,21 @@
try
{
User user = new User();
user.DisplayName = displayname;
user.Email = email;
user.SiteId = PageState.Site.SiteId;
user.Username = username;
user.Password = password;
user.Email = email;
user.DisplayName = displayname;
user = await UserService.AddUserAsync(user);
await SettingService.UpdateUserSettingsAsync(settings, user.UserId);
NavigationManager.NavigateTo(NavigateUrl());
if (user != null)
{
await SettingService.UpdateUserSettingsAsync(settings, user.UserId);
NavigationManager.NavigateTo(NavigateUrl());
}
else
{
ModuleInstance.AddModuleMessage("Error Adding User. Please Ensure Password Meets Complexity Requirements And Username Is Not Already In Use.", MessageType.Error);
}
}
catch (Exception ex)
{

View File

@ -10,10 +10,10 @@
<table class="table table-borderless">
<tr>
<td>
<label for="Name" class="control-label">Name: </label>
<label for="Name" class="control-label">Username: </label>
</td>
<td>
<input class="form-control" @bind="@displayname" readonly />
<input class="form-control" @bind="@username" readonly />
</td>
</tr>
<tr>
@ -24,6 +24,14 @@
<input class="form-control" @bind="@email" readonly />
</td>
</tr>
<tr>
<td>
<label for="Name" class="control-label">Full Name: </label>
</td>
<td>
<input class="form-control" @bind="@displayname" readonly />
</td>
</tr>
@foreach (Profile profile in profiles)
{
@ -42,7 +50,7 @@
<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)" readonly />
<input class="form-control" maxlength="@p.MaxLength" value="@GetProfileValue(p.Name, p.DefaultValue)" readonly />
</td>
</tr>
}
@ -55,8 +63,9 @@
public override SecurityAccessLevel SecurityAccessLevel { get { return SecurityAccessLevel.Admin; } }
int userid;
string displayname = "";
string username = "";
string email = "";
string displayname = "";
List<Profile> profiles;
Dictionary<string, string> settings;
string category = "";
@ -71,8 +80,9 @@
User user = await UserService.GetUserAsync(userid, PageState.Site.SiteId);
if (user != null)
{
displayname = user.DisplayName;
username = user.Username;
email = user.Email;
displayname = user.DisplayName;
settings = await SettingService.GetUserSettingsAsync(user.UserId);
}
}

View File

@ -10,10 +10,18 @@
<table class="table table-borderless">
<tr>
<td>
<label for="Name" class="control-label">Name: </label>
<label for="Name" class="control-label">Username: </label>
</td>
<td>
<input class="form-control" @bind="@displayname" />
<input class="form-control" @bind="@username" readonly />
</td>
</tr>
<tr>
<td>
<label for="Name" class="control-label">Password: </label>
</td>
<td>
<input type="password" class="form-control" @bind="@password" />
</td>
</tr>
<tr>
@ -26,10 +34,10 @@
</tr>
<tr>
<td>
<label for="Name" class="control-label">Password: </label>
<label for="Name" class="control-label">Full Name: </label>
</td>
<td>
<input type="password" class="form-control" @bind="@password" />
<input class="form-control" @bind="@displayname" />
</td>
</tr>
@ -63,9 +71,10 @@
public override SecurityAccessLevel SecurityAccessLevel { get { return SecurityAccessLevel.Admin; } }
int userid;
string displayname = "";
string email = "";
string username = "";
string password = "";
string email = "";
string displayname = "";
List<Profile> profiles;
Dictionary<string, string> settings;
string category = "";
@ -80,8 +89,9 @@
User user = await UserService.GetUserAsync(userid, PageState.Site.SiteId);
if (user != null)
{
displayname = user.DisplayName;
username = user.Username;
email = user.Email;
displayname = user.DisplayName;
settings = await SettingService.GetUserSettingsAsync(user.UserId);
}
}
@ -100,10 +110,12 @@
{
try
{
User user = new User();
user.DisplayName = displayname;
user.Email = email;
User user = await UserService.GetUserAsync(userid, PageState.Site.SiteId);
user.SiteId = PageState.Site.SiteId;
user.Username = username;
user.Password = password;
user.Email = email;
user.DisplayName = displayname;
user = await UserService.UpdateUserAsync(user);
await SettingService.UpdateUserSettingsAsync(settings, user.UserId);

View File

@ -15,11 +15,13 @@ else
<th>Name</th>
<th>&nbsp;</th>
<th>&nbsp;</th>
<th>&nbsp;</th>
</Header>
<Row>
<td>@context.User.DisplayName</td>
<td><ActionLink Action="Edit" Parameters="@($"id=" + context.UserId.ToString())" /></td>
<td><ActionLink Action="Delete" Parameters="@($"id=" + context.UserId.ToString())" Class="btn btn-danger" /></td>
<td><ActionLink Action="Roles" Parameters="@($"id=" + context.UserId.ToString())" /></td>
</Row>
</Pager>
}

View File

@ -0,0 +1,168 @@
@namespace Oqtane.Modules.Admin.Users
@inherits ModuleBase
@inject IRoleService RoleService
@inject IUserRoleService UserRoleService
@if (userroles == null)
{
<p><em>Loading...</em></p>
}
else
{
<table class="table table-borderless">
<tr>
<td>
<label for="Name" class="control-label">Role: </label>
</td>
<td>
<select class="form-control" @bind="@roleid">
<option value="-1">&lt;Select Role&gt;</option>
@foreach (Role role in roles)
{
<option value="@(role.RoleId)">@role.Name</option>
}
</select>
</td>
</tr>
<tr>
<td>
<label for="Name" class="control-label">Effective Date: </label>
</td>
<td>
<input class="form-control" @bind="@effectivedate" />
</td>
</tr>
<tr>
<td>
<label for="Name" class="control-label">Expiry Date: </label>
</td>
<td>
<input class="form-control" @bind="@expirydate" />
</td>
</tr>
</table>
<button type="button" class="btn btn-success" @onclick="SaveUserRole">Save</button>
<NavLink class="btn btn-secondary" href="@NavigateUrl()">Cancel</NavLink>
<hr />
<p align="center">
<Pager Items="@userroles">
<Header>
<th>Role</th>
<th>&nbsp;</th>
</Header>
<Row>
<td>@context.Role.Name</td>
<td>
@if (!context.Role.IsSystem)
{
<button type="button" class="btn btn-danger" @onclick=@(async () => await DeleteUserRole(context.UserRoleId))>Delete</button>
}
</td>
</Row>
</Pager>
</p>
}
@code {
public override SecurityAccessLevel SecurityAccessLevel { get { return SecurityAccessLevel.Admin; } }
int userid;
List<Role> roles;
int roleid = -1;
string effectivedate = "";
string expirydate = "";
List<UserRole> userroles;
protected override async Task OnInitializedAsync()
{
try
{
userid = Int32.Parse(PageState.QueryString["id"]);
roles = await RoleService.GetRolesAsync(PageState.Site.SiteId);
await GetUserRoles();
}
catch (Exception ex)
{
ModuleInstance.AddModuleMessage(ex.Message, MessageType.Error);
}
}
private async Task GetUserRoles()
{
userroles = await UserRoleService.GetUserRolesAsync(PageState.Site.SiteId);
userroles = userroles.Where(item => item.UserId == userid).ToList();
}
private async Task SaveUserRole()
{
try
{
if (roleid != -1)
{
UserRole userrole = userroles.Where(item => item.UserId == userid && item.RoleId == roleid).FirstOrDefault();
if (userrole != null)
{
if (string.IsNullOrEmpty(effectivedate))
{
userrole.EffectiveDate = null;
}
else
{
userrole.EffectiveDate = DateTime.Parse(effectivedate);
}
if (string.IsNullOrEmpty(expirydate))
{
userrole.ExpiryDate = null;
}
else
{
userrole.ExpiryDate = DateTime.Parse(expirydate);
}
await UserRoleService.UpdateUserRoleAsync(userrole);
}
else
{
userrole = new UserRole();
userrole.UserId = userid;
userrole.RoleId = roleid;
if (string.IsNullOrEmpty(effectivedate))
{
userrole.EffectiveDate = null;
}
else
{
userrole.EffectiveDate = DateTime.Parse(effectivedate);
}
if (string.IsNullOrEmpty(expirydate))
{
userrole.ExpiryDate = null;
}
else
{
userrole.ExpiryDate = DateTime.Parse(expirydate);
}
await UserRoleService.AddUserRoleAsync(userrole);
}
await GetUserRoles();
ModuleInstance.AddModuleMessage("User Assigned To Role", MessageType.Success);
}
else
{
ModuleInstance.AddModuleMessage("You Must Select A Role", MessageType.Warning);
}
}
catch (Exception ex)
{
ModuleInstance.AddModuleMessage(ex.Message, MessageType.Error);
}
}
private async Task DeleteUserRole(int UserRoleId)
{
await UserRoleService.DeleteUserRoleAsync(UserRoleId);
await GetUserRoles();
ModuleInstance.AddModuleMessage("User Removed From Role", MessageType.Success);
}
}