Skip to content
Open
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
30 changes: 18 additions & 12 deletions Beam.Client/App.razor
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
<Router AppAssembly="@typeof(App).Assembly">
<Found Context="routeData">
<RouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)" />
<FocusOnNavigate RouteData="@routeData" Selector="h1" />
</Found>
<NotFound>
<PageTitle>Darkness!</PageTitle>
<LayoutView Layout="@typeof(MainLayout)">
<p role="alert">Sorry, The light has gone out!</p>
</LayoutView>
</NotFound>
</Router>
<CascadingAuthenticationState>
<Router AppAssembly="@typeof(App).Assembly">
<Found Context="routeData">
<AuthorizeRouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)">
<NotAuthorized>
<RedirectToLogin />
</NotAuthorized>
</AuthorizeRouteView>
<FocusOnNavigate RouteData="@routeData" Selector="h1" />
</Found>
<NotFound>
<PageTitle>Darkness!</PageTitle>
<LayoutView Layout="@typeof(MainLayout)">
<p role="alert">Sorry, The light has gone out!</p>
</LayoutView>
</NotFound>
</Router>
</CascadingAuthenticationState>
1 change: 1 addition & 0 deletions Beam.Client/Beam.Client.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Components.Authorization" Version="10.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="10.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="10.0.0" PrivateAssets="all" />
</ItemGroup>
Expand Down
18 changes: 11 additions & 7 deletions Beam.Client/Pages/FrequencyList.razor
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,18 @@
</div>
}
}
<div class="nav-item px-3">
<div class="input-group">
<input @bind="name" placeholder="New Frequency" class="form-control" />
<div class="input-group-append">
<button @onclick="AddFrequencyClick" type="button" class="btn btn-outline-secondary"><span class="oi oi-plus"></span></button>
<AuthorizeView>
<Authorized>
<div class="nav-item px-3">
<div class="input-group">
<input @bind="name" placeholder="New Frequency" class="form-control" />
<div class="input-group-append">
<button @onclick="AddFrequencyClick" type="button" class="btn btn-outline-secondary"><span class="oi oi-plus"></span></button>
</div>
</div>
</div>
</div>
</div>
</Authorized>
</AuthorizeView>

