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

@ -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);
}
}