Adds Blazor Web App standard login
This commit is contained in:
13
WatchLog/Components/Pages/Auth.razor
Normal file
13
WatchLog/Components/Pages/Auth.razor
Normal file
@@ -0,0 +1,13 @@
|
||||
@page "/auth"
|
||||
|
||||
@using Microsoft.AspNetCore.Authorization
|
||||
|
||||
@attribute [Authorize]
|
||||
|
||||
<PageTitle>Auth</PageTitle>
|
||||
|
||||
<h1>You are authenticated</h1>
|
||||
|
||||
<AuthorizeView>
|
||||
Hello @context.User.Identity?.Name!
|
||||
</AuthorizeView>
|
||||
23
WatchLog/Components/Pages/Counter.razor
Normal file
23
WatchLog/Components/Pages/Counter.razor
Normal file
@@ -0,0 +1,23 @@
|
||||
@page "/counter"
|
||||
@rendermode InteractiveServer
|
||||
|
||||
@using Microsoft.AspNetCore.Authorization
|
||||
|
||||
@attribute [Authorize]
|
||||
|
||||
<PageTitle>Counter</PageTitle>
|
||||
|
||||
<h1>Counter</h1>
|
||||
|
||||
<p role="status">Current count: @currentCount</p>
|
||||
|
||||
<button class="btn btn-primary" @onclick="IncrementCount">Click me</button>
|
||||
|
||||
@code {
|
||||
private int currentCount = 0;
|
||||
|
||||
private void IncrementCount()
|
||||
{
|
||||
currentCount++;
|
||||
}
|
||||
}
|
||||
@@ -1,38 +0,0 @@
|
||||
@rendermode InteractiveServer
|
||||
@page "/GlobalEntities"
|
||||
@using Microsoft.EntityFrameworkCore
|
||||
@using WatchLog.Data
|
||||
@inject IDbContextFactory<WatchLogDataContext> WatchLogDataContextFactory;
|
||||
<PageTitle>GlobalEntities</PageTitle>
|
||||
|
||||
@if (ShowCreate)
|
||||
{
|
||||
<h3>Add a New GlobalEntity</h3>
|
||||
<div class="row">
|
||||
<label for="Title" class="col-4 col-form-label">Name</label>
|
||||
<div class="col-8">
|
||||
<input id="Title" name="Title" type="text" class="form-control" @bind="@NewGlobalEntity.Title" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<label for="Password" class="col-4 col-form-label">Password</label>
|
||||
<div class="col-8">
|
||||
<input id="Password" name="Password" type="text" class="form-control"/>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group row">
|
||||
<div class="offset-4 col-8">
|
||||
<button name="submit" type="submit" class="btn btn-primary" @onclick="CreateNewGlobalEntity">Submit</button>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
else
|
||||
{
|
||||
<div class="form-group row">
|
||||
<div class="offset-4 col-8">
|
||||
<button name="submit" type="submit" class="btn btn-primary" @onclick="ShowCreateForm">Add a new Global Entity</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<p>SHOW THE LIST</p>
|
||||
}
|
||||
@@ -1,45 +0,0 @@
|
||||
using Microsoft.AspNetCore.Components;
|
||||
using WatchLog.Data;
|
||||
|
||||
namespace WatchLog.Components.Pages
|
||||
{
|
||||
public partial class GlobalEntities
|
||||
{
|
||||
public bool ShowCreate { get; set; }
|
||||
|
||||
private WatchLogDataContext? _context;
|
||||
|
||||
public required GlobalEntity NewGlobalEntity { get; set; }
|
||||
|
||||
protected override Task OnInitializedAsync()
|
||||
{
|
||||
ShowCreate = false;
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
public void ShowCreateForm()
|
||||
{
|
||||
ShowCreate = true;
|
||||
NewGlobalEntity = new GlobalEntity
|
||||
{
|
||||
Title = "",
|
||||
CreationTime = DateTime.Now,
|
||||
CreatorId = 1,
|
||||
TypeId = 1,
|
||||
};
|
||||
}
|
||||
|
||||
public async Task CreateNewGlobalEntity()
|
||||
{
|
||||
_context ??= await WatchLogDataContextFactory.CreateDbContextAsync();
|
||||
|
||||
if (NewGlobalEntity is not null)
|
||||
{
|
||||
_context?.GlobalEntities.Add(NewGlobalEntity);
|
||||
_context?.SaveChangesAsync();
|
||||
}
|
||||
|
||||
ShowCreate = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,9 @@
|
||||
@page "/"
|
||||
|
||||
@using Microsoft.AspNetCore.Authorization
|
||||
|
||||
@attribute [Authorize]
|
||||
|
||||
<PageTitle>Home</PageTitle>
|
||||
|
||||
<h1>Hello, world!</h1>
|
||||
|
||||
68
WatchLog/Components/Pages/Weather.razor
Normal file
68
WatchLog/Components/Pages/Weather.razor
Normal file
@@ -0,0 +1,68 @@
|
||||
@page "/weather"
|
||||
@attribute [StreamRendering]
|
||||
|
||||
@using Microsoft.AspNetCore.Authorization
|
||||
|
||||
@attribute [Authorize(Roles = "Admin")]
|
||||
|
||||
<PageTitle>Weather</PageTitle>
|
||||
|
||||
<h1>Weather</h1>
|
||||
|
||||
<p>This component demonstrates showing data.</p>
|
||||
|
||||
@if (forecasts == null)
|
||||
{
|
||||
<p><em>Loading...</em></p>
|
||||
}
|
||||
else
|
||||
{
|
||||
<table class="table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Date</th>
|
||||
<th aria-label="Temperature in Celsius">Temp. (C)</th>
|
||||
<th aria-label="Temperature in Farenheit">Temp. (F)</th>
|
||||
<th>Summary</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@foreach (var forecast in forecasts)
|
||||
{
|
||||
<tr>
|
||||
<td>@forecast.Date.ToShortDateString()</td>
|
||||
<td>@forecast.TemperatureC</td>
|
||||
<td>@forecast.TemperatureF</td>
|
||||
<td>@forecast.Summary</td>
|
||||
</tr>
|
||||
}
|
||||
</tbody>
|
||||
</table>
|
||||
}
|
||||
|
||||
@code {
|
||||
private WeatherForecast[]? forecasts;
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
// Simulate asynchronous loading to demonstrate streaming rendering
|
||||
await Task.Delay(500);
|
||||
|
||||
var startDate = DateOnly.FromDateTime(DateTime.Now);
|
||||
var summaries = new[] { "Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching" };
|
||||
forecasts = Enumerable.Range(1, 5).Select(index => new WeatherForecast
|
||||
{
|
||||
Date = startDate.AddDays(index),
|
||||
TemperatureC = Random.Shared.Next(-20, 55),
|
||||
Summary = summaries[Random.Shared.Next(summaries.Length)]
|
||||
}).ToArray();
|
||||
}
|
||||
|
||||
private class WeatherForecast
|
||||
{
|
||||
public DateOnly Date { get; set; }
|
||||
public int TemperatureC { get; set; }
|
||||
public string? Summary { get; set; }
|
||||
public int TemperatureF => 32 + (int)(TemperatureC / 0.5556);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user