notification service and user management improvements

This commit is contained in:
Shaun Walker
2020-02-03 16:43:37 -05:00
parent d8d5e768b2
commit 0aed11e71c
50 changed files with 2077 additions and 284 deletions

View File

@ -0,0 +1,85 @@
@namespace Oqtane.Modules.Admin.Files
@inherits ModuleBase
@inject IFolderService FolderService
@inject NavigationManager NavigationManager
<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">Permissions: </label>
</td>
<td>
<PermissionGrid EntityName="Folder" PermissionNames="View,Edit" Permissions="@permissions" @ref="permissiongrid" />
</td>
</tr>
</table>
<button type="button" class="btn btn-success" @onclick="SaveFolder">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 SecurityAccessLevel SecurityAccessLevel { get { return SecurityAccessLevel.Admin; } }
int FolderId;
string name;
string permissions;
string createdby;
DateTime createdon;
string modifiedby;
DateTime modifiedon;
PermissionGrid permissiongrid;
protected override async Task OnInitializedAsync()
{
try
{
FolderId = Int32.Parse(PageState.QueryString["id"]);
Folder folder = await FolderService.GetFolderAsync(FolderId);
if (folder != null)
{
name = folder.Name;
permissions = folder.Permissions;
createdby = folder.CreatedBy;
createdon = folder.CreatedOn;
modifiedby = folder.ModifiedBy;
modifiedon = folder.ModifiedOn;
}
}
catch (Exception ex)
{
await logger.LogError(ex, "Error Loading Folder {FolderId} {Error}", FolderId, ex.Message);
AddModuleMessage("Error Loading Module", MessageType.Error);
}
}
private async Task SaveFolder()
{
try
{
Folder folder = await FolderService.GetFolderAsync(FolderId);
if (folder != null)
{
folder.Permissions = permissiongrid.GetPermissions();
await FolderService.UpdateFolderAsync(folder);
await logger.LogInformation("Folder Saved {Folder}", folder);
NavigationManager.NavigateTo(NavigateUrl(Reload.Site));
}
}
catch (Exception ex)
{
await logger.LogError(ex, "Error Saving Folder {FolderId} {Error}", FolderId, ex.Message);
AddModuleMessage("Error Saving Module", MessageType.Error);
}
}
}

View File

