Skip to content

Commit

Permalink
Merge pull request #6 from Lan2Play/feature/AuthRework
Browse files Browse the repository at this point in the history
Rework auth
  • Loading branch information
MD-V authored Apr 21, 2022
2 parents 40499e7 + 21eea00 commit 5f4da42
Show file tree
Hide file tree
Showing 93 changed files with 716 additions and 2,333 deletions.
23 changes: 0 additions & 23 deletions NetEvent/Client/Models/User.cs

This file was deleted.

4 changes: 0 additions & 4 deletions NetEvent/Client/NetEvent.Client.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,4 @@
<ServiceWorker Include="wwwroot\service-worker.js" PublishedContent="wwwroot\service-worker.published.js" />
</ItemGroup>

<ItemGroup>
<Folder Include="Models\" />
</ItemGroup>

</Project>
6 changes: 3 additions & 3 deletions NetEvent/Client/Pages/Administration/Index.razor.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using Microsoft.AspNetCore.Components;
using NetEvent.Shared.Models;
using NetEvent.Shared.Dto;

namespace NetEvent.Client.Pages.Administration
{
Expand All @@ -9,11 +9,11 @@ public partial class Index
[Inject]
public HttpClient HttpClient { get; set; }

public List<ApplicationUser>? Users { get; private set; }
public List<CurrentUser>? Users { get; private set; }

protected override async Task OnInitializedAsync()
{
Users = await Utils.Get<List<ApplicationUser>>(HttpClient, "users");
Users = await Utils.Get<List<CurrentUser>>(HttpClient, "users");
}

}
Expand Down
2 changes: 1 addition & 1 deletion NetEvent/Client/Pages/Administration/Settings.razor
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
@page "/administration/settings"
@using Microsoft.AspNetCore.Authorization
@using NetEvent.Shared.Models;


@attribute [Authorize(Roles = "Admin")]

Expand Down
17 changes: 0 additions & 17 deletions NetEvent/Client/Pages/Administration/Settings.razor.cs
Original file line number Diff line number Diff line change
@@ -1,21 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Components;
using System.Net.Http;
using System.Net.Http.Json;
using Microsoft.AspNetCore.Components.Authorization;
using Microsoft.AspNetCore.Components.Forms;
using Microsoft.AspNetCore.Components.Routing;
using Microsoft.AspNetCore.Components.Web;
using Microsoft.AspNetCore.Components.Web.Virtualization;
using Microsoft.AspNetCore.Components.WebAssembly.Http;
using Microsoft.JSInterop;
using NetEvent.Client;
using NetEvent.Client.Shared;
using MudBlazor;
using NetEvent.Shared.Models;

