Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 24 additions & 12 deletions ProjectFishWorksWebApp/App.razor
Original file line number Diff line number Diff line change
@@ -1,12 +1,24 @@
<Router AppAssembly="@typeof(App).Assembly">
<Found Context="routeData">
<RouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)" />
<FocusOnNavigate RouteData="@routeData" Selector="h1" />
</Found>
<NotFound>
<PageTitle>Not found</PageTitle>
<LayoutView Layout="@typeof(MainLayout)">
<p role="alert">Sorry, there's nothing at this address.</p>
</LayoutView>
</NotFound>
</Router>
<!-- Client/App.razor -->

<CascadingAuthenticationState>
<Router AppAssembly="@typeof(App).Assembly">
<Found Context="routeData">
<AuthorizeRouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)">
<Authorizing>
<p>Determining session state, please wait...</p>
</Authorizing>
<NotAuthorized>
<h1>Sorry</h1>
<p>You're not authorized to reach this page. You need to log in.</p>
</NotAuthorized>
</AuthorizeRouteView>
<FocusOnNavigate RouteData="@routeData" Selector="h1" />
</Found>
<NotFound>
<PageTitle>Not found</PageTitle>
<LayoutView Layout="@typeof(MainLayout)">
<p role="alert">Sorry, there's nothing at this address.</p>
</LayoutView>
</NotFound>
</Router>
</CascadingAuthenticationState>
26 changes: 26 additions & 0 deletions ProjectFishWorksWebApp/Components/AccessControl.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@


@using Microsoft.AspNetCore.Components.Authorization
@using Microsoft.AspNetCore.Components.WebAssembly.Authentication

@inject NavigationManager Navigation
@inject SignOutSessionStateManager SignOutManager

<AuthorizeView>
<Authorized>
Hello, @context.User.Identity.Name, @context.User.Claims.FirstOrDefault(k => k.Type == "sub").Value;
<a href="#" @onclick="BeginSignOut">Log out</a>
</Authorized>
<NotAuthorized>
<a href="authentication/login">Log in</a>
</NotAuthorized>
</AuthorizeView>

@code {
private async Task BeginSignOut(MouseEventArgs args)
{
await SignOutManager.SetSignOutState();
Navigation.NavigateTo("authentication/logout");

}
}
23 changes: 23 additions & 0 deletions ProjectFishWorksWebApp/Components/Authentication.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
@* Client/Pages/Authentication.razor *@

@page "/authentication/{action}"
@using Microsoft.AspNetCore.Components.WebAssembly.Authentication
@using Microsoft.Extensions.Configuration

@inject NavigationManager Navigation
@inject IConfiguration Configuration

<RemoteAuthenticatorView Action="@Action">
<LogOut>
@{
var authority = (string)Configuration["Auth0:Authority"];
var clientId = (string)Configuration["Auth0:ClientId"];

Navigation.NavigateTo($"https://app.projectfishworks.ca/v2/logout?client_id={clientId}");
}
</LogOut>
</RemoteAuthenticatorView>