@ -8,22 +8,23 @@
}
else
{
<Pager Items="@JobLogs">
<Header>
<th>Name</th>
<th>Status</th>
<th>Started</th>
<th>Finished</th>
<th>Notes</th>
</Header>
<Row>
<td>@context.Job.Name</td>
<td>@DisplayStatus(context.Job.IsExecuting, context.Succeeded)</td>
<td>@context.StartDate</td>
<td>@context.FinishDate</td>
<td><ActionDialog Header="Job Notes" Message="@context.Notes" Text="View" Security="SecurityAccessLevel.Host" /></td>
</Row>
</Pager>
<Pager Items="@JobLogs">
<Header>
<th>Name</th>
<th>Status</th>
<th>Started</th>
<th>Finished</th>
</Header>
<Row>
<td>@context.Job.Name</td>
<td>@DisplayStatus(context.Job.IsExecuting, context.Succeeded)</td>
<td>@context.StartDate</td>
<td>@context.FinishDate</td>
</Row>
<Detail>
<td colspan="4">@context.Notes</td>
</Detail>
</Pager>
}
@code {

View File

@ -5,6 +5,10 @@
@inject IUserService UserService
@inject IServiceProvider ServiceProvider
@if (Message != "")
{
<ModuleMessage Message="@Message" Type="@Type" />
}
<AuthorizeView>
<Authorizing>
<text>...</text>
@ -30,6 +34,8 @@
</div>
<button type="button" class="btn btn-primary" @onclick="Login">Login</button>
<button type="button" class="btn btn-secondary" @onclick="Cancel">Cancel</button>
<br /><br />
<button type="button" class="btn btn-secondary" @onclick="Forgot">Forgot Password</button>
</div>
</NotAuthorized>
</AuthorizeView>
@ -37,14 +43,35 @@
@code {
public override SecurityAccessLevel SecurityAccessLevel { get { return SecurityAccessLevel.Anonymous; } }
public string Username { get; set; } = "";
public string Password { get; set; } = "";
public bool Remember { get; set; } = false;
string ReturnUrl = "";
public string Message = "";
public MessageType Type = MessageType.Info;
public string Username = "";
public string Password = "";
public bool Remember = false;
protected override void OnInitialized()
{
if (PageState.QueryString.ContainsKey("returnurl"))
{
ReturnUrl = PageState.QueryString["returnurl"];
}
if (PageState.QueryString.ContainsKey("verified"))
{
if (PageState.QueryString["verified"] == "1")
{
Message = "User Account Verified Successfully. You Can Now Login With Your Username And Password Below.";
}
else
{
Message = "User Account Could Not Be Verified. Please Contact Your Administrator For Further Instructions.";
Type = MessageType.Warning;
}
}
}
private async Task Login()
{
string ReturnUrl = PageState.QueryString["returnurl"];
var authstateprovider = (IdentityAuthenticationStateProvider)ServiceProvider.GetService(typeof(IdentityAuthenticationStateProvider));
if (authstateprovider == null)
{
@ -61,12 +88,12 @@
var interop = new Interop(jsRuntime);
string antiforgerytoken = await interop.GetElementByName("__RequestVerificationToken");
var fields = new { __RequestVerificationToken = antiforgerytoken, username = Username, password = Password, remember = Remember, returnurl = ReturnUrl };
await interop.SubmitForm("/login/", fields);
await interop.SubmitForm("/pages/login/", fields);
}
else
{
await logger.LogInformation("Login Failed For Username {Username}", Username);
AddModuleMessage("Login Failed. Please Remember That Passwords Are Case Sensitive.", MessageType.Error);
AddModuleMessage("Login Failed. Please Remember That Passwords Are Case Sensitive And User Accounts Require Email Verification When They Initially Created.", MessageType.Error);
}
}
else
@ -86,14 +113,36 @@
else
{
await logger.LogInformation("Login Failed For Username {Username}", Username);
AddModuleMessage("Login Failed. Please Remember That Passwords Are Case Sensitive.", MessageType.Error);
AddModuleMessage("Login Failed. Please Remember That Passwords Are Case Sensitive And User Accounts Require Verification When They Are Initially Created So You May Wish To Check Your Email.", MessageType.Error);
}
}
}
private void Cancel()
{
string ReturnUrl = PageState.QueryString["returnurl"];
NavigationManager.NavigateTo(ReturnUrl);
}
private async Task Forgot()
{
if (Username != "")
{
User user = await UserService.GetUserAsync(Username, PageState.Site.SiteId);
if (user != null)
{
await UserService.ForgotPasswordAsync(user);
Message = "Please Check The Email Address Associated To Your User Account For A Password Reset Notification";
}
else
{
Message = "User Does Not Exist";
Type = MessageType.Warning;
}
}
else
{
Message = "Please Enter The Username Related To Your Account And Then Click The Forgot Password Option";
}
StateHasChanged();
}
}

View File

@ -3,6 +3,11 @@
@inject NavigationManager NavigationManager
@inject IUserService UserService
@if (Message != "")
{
<ModuleMessage Message="@Message" Type="MessageType.Info" />
}
<div class="container">
<div class="form-group">
<label for="Username" class="control-label">Username: </label>
@ -13,43 +18,62 @@
<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" />
<label for="Password" class="control-label">Confirm Password: </label>
<input type="password" class="form-control" placeholder="Password" @bind="@Confirm" />
</div>
<button type="button" class="btn btn-primary" @onclick="RegisterUser">Register</button>
<div class="form-group">
<label for="Username" class="control-label">Email: </label>
<input type="text" class="form-control" placeholder="Email" @bind="@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" />
</div>
<button type="button" class="btn btn-primary" @onclick="Register">Register</button>
<button type="button" class="btn btn-secondary" @onclick="Cancel">Cancel</button>
</div>
@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 = "";
private async Task RegisterUser()
private async Task Register()
{
try
{
if (Username != "" && Password != "" && Email != "")
Message = "";
if (Username != "" && Password != "" && Confirm != "" && Email != "")
{
User user = new User();
user.SiteId = PageState.Site.SiteId;
user.Username = Username;
user.DisplayName = Username;
user.Email = Email;
user.Password = Password;
user = await UserService.AddUserAsync(user);
if (user != null)
if (Password == Confirm)
{
await logger.LogInformation("User Created {Username} {Email}", Username, Email);
NavigationManager.NavigateTo(NavigateUrl(""));
User user = new User();
user.SiteId = PageState.Site.SiteId;
user.Username = Username;
user.DisplayName = (DisplayName == "" ? Username : DisplayName);
user.Email = Email;
user.Password = Password;
user = await UserService.AddUserAsync(user);
if (user != null)
{
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);
AddModuleMessage("Error Adding User. Please Ensure Password Meets Complexity Requirements And Username Is Not Already In Use.", MessageType.Error);
}
}
else
{
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);
AddModuleMessage("Passwords Entered Do Not Match", MessageType.Warning);
}
}
else

