From 23a959a026a3ec14e8ceddb8193f8ded3cb4e0ab Mon Sep 17 00:00:00 2001 From: krystian kempski Date: Tue, 12 Mar 2024 21:31:17 +0100 Subject: [PATCH] Adding MG role functions and characters asigned to users --- .../CharacterReps/CharacterRepository.cs | 6 ++++ .../IRepository/ICharacterRepository.cs | 1 + .../Identity/Pages/Account/Register.cshtml | 31 +------------------ .../Identity/Pages/Account/Register.cshtml.cs | 2 +- DagoniteEmpire/DagoniteEmpire.csproj | 1 + .../Pages/CharacterPages/CharacterList.razor | 31 ++++++++++++++++--- .../CharacterPages/CharacterList.razor.css | 1 + .../CharacterPages/CharacterUpsert.razor | 2 +- DagoniteEmpire/Pages/Index.razor | 4 +-- DagoniteEmpire/Pages/Index.razor.css | 8 +++-- 10 files changed, 46 insertions(+), 41 deletions(-) diff --git a/DA_Business/Repository/CharacterReps/CharacterRepository.cs b/DA_Business/Repository/CharacterReps/CharacterRepository.cs index 8955091..8707df9 100644 --- a/DA_Business/Repository/CharacterReps/CharacterRepository.cs +++ b/DA_Business/Repository/CharacterReps/CharacterRepository.cs @@ -59,6 +59,12 @@ public async Task GetById(int id) } return new CharacterDTO(); } + public async Task> GetAllForUser(string userName) + { + if (userName == null || userName.Length<3) + return null; + return _mapper.Map, IEnumerable>(_db.Characters.Where(u => u.UserName == userName)); + } public async Task Update(CharacterDTO objDTO) { diff --git a/DA_Business/Repository/CharacterReps/IRepository/ICharacterRepository.cs b/DA_Business/Repository/CharacterReps/IRepository/ICharacterRepository.cs index ece5ba0..6f5d60a 100644 --- a/DA_Business/Repository/CharacterReps/IRepository/ICharacterRepository.cs +++ b/DA_Business/Repository/CharacterReps/IRepository/ICharacterRepository.cs @@ -16,5 +16,6 @@ public interface ICharacterRepository public Task GetById(int id); public Task> GetAll(int? id=null); + public Task> GetAllForUser(string userName); } } diff --git a/DagoniteEmpire/Areas/Identity/Pages/Account/Register.cshtml b/DagoniteEmpire/Areas/Identity/Pages/Account/Register.cshtml index d07dfea..a34e66c 100644 --- a/DagoniteEmpire/Areas/Identity/Pages/Account/Register.cshtml +++ b/DagoniteEmpire/Areas/Identity/Pages/Account/Register.cshtml @@ -45,36 +45,7 @@ - @*
-
-

Use another service to register.

