started applications page

This commit is contained in:
2024-09-05 22:31:13 +03:00
parent 24881ae1db
commit 80e15e88f5
11 changed files with 93 additions and 11 deletions

View File

@@ -1,11 +1,16 @@
@using System.Net
@using System.IdentityModel.Tokens.Jwt
@using System.Security.Claims
@using BlazorWebAssemblyVisaApiClient.Components.Auth.Exceptions
@using BlazorWebAssemblyVisaApiClient.ErrorHandling
@using VisaApiClient
@code {
public static bool LoggedIn;
public static ApplicantModel? CurrentApplicant; //todo api action
public static string? CurrentRole;
private static AuthData savedData = null!;
private static readonly JwtSecurityTokenHandler TokenHandler = new();
[CascadingParameter] private GlobalErrorHandler ErrorHandler { get; set; } = null!;
@@ -24,6 +29,10 @@
{
var token = await Client.LoginAsync(authData.Email, authData.Password);
Client.SetAuthToken(token);
CurrentRole = TokenHandler.ReadJwtToken(token.Token)
.Claims
.FirstOrDefault(claim => claim.Type == ClaimTypes.Role)?
.Value;
savedData = authData;
Status?.SetSucces("Logged in successfully.");

View File

@@ -1,6 +1,6 @@
@using System.ComponentModel.DataAnnotations
@using System.Linq.Expressions
@using System.Linq.Expressions
@using System.Reflection
@using BlazorWebAssemblyVisaApiClient.Infrastructure.Helpers
@typeparam TItem where TItem : class
@typeparam TMember where TMember : struct, Enum
@@ -22,18 +22,12 @@
protected override void OnInitialized()
{
var enumMembers = typeof(TMember).GetMembers();
var modelMemberName = ((MemberExpression)EnumProperty.Body).Member.Name;
modelMemberInfo = typeof(TItem).GetProperty(modelMemberName)!;
foreach (var value in Enum.GetValues<TMember>())
{
var member = enumMembers.First(info => info.Name == value.ToString());
var displayAttribute = (DisplayAttribute?)member
.GetCustomAttributes(typeof(DisplayAttribute), false)
.FirstOrDefault();
var displayName = displayAttribute?.Name ?? value.ToString();
enumValues.Add(value, displayName);
enumValues.Add(value, value.GetDisplayName());
}
}

View File

@@ -1,4 +1,5 @@
@using BlazorWebAssemblyVisaApiClient.Infrastructure.Services
@using BlazorWebAssemblyVisaApiClient.Infrastructure.Services.DateTimeProvider
@using VisaApiClient
<div>