View File

@ -0,0 +1,89 @@
@namespace Oqtane.Modules.Admin.Reset
@inherits ModuleBase
@inject NavigationManager NavigationManager
@inject IUserService UserService
<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" readonly />
</div>
<div class="form-group">
<label for="Password" class="control-label">Password: </label>
<input type="password" class="form-control" placeholder="Password" @bind="@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" />
</div>
<button type="button" class="btn btn-primary" @onclick="Reset">Reset Password</button>
<button type="button" class="btn btn-secondary" @onclick="Cancel">Cancel</button>
</div>
@code {
public override SecurityAccessLevel SecurityAccessLevel { get { return SecurityAccessLevel.Anonymous; } }
string Username = "";
string Password = "";
string Confirm = "";
protected override void OnInitialized()
{
if (PageState.QueryString.ContainsKey("name") && PageState.QueryString.ContainsKey("token"))
{
Username = PageState.QueryString["name"];
}
else
{
NavigationManager.NavigateTo(NavigateUrl(""));
}
}
private async Task Reset()
{
try
{
if (Username != "" && Password != "" && Confirm != "")
{
if (Password == Confirm)
{
User user = new User();
user.SiteId = PageState.Site.SiteId;
user.Username = Username;
user.DisplayName = Username;
user.Password = Password;
user = await UserService.ResetPasswordAsync(user, PageState.QueryString["token"]);
if (user != null)
{
await logger.LogInformation("User Password Reset {Username}", Username);
NavigationManager.NavigateTo(NavigateUrl("login"));
}
else
{
await logger.LogError("Error Resetting User Password {Username}", Username);
AddModuleMessage("Error Resetting User Password. Please Ensure Password Meets Complexity Requirements.", MessageType.Error);
}
}
else
{
AddModuleMessage("Passwords Entered Do Not Match", MessageType.Warning);
}
}
else
{
AddModuleMessage("You Must Provide A Username, Password, and Email Address", MessageType.Warning);
}
}
catch (Exception ex)
{
await logger.LogError(ex, "Error Resetting User Password {Username} {Error}", Username, ex.Message);
AddModuleMessage("Error Resetting User Password", MessageType.Error);
}
}
private void Cancel()
{
NavigationManager.NavigateTo(NavigateUrl(""));
}
}

View File

@ -101,7 +101,7 @@ else
<label for="Name" class="control-label">Host Username:</label>
</td>
<td>
<input class="form-control" @bind="@username" disabled />
<input class="form-control" @bind="@username" readonly />
</td>
</tr>
<tr>
@ -143,7 +143,7 @@ else
urls = PageState.Alias.Name;
themes = ThemeService.GetThemeTypes(PageState.Themes);
containers = ThemeService.GetContainerTypes(PageState.Themes);
username = PageState.User.Username;
username = Constants.HostUser;
}
private async void TenantChanged(ChangeEventArgs e)

View File