@code {
[Parameter] public string Action { get; set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@
[Parameter]
public int nodeID { get; set; } = 0;

[CascadingParameter]
private Task<AuthenticationState>? authenticationState { get; set; }

ACControlDevice aCControlDevice;

BaseStationManifests baseStationManifests;
Expand Down Expand Up @@ -124,14 +127,21 @@
{

//Create the TesterHatDevice data model
this.aCControlDevice = new ACControlDevice(MqttService, this.systemID, this.basestationID, this.nodeID);

if (authenticationState is not null)
{
var authState = await authenticationState;
this.aCControlDevice = new ACControlDevice(MqttService, authState.User.Claims.FirstOrDefault(k => k.Type == "sub").Value ?? "", this.systemID, this.basestationID, this.nodeID);

baseStationManifests = new BaseStationManifests(authState.User.Claims.FirstOrDefault(k => k.Type == "sub").Value ?? "", systemID, MqttService);

}
if (MqttService.IsConnected())
{
MqttService.MessageReceived += MqttClient_MessageReceived;
}

baseStationManifests = new BaseStationManifests(systemID, MqttService);

}

private void MqttClient_MessageReceived(object sender, MqttApplicationMessageReceivedEventArgs e)
Expand Down
13 changes: 11 additions & 2 deletions ProjectFishWorksWebApp/Components/DevicePages/ACControlPage.razor
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,9 @@
[Parameter]
public int nodeID { get; set; } = 0;

[CascadingParameter]
private Task<AuthenticationState>? authenticationState { get; set; }

ACControlDevice aCControlDevice;

BaseStationManifests baseStationManifests;
Expand Down Expand Up @@ -155,15 +158,21 @@
protected override async Task OnInitializedAsync()
{


//Create the TesterHatDevice data model
this.aCControlDevice = new ACControlDevice(MqttService, this.systemID, this.basestationID, this.nodeID);
if (authenticationState is not null)
{
var authState = await authenticationState;
this.aCControlDevice = new ACControlDevice(MqttService, authState.User.Claims.FirstOrDefault(k => k.Type == "sub").Value ?? "", this.systemID, this.basestationID, this.nodeID);
baseStationManifests = new BaseStationManifests(authState.User.Claims.FirstOrDefault(k => k.Type == "sub").Value ?? "", systemID, MqttService);
}

if (MqttService.IsConnected())
{
MqttService.MessageReceived += MqttClient_MessageReceived;
}

baseStationManifests = new BaseStationManifests(systemID, MqttService);

}

private void MqttClient_MessageReceived(object sender, MqttApplicationMessageReceivedEventArgs e)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,20 @@
[Parameter]
public int NodeID { get; set; }

[CascadingParameter]
private Task<AuthenticationState>? authenticationState { get; set; }


BaseStationDevice baseStationDevice;


protected override async Task OnInitializedAsync()
{
this.baseStationDevice = new BaseStationDevice(MqttService, this.SystemID, BaseStationID, this.NodeID);
if (authenticationState is not null)
{
var authState = await authenticationState;
this.baseStationDevice = new BaseStationDevice(MqttService, authState.User.Claims.FirstOrDefault(k => k.Type == "sub").Value ?? "", this.SystemID, BaseStationID, this.NodeID);
}
if (MqttService.IsConnected())
{
MqttService.MessageReceived += MqttClient_MessageReceived;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,12 +232,19 @@
[Parameter]
public int NodeID { get; set; }

[CascadingParameter]
private Task<AuthenticationState>? authenticationState { get; set; }


LeakSensorDevice leakSensorDevice;

protected override async Task OnInitializedAsync()
{
this.leakSensorDevice = new LeakSensorDevice(MqttService, this.SystemID, BaseStationID, this.NodeID);
if (authenticationState is not null)
{
var authState = await authenticationState;
this.leakSensorDevice = new LeakSensorDevice(MqttService, authState.User.Claims.FirstOrDefault(k => k.Type == "sub").Value ?? "", this.SystemID, BaseStationID, this.NodeID);
}
if (MqttService.IsConnected())
{
MqttService.MessageReceived += MqttClient_MessageReceived;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -261,12 +261,19 @@
[Parameter]
public int NodeID { get; set; }

[CascadingParameter]
private Task<AuthenticationState>? authenticationState { get; set; }


LightingControlDevice lightingControlDevice;

protected override async Task OnInitializedAsync()
{
this.lightingControlDevice = new LightingControlDevice(MqttService, this.SystemID, BaseStationID, this.NodeID);
if (authenticationState is not null)
{
var authState = await authenticationState;
this.lightingControlDevice = new LightingControlDevice(MqttService, authState.User.Claims.FirstOrDefault(k => k.Type == "sub").Value ?? "", this.SystemID, BaseStationID, this.NodeID);
}
if (MqttService.IsConnected())
{
MqttService.MessageReceived += MqttClient_MessageReceived;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@
[Parameter]
public int NodeID { get; set; } = 0;

[CascadingParameter]
private Task<AuthenticationState>? authenticationState { get; set; }

PHSensorDevice PHsensor;

private Dictionary<int, HistoryChartMessageIDData> historyMessageIDs = new Dictionary<int, HistoryChartMessageIDData>
Expand All @@ -92,7 +95,11 @@

protected override async Task OnInitializedAsync()
{
this.PHsensor = new PHSensorDevice(MqttService, this.SystemID, this.BasestationID, this.NodeID);
if (authenticationState is not null)
{
var authState = await authenticationState;
this.PHsensor = new PHSensorDevice(MqttService, authState.User.Claims.FirstOrDefault(k => k.Type == "sub").Value ?? "", this.SystemID, this.BasestationID, this.NodeID);
}

if (MqttService.IsConnected())
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,9 @@
[Parameter]
public int NodeID { get; set; } = 0;

[CascadingParameter]
private Task<AuthenticationState>? authenticationState { get; set; }

private Dictionary<int, HistoryChartMessageIDData> historyMessageIDs = new Dictionary<int, HistoryChartMessageIDData>
{
{2560, new HistoryChartMessageIDData{PerameterName = "Ambient Temperature", XAxisName = "Time", YAxisName = "Temperature °C"}},
Expand Down Expand Up @@ -208,7 +211,11 @@

protected override async Task OnInitializedAsync()
{
this.tempHum = new TempHumDevice(MqttService, this.SystemID, this.BasestationID, this.NodeID);
if (authenticationState is not null)
{
var authState = await authenticationState;
this.tempHum = new TempHumDevice(MqttService, authState.User.Claims.FirstOrDefault(k => k.Type == "sub").Value ?? "", this.SystemID, this.BasestationID, this.NodeID);
}

if (MqttService.IsConnected())
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@
[Parameter]
public int NodeID { get; set; }

[CascadingParameter]
private Task<AuthenticationState>? authenticationState { get; set; }

TerraruimSensorsDevice terraruimSensors;

private Dictionary<int, HistoryChartMessageIDData> historyMessageIDs = new Dictionary<int, HistoryChartMessageIDData>
Expand All @@ -79,7 +82,12 @@

protected override async Task OnInitializedAsync()
{
terraruimSensors = new TerraruimSensorsDevice(MqttService, this.SystemID, this.BaseStationID, this.NodeID);
if (authenticationState is not null)
{
var authState = await authenticationState;

terraruimSensors = new TerraruimSensorsDevice(MqttService, authState.User.Claims.FirstOrDefault(k => k.Type == "sub").Value ?? "", this.SystemID, this.BaseStationID, this.NodeID);
}

if (MqttService.IsConnected())
{
Expand All @@ -90,7 +98,7 @@
private void MqttClient_MessageReceived(object sender, MqttApplicationMessageReceivedEventArgs e)
{
//Refresh the UI when a message is received
if (int.Parse(e.ApplicationMessage.Topic.Split("/")[3]) == NodeID || e.ApplicationMessage.Topic.Split("/")[0] == "historyOut")
if (int.Parse(e.ApplicationMessage.Topic.Split("/")[4]) == NodeID || e.ApplicationMessage.Topic.Split("/")[1] == "historyOut")
{
base.StateHasChanged();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@
[Parameter]
public int nodeID { get; set; } = 0;

[CascadingParameter]
private Task<AuthenticationState>? authenticationState { get; set; }

TesterHatDevice testerHat;

//Event handlers for the HistoryChart component
Expand All @@ -91,7 +94,11 @@
{

//Create the TesterHatDevice data model
this.testerHat = new TesterHatDevice(MqttService, this.systemID, this.basestationID, this.nodeID);
if (authenticationState is not null)
{
var authState = await authenticationState;
this.testerHat = new TesterHatDevice(MqttService, authState.User.Claims.FirstOrDefault(k => k.Type == "sub").Value ?? "", this.systemID, this.basestationID, this.nodeID);
}

if (MqttService.IsConnected())
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,21 @@
[Parameter]
public int nodeID { get; set; } = 0;

[CascadingParameter]
private Task<AuthenticationState>? authenticationState { get; set; }

ACControlDevice aCControlDevice;


protected override async Task OnInitializedAsync()
{

//Create the TesterHatDevice data model
this.aCControlDevice = new ACControlDevice(MqttService, this.systemID, this.basestationID, this.nodeID);
if (authenticationState is not null)
{
var authState = await authenticationState;
this.aCControlDevice = new ACControlDevice(MqttService, authState.User.Claims.FirstOrDefault(k => k.Type == "sub").Value ?? "", this.systemID, this.basestationID, this.nodeID);
}

if (MqttService.IsConnected())
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,21 @@
[Parameter]
public int nodeID { get; set; } = 0;

[CascadingParameter]
private Task<AuthenticationState>? authenticationState { get; set; }

ACControlDevice aCControlDevice;


protected override async Task OnInitializedAsync()
{

//Create the TesterHatDevice data model
this.aCControlDevice = new ACControlDevice(MqttService, this.systemID, this.basestationID, this.nodeID);
if (authenticationState is not null)
{
var authState = await authenticationState;
this.aCControlDevice = new ACControlDevice(MqttService, authState.User.Claims.FirstOrDefault(k => k.Type == "sub").Value ?? "", this.systemID, this.basestationID, this.nodeID);
}

if (MqttService.IsConnected())
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,19 @@
[Parameter]
public int NodeID { get; set; }

[CascadingParameter]
private Task<AuthenticationState>? authenticationState { get; set; }


BaseStationDevice baseStationDevice;

protected override async Task OnInitializedAsync()
{
this.baseStationDevice = new BaseStationDevice(MqttService, this.SystemID, BaseStationID, this.NodeID);
if (authenticationState is not null)
{
var authState = await authenticationState;
this.baseStationDevice = new BaseStationDevice(MqttService, authState.User.Claims.FirstOrDefault(k => k.Type == "sub").Value ?? "", this.SystemID, BaseStationID, this.NodeID);
}
if (MqttService.IsConnected())
{
MqttService.MessageReceived += MqttClient_MessageReceived;
Expand Down
Loading
Loading