Correcting bug with GetCurrentUser function

arthur_menu
Arthur VALIN 2 years ago
parent 905db68161
commit 7883166abe

@ -7,7 +7,7 @@
public string UserName { get; set; }
public int NumberOfKeys { get; set; } = 0;
public List<Item> Inventory { get; set; } = new List<Item>();
public List<UserRoles> Roles { get; set; } = new List<UserRoles>() { UserRoles.User };
}
}

@ -25,7 +25,7 @@ namespace CraftSharp.Pages
public IDataService DataService { get; set; }
[Inject]
public IAuthService AuthService { get; set; }
public CustomStateProvider AuthService { get; set; }
[CascadingParameter]
public Task<AuthenticationState> Context { get; set; }
@ -46,7 +46,7 @@ namespace CraftSharp.Pages
items = await DataService.List(0, totalItem);
var authState = await Context;
NumberOfKeys = AuthService.GetCurrentUser(authState.User.Identity.Name).numberOfKeys;
NumberOfKeys = AuthService.GetCurrentUser().NumberOfKeys;
}
bool canOpen()

@ -15,7 +15,7 @@ namespace CraftSharp.Services
new AppUser { UserName = "Admin", Password = "123456", Roles = new List<UserRoles> { UserRoles.Admin }, numberOfKeys=999 }
};
}
public AppUser GetCurrentUser(string userName)
/* public AppUser GetCurrentUser(string userName)
{
var user = CurrentUser.FirstOrDefault(w => w.UserName == userName);
@ -25,7 +25,7 @@ namespace CraftSharp.Services
}
return user;
}
}*/
public CurrentUser GetUser(string userName)
@ -46,6 +46,7 @@ namespace CraftSharp.Services
UserName = user.UserName,
NumberOfKeys = user.numberOfKeys,
Inventory = user.inventory,
Roles = user.Roles,
Claims = claims.ToDictionary(c => c.Type, c => c.Value)
};
}

@ -62,7 +62,7 @@ namespace CraftSharp.Services
NotifyAuthenticationStateChanged(GetAuthenticationStateAsync());
}
private CurrentUser GetCurrentUser()
public CurrentUser GetCurrentUser()
{
if (_currentUser != null && _currentUser.IsAuthenticated)
{

@ -4,8 +4,6 @@ namespace CraftSharp.Services
{
public interface IAuthService
{
AppUser GetCurrentUser(string userName);
CurrentUser GetUser(string userName);
void Login(ConnexionModel loginRequest);

@ -12,9 +12,6 @@ namespace CraftSharp.Shared
[Inject]
public IStringLocalizer<HeaderLayout> Localizer { get; set; }
[Inject]
public IAuthService AuthService { get; set; }
[Inject]
public CustomStateProvider AuthStateProvider { get; set; }
@ -44,18 +41,9 @@ namespace CraftSharp.Shared
async public void isAdmin()
{
var authState = await AuthenticationState;
var roles = AuthService.GetCurrentUser(authState.User.Identity.Name).Roles;
var roles = AuthStateProvider.GetCurrentUser().Roles;
isUserAdmin = roles.Contains(UserRoles.Admin);
}
/* protected override async Task OnParametersSetAsync()
{
if (!(await AuthenticationState).User.Identity.IsAuthenticated)
{
NavigationManager.NavigateTo("/inscription");
}
}*/
private async Task LogoutClick()
{
await AuthStateProvider.Logout();

Loading…
Cancel
Save