@ -4,6 +4,7 @@
@inject ISiteService SiteService
@inject IAliasService AliasService
@inject IThemeService ThemeService
@inject ISettingService SettingService
@if (themes == null)
{
@ -11,92 +12,141 @@
}
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">Aliases: </label>
</td>
<td>
<textarea class="form-control" @bind="@urls" rows="3" />
</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" @onchange="(e => ThemeChanged(e))">
<option value="">&lt;Select Theme&gt;</option>
@foreach (KeyValuePair<string, string> item in themes)
{
if (item.Key == themetype)
<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">Aliases: </label>
</td>
<td>
<textarea class="form-control" @bind="@urls" rows="3" />
</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" @onchange="(e => ThemeChanged(e))">
<option value="">&lt;Select Theme&gt;</option>
@foreach (KeyValuePair<string, string> item in themes)
{
<option value="@item.Key" selected>@item.Value</option>
if (item.Key == themetype)
{
<option value="@item.Key" selected>@item.Value</option>
}
else
{
<option value="@item.Key">@item.Value</option>
}
}
else
</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="@item.Key">@item.Value</option>
<option value="@panelayout.Key">@panelayout.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>
<tr>
<td>
<label for="Name" class="control-label">Default Container: </label>
</td>
<td>
<select class="form-control" @bind="@containertype">
<option value="">&lt;Select Container&gt;</option>
@foreach (KeyValuePair<string, string> container in containers)
{
<option value="@container.Key">@container.Value</option>
}
</select>
</td>
</tr>
<tr>
<td>
<label for="Name" class="control-label">Is Deleted? </label>
</td>
<td>
<select class="form-control" @bind="@isdeleted">
<option value="True">Yes</option>
<option value="False">No</option>
</select>
</td>
</tr>
</table>
</select>
</td>
</tr>
<tr>
<td>
<label for="Name" class="control-label">Default Container: </label>
</td>
<td>
<select class="form-control" @bind="@containertype">
<option value="">&lt;Select Container&gt;</option>
@foreach (KeyValuePair<string, string> container in containers)
{
<option value="@container.Key">@container.Value</option>
}
</select>
</td>
</tr>
<tr>
<td>
<label for="Name" class="control-label">Is Deleted? </label>
</td>
<td>
<select class="form-control" @bind="@isdeleted">
<option value="True">Yes</option>
<option value="False">No</option>
</select>
</td>
</tr>
</table>
<a data-toggle="collapse" class="app-link-unstyled" href="#SMTP" aria-expanded="false" aria-controls="SMTP">
<h5>SMTP Settings</h5><hr class="app-rule" />
</a>
<div class="collapse" id="SMTP">
<table class="table table-borderless">
<tr>
<td>
<label for="Name" class="control-label">Host: </label>
</td>
<td>
<input class="form-control" @bind="@smtphost" />
</td>
</tr>
<tr>
<td>
<label for="Name" class="control-label">Port: </label>
</td>
<td>
<input class="form-control" @bind="@smtpport" />
</td>
</tr>
<tr>
<td>
<label for="Name" class="control-label">SSL Enabled: </label>
</td>
<td>
<input class="form-control" @bind="@smtpssl" />
</td>
</tr>
<tr>
<td>
<label for="Name" class="control-label">Username: </label>
</td>
<td>
<input class="form-control" @bind="@smtpusername" />
</td>
</tr>
<tr>
<td>
<label for="Name" class="control-label">Password: </label>
</td>
<td>
<input type="password" class="form-control" @bind="@smtppassword" />
</td>
</tr>
</table>
</div>
<button type="button" class="btn btn-success" @onclick="SaveSite">Save</button>
<NavLink class="btn btn-secondary" href="@NavigateUrl()">Cancel</NavLink>
<br />
@ -121,6 +171,12 @@ else
string layouttype;
string containertype;
string smtphost = "";
string smtpport = "";
string smtpssl = "";
string smtpusername = "";
string smtppassword = "";
string createdby;
DateTime createdon;
string modifiedby;
@ -135,8 +191,8 @@ else
{
themes = ThemeService.GetThemeTypes(PageState.Themes);
containers = ThemeService.GetContainerTypes(PageState.Themes);
Alias = PageState.Aliases.Where(item => item.AliasId == Int32.Parse(PageState.QueryString["id"])).FirstOrDefault();
Alias = PageState.Aliases.Where(item => item.AliasId == Int32.Parse(PageState.QueryString["id"])).FirstOrDefault();
siteid = Alias.SiteId;
Site site = await SiteService.GetSiteAsync(siteid, Alias);
if (site != null)
@ -153,6 +209,13 @@ else
layouttype = site.DefaultLayoutType;
containertype = site.DefaultContainerType;
Dictionary<string, string> settings = await SettingService.GetSiteSettingsAsync(site.SiteId);
smtphost = SettingService.GetSetting(settings, "SMTPHost", "");
smtpport = SettingService.GetSetting(settings, "SMTPPort", "");
smtpssl = SettingService.GetSetting(settings, "SMTPSSL", "");
smtpusername = SettingService.GetSetting(settings, "SMTPUsername", "");
smtppassword = SettingService.GetSetting(settings, "SMTPPassword", "");
createdby = site.CreatedBy;
createdon = site.CreatedOn;
modifiedby = site.ModifiedBy;
@ -229,6 +292,15 @@ else
await AliasService.AddAliasAsync(alias);
}
}
Dictionary<string, string> settings = await SettingService.GetSiteSettingsAsync(site.SiteId);
SettingService.SetSetting(settings, "SMTPHost", smtphost);
SettingService.SetSetting(settings, "SMTPPort", smtpport);
SettingService.SetSetting(settings, "SMTPSSL", smtpssl);
SettingService.SetSetting(settings, "SMTPUsername", smtpusername);
SettingService.SetSetting(settings, "SMTPPassword", smtppassword);
await SettingService.UpdateModuleSettingsAsync(settings, site.SiteId);
await logger.LogInformation("Site Saved {Site}", site);
NavigationManager.NavigateTo(NavigateUrl(Reload.Site));