namespace NetEvent.Client.Pages.Administration
{
Expand Down
21 changes: 11 additions & 10 deletions NetEvent/Client/Pages/Administration/Users.razor
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
@page "/administration/users"
@using Microsoft.AspNetCore.Authorization
@using Microsoft.AspNetCore.Identity
@using NetEvent.Shared.Models;
@using NetEvent.Shared.Dto


@attribute [Authorize(Roles = "Admin")]

<MudTabs Elevation="1" Rounded="true">
<MudTabPanel Text="User">
<MudDataGrid T="ApplicationUser"
<MudDataGrid T="CurrentUser"
MultiSelection="false"
Items="@AllUsers"
Sortable="true"
Expand All @@ -26,27 +27,27 @@
</ToolBarContent>
<Columns>
@*<SelectColumn T="ApplicationUser" />*@
<Column T="ApplicationUser" Field="UserName" Title="Username" />
<Column T="ApplicationUser" Field="FirstName" />
<Column T="ApplicationUser" Field="LastName" />
<Column T="ApplicationUser" Field="Email" />
<Column T="ApplicationUser" Field="PhoneNumber" Title="Molar mass" />
<Column T="ApplicationUser" Field="EmailConfirmed">
<Column T="CurrentUser" Field="UserName" Title="Username" />
<Column T="CurrentUser" Field="FirstName" />
<Column T="CurrentUser" Field="LastName" />
<Column T="CurrentUser" Field="Email" />
<Column T="CurrentUser" Field="PhoneNumber" Title="Molar mass" />
<Column T="CurrentUser" Field="EmailConfirmed">
<CellTemplate>
<MudCheckBox Checked="@context.Item.EmailConfirmed" ReadOnly="true" />
</CellTemplate>
<EditTemplate>
<MudCheckBox @bind-Checked="@context.Item.EmailConfirmed" Label="Email confirmed" />
</EditTemplate>
</Column>
<Column T="ApplicationUser" CellClass="d-flex justify-end">
<Column T="CurrentUser" CellClass="d-flex justify-end">
<CellTemplate>
<MudIconButton Size="@Size.Small" Icon="@Icons.Outlined.Edit" OnClick="@context.Actions.StartEditingItem" />
</CellTemplate>
</Column>
</Columns>
<PagerContent>
<MudDataGridPager T="ApplicationUser" />
<MudDataGridPager T="CurrentUser" />
</PagerContent>
</MudDataGrid>
</MudTabPanel>
Expand Down
26 changes: 5 additions & 21 deletions NetEvent/Client/Pages/Administration/Users.razor.cs
Original file line number Diff line number Diff line change
@@ -1,22 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Components;
using System.Net.Http;
using System.Net.Http.Json;
using Microsoft.AspNetCore.Components.Authorization;
using Microsoft.AspNetCore.Components.Forms;
using Microsoft.AspNetCore.Components.Routing;
using Microsoft.AspNetCore.Components.Web;
using Microsoft.AspNetCore.Components.Web.Virtualization;
using Microsoft.AspNetCore.Components.WebAssembly.Http;
using Microsoft.JSInterop;
using NetEvent.Client;
using NetEvent.Client.Shared;
using MudBlazor;
using NetEvent.Shared.Models;
using Microsoft.AspNetCore.Identity;
using NetEvent.Shared.Dto;

namespace NetEvent.Client.Pages.Administration
{
Expand All @@ -29,17 +13,17 @@ public partial class Users

protected override async Task OnInitializedAsync()
{
AllUsers = await Utils.Get<List<ApplicationUser>>(HttpClient, "users");
AllUsers = await Utils.Get<List<CurrentUser>>(HttpClient, "users");
AllRoles = await Utils.Get<List<IdentityRole>>(HttpClient, "roles");
}

#region Users

public List<ApplicationUser>? AllUsers { get; private set; }
public List<CurrentUser>? AllUsers { get; private set; }
private string _usersSearchString;

// quick filter - filter gobally across multiple columns with the same input
private Func<ApplicationUser, bool> _usersQuickFilter => x =>
private Func<CurrentUser, bool> _usersQuickFilter => x =>
{
if (string.IsNullOrWhiteSpace(_usersSearchString))
return true;
Expand All @@ -60,7 +44,7 @@ protected override async Task OnInitializedAsync()
};


void CommittedUserChanges(ApplicationUser item)
void CommittedUserChanges(CurrentUser item)
{
_ = Utils.Put(HttpClient, $"users/{item.Id}", item);
}
Expand Down
7 changes: 0 additions & 7 deletions NetEvent/Client/Pages/Authentication.razor

This file was deleted.

2 changes: 0 additions & 2 deletions NetEvent/Client/Pages/Index.razor
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,3 @@
<h1>Hello, world!</h1>

Welcome to your new app.

<SurveyPrompt Title="How is Blazor working for you?" />
17 changes: 17 additions & 0 deletions NetEvent/Client/Pages/Login.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
@page "/login"

<h3>Login</h3>

<EditForm Model="LoginRequest" OnValidSubmit="ExecuteLogin">
<DataAnnotationsValidator />
<MudCard >
<MudCardContent>
<MudTextField id="Input.Email" Label="Email" @bind-Value="LoginRequest.UserName" For="@(() => LoginRequest.UserName)" />
<MudTextField id="Input.Password" Label="Password" @bind-Value="LoginRequest.Password" For="@(() => LoginRequest.Password)" InputType="InputType.Password" />
<MudCheckBox id="Input.Remember" Label="Remember Me" @bind-Checked="LoginRequest.RememberMe" />
</MudCardContent>
<MudCardActions>
<MudButton ButtonType="ButtonType.Submit" Variant="Variant.Outlined" Color="Color.Primary" Class="ma-2 py-2">Login</MudButton>
</MudCardActions>
</MudCard>
</EditForm>
43 changes: 43 additions & 0 deletions NetEvent/Client/Pages/Login.razor.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
using Microsoft.AspNetCore.Components;
using NetEvent.Client.Services;
using NetEvent.Shared.Dto;

namespace NetEvent.Client.Pages
{
public partial class Login
{
[Inject]
public CustomStateProvider AuthenticationStateProvider { get; set; }

[Inject]
public NavigationManager NavigationManager { get; set; }


public LoginRequest LoginRequest { get; set; } = new ();


public string Error { get; set; }


protected override async Task OnAfterRenderAsync(bool firstRender)
{
if (firstRender)
{

}
}

public async Task ExecuteLogin()
{
try
{
await AuthenticationStateProvider.Login(LoginRequest);
NavigationManager.NavigateTo("");
}
catch (Exception ex)
{
Error = ex.Message;
}
}
}
}
47 changes: 0 additions & 47 deletions NetEvent/Client/Pages/Profile/Manage.razor

This file was deleted.

36 changes: 0 additions & 36 deletions NetEvent/Client/Pages/Profile/Manage.razor.cs

This file was deleted.

Loading

0 comments on commit 5f4da42

Please sign in to comment.