@code
{
Expand Down
71 changes: 71 additions & 0 deletions Beam.Client/Pages/Login.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
@page "/login"
@inject BeamAuthenticationStateProvider auth
@inject NavigationManager navigation

<PageTitle>Sign in to BEAM</PageTitle>

<h2>Sign in</h2>

<EditForm Model="@request" OnValidSubmit="@SignIn">
<DataAnnotationsValidator />

<div class="mb-3">
<label class="form-label" for="login-username">Username</label>
<InputText id="login-username" class="form-control" autocomplete="username" @bind-Value="request.Username" />
<ValidationMessage For="@(() => request.Username)" />
</div>

<div class="mb-3">
<label class="form-label" for="login-password">Password</label>
<InputText id="login-password" type="password" class="form-control" autocomplete="current-password" @bind-Value="request.Password" />
<ValidationMessage For="@(() => request.Password)" />
</div>

@if (!string.IsNullOrWhiteSpace(error))
{
<div class="alert alert-danger" role="alert">@error</div>
}

<button class="btn btn-primary" type="submit" disabled="@busy">
@(busy ? "Signing in..." : "Sign in")
</button>
</EditForm>

<p class="mt-3">
Need an account? <NavLink href="@RegisterUrl">Create one</NavLink>.
</p>

@code {
private readonly LoginRequest request = new LoginRequest();
private string? error;
private bool busy;

[SupplyParameterFromQuery(Name = "returnUrl")]
public string? ReturnUrl { get; set; }

private string RegisterUrl =>
string.IsNullOrWhiteSpace(ReturnUrl) ? "register" : $"register?returnUrl={Uri.EscapeDataString(ReturnUrl)}";

private async Task SignIn()
{
busy = true;
error = null;

try
{
var result = await auth.Login(request);

if (!result.Succeeded)
{
error = result.Error;
return;
}

navigation.NavigateTo(string.IsNullOrWhiteSpace(ReturnUrl) ? "" : ReturnUrl);
}
finally
{
busy = false;
}
}
}
29 changes: 20 additions & 9 deletions Beam.Client/Pages/RayInput.razor
Original file line number Diff line number Diff line change
@@ -1,14 +1,25 @@
@inject DataService data
<p>
<Card Title="Cast a New Ray:">
<div class="input-group">
<input @bind="newRayText" class="form-control" />
<div class="input-group-append">
<button @onclick="ClearText" type="button" class="btn btn-outline-secondary"><span class="oi oi-circle-x"></span></button>
<button @onclick="CastRay" type="button" class="btn btn-outline-secondary"><span class="oi oi-audio"></span></button>
</div>
</div>
</Card>
<AuthorizeView>
<Authorized>
<Card Title="Cast a New Ray:">
<div class="input-group">
<input @bind="newRayText" class="form-control" />
<div class="input-group-append">
<button @onclick="ClearText" type="button" class="btn btn-outline-secondary"><span class="oi oi-circle-x"></span></button>
<button @onclick="CastRay" type="button" class="btn btn-outline-secondary"><span class="oi oi-audio"></span></button>
</div>
</div>
</Card>
</Authorized>
<NotAuthorized>
<Card Title="Cast a New Ray:">
<p>
<NavLink href="login">Sign in</NavLink> or <NavLink href="register">create an account</NavLink> to cast a ray.
</p>
</Card>
</NotAuthorized>
</AuthorizeView>
</p>

@code{
Expand Down
33 changes: 21 additions & 12 deletions Beam.Client/Pages/RayItem.razor
Original file line number Diff line number Diff line change
@@ -1,18 +1,27 @@
@inject DataService data
<Card>
<div class="row-fluid">
@if (!ray.UsersPrismed.Contains(data.CurrentUser.Name))
{
<button class="btn btn-outline-secondary col-1" @onclick="(() => data.PrismRay(ray.RayId))">
<span class="oi oi-rss"></span>@ray.PrismCount
</button>
}
else
{
<button class="btn btn-outline-success col-1" @onclick="(() => data.UnPrismRay(ray.RayId))">
<span class="oi oi-rss"></span>@ray.PrismCount
</button>
}
<AuthorizeView>
<Authorized>
@if (!ray.UsersPrismed.Contains(data.CurrentUserName))
{
<button class="btn btn-outline-secondary col-1" @onclick="(() => data.PrismRay(ray.RayId))">
<span class="oi oi-rss"></span>@ray.PrismCount
</button>
}
else
{
<button class="btn btn-outline-success col-1" @onclick="(() => data.UnPrismRay(ray.RayId))">
<span class="oi oi-rss"></span>@ray.PrismCount
</button>
}
</Authorized>
<NotAuthorized>
<NavLink class="btn btn-outline-secondary col-1" href="login" title="Sign in to prism this ray">
<span class="oi oi-rss"></span>@ray.PrismCount
</NavLink>
</NotAuthorized>
</AuthorizeView>
<span class="card-text col-9">"@ray.Text"</span>
</div>
<div class="row-fluid">
Expand Down
4 changes: 2 additions & 2 deletions Beam.Client/Pages/RayList.razor
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@

void UpdateNewRayText()
{
if (!data.Rays.Any(r => r.UserName == data.CurrentUser.Name))
if (data.IsSignedIn && !data.Rays.Any(r => r.UserName == data.CurrentUserName))
{
newRayText = $"Hello, My Name is {data.CurrentUser.Name}";
newRayText = $"Hello, My Name is {data.CurrentUserName}";
}
}

Expand Down
77 changes: 77 additions & 0 deletions Beam.Client/Pages/Register.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
@page "/register"
@inject BeamAuthenticationStateProvider auth
@inject NavigationManager navigation

<PageTitle>Create a BEAM account</PageTitle>

<h2>Create an account</h2>

<EditForm Model="@request" OnValidSubmit="@CreateAccount">
<DataAnnotationsValidator />

<div class="mb-3">
<label class="form-label" for="register-username">Username</label>
<InputText id="register-username" class="form-control" autocomplete="username" @bind-Value="request.Username" />
<ValidationMessage For="@(() => request.Username)" />
</div>

<div class="mb-3">
<label class="form-label" for="register-password">Password</label>
<InputText id="register-password" type="password" class="form-control" autocomplete="new-password" @bind-Value="request.Password" />
<ValidationMessage For="@(() => request.Password)" />
</div>

<div class="mb-3">
<label class="form-label" for="register-confirm">Confirm password</label>
<InputText id="register-confirm" type="password" class="form-control" autocomplete="new-password" @bind-Value="request.ConfirmPassword" />
<ValidationMessage For="@(() => request.ConfirmPassword)" />
</div>

@if (!string.IsNullOrWhiteSpace(error))
{
<div class="alert alert-danger" role="alert">@error</div>
}

<button class="btn btn-primary" type="submit" disabled="@busy">
@(busy ? "Creating account..." : "Create account")
</button>
</EditForm>

<p class="mt-3">
Already have an account? <NavLink href="@LoginUrl">Sign in</NavLink>.
</p>

@code {
private readonly RegisterRequest request = new RegisterRequest();
private string? error;
private bool busy;

[SupplyParameterFromQuery(Name = "returnUrl")]
public string? ReturnUrl { get; set; }

private string LoginUrl =>
string.IsNullOrWhiteSpace(ReturnUrl) ? "login" : $"login?returnUrl={Uri.EscapeDataString(ReturnUrl)}";

private async Task CreateAccount()
{
busy = true;
error = null;

try
{
var result = await auth.Register(request);

if (!result.Succeeded)
{
error = result.Error;
return;
}

navigation.NavigateTo(string.IsNullOrWhiteSpace(ReturnUrl) ? "" : ReturnUrl);
}
finally
{
busy = false;
}
}
}
Loading