View File

@ -0,0 +1,100 @@
@namespace Oqtane.Modules.Admin.UserProfile
@inherits ModuleBase
@inject NavigationManager NavigationManager
@inject IUserRoleService UserRoleService
@inject INotificationService NotificationService
@if (PageState.User != null)
{
<table class="table table-borderless">
<tr>
<td>
<label for="Name" class="control-label">To: </label>
</td>
<td>
<select class="form-control" @bind="@userid">
<option value="-1">&lt;Select User&gt;</option>
@if (userroles != null)
{
foreach (UserRole userrole in userroles)
{
<option value="@userrole.UserId">@userrole.User.DisplayName</option>
}
}
</select>
</td>
</tr>
<tr>
<td>
<label for="Name" class="control-label">Subject: </label>
</td>
<td>
<input class="form-control" @bind="@subject" />
</td>
</tr>
<tr>
<td>
<label for="Name" class="control-label">Message: </label>
</td>
<td>
<textarea class="form-control" @bind="@body" rows="5" />
</td>
</tr>
</table>
<button type="button" class="btn btn-primary" @onclick="Send">Send</button>
<NavLink class="btn btn-secondary" href="@NavigateUrl()">Cancel</NavLink>
}
@code {
public override SecurityAccessLevel SecurityAccessLevel { get { return SecurityAccessLevel.View; } }
public override string Title { get { return "Send Notification"; } }
List<UserRole> userroles;
string userid = "-1";
string subject = "";
string body = "";
protected override async Task OnInitializedAsync()
{
try
{
userroles = await UserRoleService.GetUserRolesAsync(PageState.Site.SiteId);
userroles = userroles.Where(item => item.Role.Name == Constants.RegisteredRole || item.Role.Name == Constants.HostRole)
.OrderBy(item => item.User.DisplayName).ToList();
}
catch (Exception ex)
{
await logger.LogError(ex, "Error Loading Users {Error}", ex.Message);
AddModuleMessage("Error Loading Users", MessageType.Error);
}
}
private async Task Send()
{
Notification notification = new Notification();
try
{
notification.SiteId = PageState.Site.SiteId;
notification.FromUserId = PageState.User.UserId;
notification.ToUserId = int.Parse(userid);
notification.ToEmail = "";
notification.Subject = subject;
notification.Body = body;
notification.ParentId = null;
notification.CreatedOn = DateTime.Now;
notification.IsDelivered = false;
notification.DeliveredOn = null;
notification = await NotificationService.AddNotificationAsync(notification);
await logger.LogInformation("Notification Created {Notification}", notification);
NavigationManager.NavigateTo(NavigateUrl());
}
catch (Exception ex)
{
await logger.LogError(ex, "Error Adding Notification {Notification} {Error}", notification, ex.Message);
AddModuleMessage("Error Adding Notification", MessageType.Error);
}
}
}

View File