-
- @{ - if ((Model.ExternalLogins?.Count ?? 0) == 0) - { -
-

- There are no external authentication services configured. See this article - about setting up this ASP.NET application to support logging in via external services. -

-
- } - else - { -
-
-

- @foreach (var provider in Model.ExternalLogins!) - { - - } -

-
-
- } - } -
-
*@ + @section Scripts { diff --git a/DagoniteEmpire/Areas/Identity/Pages/Account/Register.cshtml.cs b/DagoniteEmpire/Areas/Identity/Pages/Account/Register.cshtml.cs index ef836be..1ea86f6 100644 --- a/DagoniteEmpire/Areas/Identity/Pages/Account/Register.cshtml.cs +++ b/DagoniteEmpire/Areas/Identity/Pages/Account/Register.cshtml.cs @@ -130,7 +130,7 @@ public async Task OnPostAsync(string returnUrl = null) { var user = CreateUser(); - await _userStore.SetUserNameAsync(user, Input.Email, CancellationToken.None); + await _userStore.SetUserNameAsync(user, Input.UserName, CancellationToken.None); await _emailStore.SetEmailAsync(user, Input.Email, CancellationToken.None); var result = await _userManager.CreateAsync(user, Input.Password); diff --git a/DagoniteEmpire/DagoniteEmpire.csproj b/DagoniteEmpire/DagoniteEmpire.csproj index b02e1e7..9fd5597 100644 --- a/DagoniteEmpire/DagoniteEmpire.csproj +++ b/DagoniteEmpire/DagoniteEmpire.csproj @@ -39,6 +39,7 @@ + diff --git a/DagoniteEmpire/Pages/CharacterPages/CharacterList.razor b/DagoniteEmpire/Pages/CharacterPages/CharacterList.razor index 991b586..fcdaac8 100644 --- a/DagoniteEmpire/Pages/CharacterPages/CharacterList.razor +++ b/DagoniteEmpire/Pages/CharacterPages/CharacterList.razor @@ -2,6 +2,7 @@ @using Syncfusion.Blazor.Navigations; @inject ICharacterRepository _characterRepository @inject ISpecialSkillRepository _specialSkillRepository +@inject AuthenticationStateProvider GetAuthenticationStateAsync @inject NavigationManager _navigationManager @inject IJSRuntime _jsRuntime @attribute [Authorize(Roles = SD.Role_Admin + "," + SD.Role_HeroPlayer + "," + SD.Role_DukePlayer + "," + SD.Role_GameMaster)] @@ -9,7 +10,7 @@
-

User Characters List

+

@Title

@@ -19,10 +20,13 @@ + @if (IsAdminOrMG){ + + } - - - + + + @if (Characters.Any()) @@ -48,7 +52,9 @@ @code { private IEnumerable Characters { get; set; } = new List(); public bool IsLoading { get; set; } + public bool IsAdminOrMG { get; set; } = true; private int DeleteCharacterId { get; set; } = 0; + private string Title { get; set; } = "Your characters"; // [CascadingParameter] // public Task AuthenticationState { get; set; } @@ -80,7 +86,22 @@ { IsLoading = true; StateHasChanged(); - Characters = await _characterRepository.GetAll(); + var authstate = await GetAuthenticationStateAsync.GetAuthenticationStateAsync(); + var user = authstate.User; + Title = "Characters of " + user.Identity.Name; + if (user == null) + return; // failed to load + + IsAdminOrMG = user.IsInRole(SD.Role_Admin) || user.IsInRole(SD.Role_GameMaster); + + if (IsAdminOrMG) + { + Characters = await _characterRepository.GetAll(); + } + else + { + Characters = await _characterRepository.GetAllForUser(user.Identity.Name); + } IsLoading = false; StateHasChanged(); } diff --git a/DagoniteEmpire/Pages/CharacterPages/CharacterList.razor.css b/DagoniteEmpire/Pages/CharacterPages/CharacterList.razor.css index 71b3b54..963ee3a 100644 --- a/DagoniteEmpire/Pages/CharacterPages/CharacterList.razor.css +++ b/DagoniteEmpire/Pages/CharacterPages/CharacterList.razor.css @@ -6,4 +6,5 @@ .card-title{ color: black; + padding-left:8px; } diff --git a/DagoniteEmpire/Pages/CharacterPages/CharacterUpsert.razor b/DagoniteEmpire/Pages/CharacterPages/CharacterUpsert.razor index 1c691e8..81ac3cf 100644 --- a/DagoniteEmpire/Pages/CharacterPages/CharacterUpsert.razor +++ b/DagoniteEmpire/Pages/CharacterPages/CharacterUpsert.razor @@ -11,7 +11,7 @@ @using DA_Models @using DagoniteEmpire.Service.IService @using DagoniteEmpire.Pages.Components -@attribute [Authorize(Roles = SD.Role_Admin + "," + SD.Role_HeroPlayer + "," + SD.Role_DukePlayer)] +@attribute [Authorize(Roles = SD.Role_Admin + "," + SD.Role_HeroPlayer + "," + SD.Role_DukePlayer + "," + SD.Role_GameMaster)] @inject NavigationManager _navigationManager <_LeavePage IsParentComponentProcessing=IsLoading LeaveConfirmation="ConfirmLeave_Click" > diff --git a/DagoniteEmpire/Pages/Index.razor b/DagoniteEmpire/Pages/Index.razor index 5494bff..894dd8c 100644 --- a/DagoniteEmpire/Pages/Index.razor +++ b/DagoniteEmpire/Pages/Index.razor @@ -3,8 +3,8 @@ Dagonite Empire
-
-

Welcome to Dagonite Empire!

+
+

Welcome to Dagonite Empire!

diff --git a/DagoniteEmpire/Pages/Index.razor.css b/DagoniteEmpire/Pages/Index.razor.css index 3d3d682..b03607b 100644 --- a/DagoniteEmpire/Pages/Index.razor.css +++ b/DagoniteEmpire/Pages/Index.razor.css @@ -11,11 +11,12 @@ h1 { font-family: 'Eagle Lake', serif; + text-shadow: 8px 8px 6px black; } .hero-img { position: relative; - height: 100vh; + height: calc(100vh - 62px); background-image: url('../images/EastMarchy_header.webp'); background-size: cover; background-position: center; @@ -27,10 +28,13 @@ h1 { } .blue-text { - color: darkgoldenrod; + color: darkgoldenrod;/* + text-shadow: 5px 5px 20px rgb(0, 0, 0);*/ } +.text{ +} .hero-shadow { position: absolute;