@ -4,69 +4,156 @@
@inject IUserService UserService
@inject IProfileService ProfileService
@inject ISettingService SettingService
@inject INotificationService NotificationService
@if (PageState.User != null && profiles != null)
{
<table class="table table-borderless">
<tr>
<td>
<label for="Name" class="control-label">Username: </label>
</td>
<td>
<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>
<td>
<label for="Name" class="control-label">Email: </label>
</td>
<td>
<input class="form-control" @bind="@email" />
</td>
</tr>
<tr>
<td>
<label for="Name" class="control-label">Full Name: </label>
</td>
<td>
<input class="form-control" @bind="@displayname" />
</td>
</tr>
<div class="container-fluid">
<div class="form-group">
@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 />
<ul class="nav nav-tabs" role="tablist">
<li class="nav-item">
<a class="nav-link active" data-toggle="tab" href="#Profile" role="tab">
Profile
</a>
</li>
<li class="nav-item">
<a class="nav-link" data-toggle="tab" href="#Notifications" role="tab">
Notifications
</a>
</li>
</ul>
<div class="tab-content">
<div id="Profile" class="tab-pane fade show active" role="tabpanel">
<br />
<table class="table table-borderless">
<tr>
<td>
<label for="Name" class="control-label">Username: </label>
</td>
<td>
<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>
<td>
<label for="Name" class="control-label">Confirm Password: </label>
</td>
<td>
<input type="password" class="form-control" @bind="@confirm" />
</td>
</tr>
<tr>
<td>
<label for="Name" class="control-label">Email: </label>
</td>
<td>
<input class="form-control" @bind="@email" />
</td>
</tr>
<tr>
<td>
<label for="Name" class="control-label">Full Name: </label>
</td>
<td>
<input class="form-control" @bind="@displayname" />
</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="Save">Save</button>
<button type="button" class="btn btn-secondary" @onclick="Cancel">Cancel</button>
</div>
<div id="Notifications" class="tab-pane fade" role="tabpanel">
<br />
<ActionLink Action="Add" Text="Send Notification" Security="SecurityAccessLevel.View" EditMode="false" />
<br /><br />
@if (filter == "to")
{
<Pager Items="@notifications">
<Header>
<th>&nbsp;</th>
<th>&nbsp;</th>
<th>From</th>
<th>Subject</th>
<th>Received</th>
</Header>
<Row>
<td><ActionLink Action="View" Parameters="@($"id=" + context.NotificationId.ToString())" Security="SecurityAccessLevel.View" EditMode="false" /></td>
<td><ActionDialog Header="Delete Notification" Message="@("Are You Sure You Wish To Delete This Notification?")" Action="Delete" Security="SecurityAccessLevel.View" Class="btn btn-danger" OnClick="@(async () => await Delete(context))" EditMode="false" /></td>
<td>@(context.FromUser == null ? "System" : context.FromUser.DisplayName)</td>
<td>@context.Subject</td>
<td>@context.CreatedOn</td>
</Row>
<Detail>
<td colspan="2"></td>
<td colspan="3">@(context.Body.Length > 100 ? context.Body.Substring(0,100) : context.Body)</td>
</Detail>
</Pager>
}
else
{
<Pager Items="@notifications">
<Header>
<th>&nbsp;</th>
<th>&nbsp;</th>
<th>To</th>
<th>Subject</th>
<th>Sent</th>
</Header>
<Row>
<td><ActionLink Action="View" Parameters="@($"id=" + context.NotificationId.ToString())" Security="SecurityAccessLevel.View" EditMode="false" /></td>
<td><ActionDialog Header="Delete Notification" Message="@("Are You Sure You Wish To Delete This Notification?")" Action="Delete" Security="SecurityAccessLevel.View" Class="btn btn-danger" OnClick="@(async () => await Delete(context))" EditMode="false" /></td>
<td>@(context.ToUser == null ? context.ToEmail : context.ToUser.DisplayName)</td>
<td>@context.Subject</td>
<td>@context.CreatedOn</td>
</Row>
<Detail>
<td colspan="2"></td>
<td colspan="3">@(context.Body.Length > 100 ? context.Body.Substring(0,100) : context.Body)</td>
</Detail>
</Pager>
}
<br /><hr />
<select class="form-control" @onchange="(e => FilterChanged(e))">
<option value="to">Inbox</option>
<option value="from">Sent Items</option>
</select>
</div>
</div>
</div>
</div>
}
@code {
@ -74,11 +161,14 @@
string username = "";
string password = "";
string confirm = "";
string email = "";
string displayname = "";
List<Profile> profiles;
Dictionary<string, string> settings;
string category = "";
string filter = "to";
List<Notification> notifications;
protected override async Task OnInitializedAsync()
{
@ -91,6 +181,7 @@
displayname = PageState.User.DisplayName;
profiles = await ProfileService.GetProfilesAsync(ModuleState.SiteId);
settings = await SettingService.GetUserSettingsAsync(PageState.User.UserId);
await LoadNotificationsAsync();
}
else
{
@ -104,25 +195,45 @@
}
}
private async Task LoadNotificationsAsync()
{
notifications = await NotificationService.GetNotificationsAsync(PageState.Site.SiteId, filter, PageState.User.UserId);
notifications = notifications.Where(item => item.DeletedBy != PageState.User.Username).ToList();
}
private string GetProfileValue(string SettingName, string DefaultValue)
{
return SettingService.GetSetting(settings, SettingName, DefaultValue);
}
private async Task SaveUser()
private async Task Save()
{
try
{
User user = PageState.User;
user.Username = username;
user.Password = password;
user.Email = email;
user.DisplayName = displayname;
await UserService.UpdateUserAsync(user);
await SettingService.UpdateUserSettingsAsync(settings, PageState.User.UserId);
await logger.LogInformation("User Profile Saved");
if (password != "" && confirm != "" && email != "")
{
if (password == confirm)
{
User user = PageState.User;
user.Username = username;
user.Password = password;
user.Email = email;
user.DisplayName = (displayname == "" ? username : displayname);
await UserService.UpdateUserAsync(user);
await SettingService.UpdateUserSettingsAsync(settings, PageState.User.UserId);
await logger.LogInformation("User Profile Saved");
NavigationManager.NavigateTo(NavigateUrl(""));
NavigationManager.NavigateTo(NavigateUrl(""));
}
else
{
AddModuleMessage("Passwords Entered Do Not Match", MessageType.Warning);
}
}
else
{
AddModuleMessage("You Must Provide A Username, Password, and Email Address", MessageType.Warning);
}
}
catch (Exception ex)
{
@ -141,4 +252,36 @@
string value = (string)e.Value;
settings = SettingService.SetSetting(settings, SettingName, value);
}
private async Task Delete(Notification Notification)
{
try
{
if (!Notification.IsDeleted)
{
Notification.IsDeleted = true;
await NotificationService.UpdateNotificationAsync(Notification);
}
else
{
await NotificationService.DeleteNotificationAsync(Notification.NotificationId);
}
await logger.LogInformation("Notification Deleted {Notification}", Notification);
await LoadNotificationsAsync();
StateHasChanged();
}
catch (Exception ex)
{
await logger.LogError(ex, "Error Deleting Notification {Notification} {Error}", Notification, ex.Message);
AddModuleMessage(ex.Message, MessageType.Error);
}
}
private async void FilterChanged(ChangeEventArgs e)
{
filter = (string)e.Value;
await LoadNotificationsAsync();
StateHasChanged();
}
}

View File

@ -0,0 +1,161 @@
@namespace Oqtane.Modules.Admin.UserProfile
@inherits ModuleBase
@inject NavigationManager NavigationManager
@inject IUserRoleService UserRoleService
@inject INotificationService NotificationService
@if (PageState.User != null)
{
<table class="table table-borderless">
<tr>
<td>
<label for="Name" class="control-label">@title: </label>
</td>
<td>
<select class="form-control" readonly @bind="userid">
<option value="-1">&lt;System&gt;</option>
@if (userroles != null)
{
foreach (UserRole userrole in userroles)
{
<option value="@userrole.UserId">@userrole.User.DisplayName</option>
}
}
</select>
</td>
</tr>
<tr>
<td>
<label for="Name" class="control-label">Subject: </label>
</td>
<td>
<input class="form-control" @bind="@subject" />
</td>
</tr>
@if (title == "From")
{
<tr>
<td>
<label for="Name" class="control-label">Date: </label>
</td>
<td>
<input class="form-control" @bind="@createdon" />
</td>
</tr>
}
<tr>
<td>
<label for="Name" class="control-label">Message: </label>
</td>
<td>
<textarea class="form-control" @bind="@body" rows="5" />
</td>
</tr>
</table>
@if (reply != "")
{
<button type="button" class="btn btn-primary" @onclick="Send">Send</button>
}
else
{
if (title == "From")
{
<button type="button" class="btn btn-primary" @onclick="Reply">Reply</button>
}
}
<NavLink class="btn btn-secondary" href="@NavigateUrl()">Cancel</NavLink>
<br />
<br />
<p>@reply</p>
}
@code {
public override SecurityAccessLevel SecurityAccessLevel { get { return SecurityAccessLevel.View; } }
public override string Title { get { return "View Notification"; } }
int notificationid;
string title = "";
List<UserRole> userroles;
string userid = "-1";
string subject = "";
string createdon = "";
string body = "";
string reply = "";
protected override async Task OnInitializedAsync()
{
try
{
userroles = await UserRoleService.GetUserRolesAsync(PageState.Site.SiteId);
userroles = userroles.Where(item => item.Role.Name == Constants.RegisteredRole || item.Role.Name == Constants.HostRole)
.OrderBy(item => item.User.DisplayName).ToList();
notificationid = Int32.Parse(PageState.QueryString["id"]);
Notification notification = await NotificationService.GetNotificationAsync(notificationid);
if (notification != null)
{
if (notification.ToUserId == PageState.User.UserId)
{
title = "From";
if (notification.FromUserId != null)
{
userid = notification.FromUserId.ToString();
}
}
else
{
title = "To";
if (notification.ToUserId != null)
{
userid = notification.ToUserId.ToString();
}
}
subject = notification.Subject;
createdon = notification.CreatedOn.ToString();
body = notification.Body;
}
}
catch (Exception ex)
{
await logger.LogError(ex, "Error Loading Users {Error}", ex.Message);
AddModuleMessage("Error Loading Users", MessageType.Error);
}
}
private void Reply()
{
title = "To";
subject = "RE: " + subject;
reply = body;
StateHasChanged();
}
private async Task Send()
{
Notification notification = new Notification();
notification.SiteId = PageState.Site.SiteId;
notification.FromUserId = PageState.User.UserId;
notification.ToUserId = int.Parse(userid);
notification.ToEmail = "";
notification.Subject = subject;
notification.Body = body;
notification.ParentId = notificationid;
notification.CreatedOn = DateTime.Now;
notification.IsDelivered = false;
notification.DeliveredOn = null;
try
{
notification = await NotificationService.AddNotificationAsync(notification);
await logger.LogInformation("Notification Created {Notification}", notification);
NavigationManager.NavigateTo(NavigateUrl());
}
catch (Exception ex)
{
await logger.LogError(ex, "Error Adding Notification {Notification} {Error}", notification, ex.Message);
AddModuleMessage("Error Adding Notification", MessageType.Error);
}
}
}

View File

@ -24,6 +24,14 @@
<input type="password" class="form-control" @bind="@password" />
</td>
</tr>
<tr>
<td>
<label for="Name" class="control-label">Confirm Password: </label>
</td>
<td>
<input type="password" class="form-control" @bind="@confirm" />
</td>
</tr>
<tr>
<td>
<label for="Name" class="control-label">Email: </label>
@ -72,6 +80,7 @@
string username = "";
string password = "";
string confirm = "";
string email = "";
string displayname = "";
List<Profile> profiles;
@ -96,25 +105,39 @@
{
try
{
User user = new User();
user.SiteId = PageState.Site.SiteId;
user.Username = username;
user.Password = password;
user.Email = email;
user.DisplayName = string.IsNullOrWhiteSpace(user.DisplayName) ? user.Username : user.DisplayName;
user = await UserService.AddUserAsync(user);
if (user != null)
if (username != "" && password != "" && confirm != "" && email != "")
{
await SettingService.UpdateUserSettingsAsync(settings, user.UserId);
await logger.LogInformation("User Created {User}", user);
NavigationManager.NavigateTo(NavigateUrl());
if (password == confirm)
{
User user = new User();
user.SiteId = PageState.Site.SiteId;
user.Username = username;
user.Password = password;
user.Email = email;
user.DisplayName = string.IsNullOrWhiteSpace(displayname) ? username : displayname;
user = await UserService.AddUserAsync(user);
if (user != null)
{
await SettingService.UpdateUserSettingsAsync(settings, user.UserId);
await logger.LogInformation("User Created {User}", user);
NavigationManager.NavigateTo(NavigateUrl());
}
else
{
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);
}
}
else
{
AddModuleMessage("Passwords Entered Do Not Match", MessageType.Warning);
}
}
else
{
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);
AddModuleMessage("You Must Provide A Username, Password, and Email Address", MessageType.Warning);
}
}
catch (Exception ex)

View File

@ -24,6 +24,14 @@
<input type="password" class="form-control" @bind="@password" />
</td>
</tr>
<tr>
<td>
<label for="Name" class="control-label">Confirm Password: </label>
</td>
<td>
<input type="password" class="form-control" @bind="@confirm" />
</td>
</tr>
<tr>
<td>
<label for="Name" class="control-label">Email: </label>
@ -87,6 +95,7 @@
int userid;
string username = "";
string password = "";
string confirm = "";
string email = "";
string displayname = "";
List<Profile> profiles;
@ -139,19 +148,33 @@
{
try
{
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 = string.IsNullOrWhiteSpace(user.DisplayName) ? user.Username : user.DisplayName;
user.IsDeleted = (isdeleted == null ? true : Boolean.Parse(isdeleted));
if (username != "" && password != "" && confirm != "" && email != "")
{
if (password == confirm)
{
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 = string.IsNullOrWhiteSpace(displayname) ? username : displayname;
user.IsDeleted = (isdeleted == null ? true : Boolean.Parse(isdeleted));
user = await UserService.UpdateUserAsync(user);
await SettingService.UpdateUserSettingsAsync(settings, user.UserId);
await logger.LogInformation("User Saved {User}", user);
user = await UserService.UpdateUserAsync(user);
await SettingService.UpdateUserSettingsAsync(settings, user.UserId);
await logger.LogInformation("User Saved {User}", user);
NavigationManager.NavigateTo(NavigateUrl());
NavigationManager.NavigateTo(NavigateUrl());
}
else
{
AddModuleMessage("Passwords Entered Do Not Match", MessageType.Warning);
}
}
else
{
AddModuleMessage("You Must Provide A Username, Password, and Email Address", MessageType.Warning);
}
}
catch (Exception ex)
{