Вытащил солюшен на уровень выше, чтобы прощё было дотнетить
	
		
			
	
		
	
	
		
	
		
			Some checks failed
		
		
	
	
		
			
				
	
				continuous-integration/drone/push Build is failing
				
			
		
		
	
	
				
					
				
			
		
			Some checks failed
		
		
	
	continuous-integration/drone/push Build is failing
				
			This commit is contained in:
		| @@ -0,0 +1,8 @@ | ||||
| namespace BlazorWebAssemblyVisaApiClient.Infrastructure.Services.DateTimeProvider; | ||||
|  | ||||
| public class DateTimeProvider : IDateTimeProvider | ||||
| { | ||||
|     public DateTime Now() => DateTime.Now; | ||||
|  | ||||
|     public string FormattedNow() => Now().ToString("yyyy-MM-dd"); | ||||
| } | ||||
| @@ -0,0 +1,8 @@ | ||||
| namespace BlazorWebAssemblyVisaApiClient.Infrastructure.Services.DateTimeProvider; | ||||
|  | ||||
| public interface IDateTimeProvider | ||||
| { | ||||
|     DateTime Now(); | ||||
|  | ||||
|     string FormattedNow(); | ||||
| } | ||||
| @@ -0,0 +1,5 @@ | ||||
| using BlazorWebAssemblyVisaApiClient.Common.Exceptions; | ||||
|  | ||||
| namespace BlazorWebAssemblyVisaApiClient.Infrastructure.Services.UserDataProvider.Exceptions; | ||||
|  | ||||
| public class UnknownRoleException() : BlazorClientException("Unknown user role"); | ||||
| @@ -0,0 +1,14 @@ | ||||
| using VisaApiClient; | ||||
|  | ||||
| namespace BlazorWebAssemblyVisaApiClient.Infrastructure.Services.UserDataProvider; | ||||
|  | ||||
| public interface IUserDataProvider | ||||
| { | ||||
|     public string? CurrentRole { get; } | ||||
|  | ||||
|     public Action? OnRoleChanged { get; set; } | ||||
|  | ||||
|     public Task<ApplicantModel> GetApplicant(); | ||||
|  | ||||
|     public void UpdateCurrentRole(); | ||||
| } | ||||
| @@ -0,0 +1,52 @@ | ||||
| using System.IdentityModel.Tokens.Jwt; | ||||
| using System.Security.Claims; | ||||
| using BlazorWebAssemblyVisaApiClient.Infrastructure.Services.UserDataProvider.Exceptions; | ||||
| using VisaApiClient; | ||||
|  | ||||
| namespace BlazorWebAssemblyVisaApiClient.Infrastructure.Services.UserDataProvider; | ||||
|  | ||||
| public class UserDataProvider(IClient client) : IUserDataProvider | ||||
| { | ||||
|     private readonly static JwtSecurityTokenHandler tokenHandler = new(); | ||||
|  | ||||
|     public string? CurrentRole { get; private set; } | ||||
|  | ||||
|     public Action? OnRoleChanged { get; set; } | ||||
|  | ||||
|     public async Task<ApplicantModel> GetApplicant() | ||||
|     { | ||||
|             return await client.GetApplicantAsync(); | ||||
|         } | ||||
|  | ||||
|     public void UpdateCurrentRole() | ||||
|     { | ||||
|             var role = CurrentRole; | ||||
|  | ||||
|             if (client.AuthToken is null) | ||||
|             { | ||||
|                 if (CurrentRole is not null) | ||||
|                 { | ||||
|                     role = null; | ||||
|                 } | ||||
|             } | ||||
|             else | ||||
|             { | ||||
|                 var token = tokenHandler.ReadJwtToken(client.AuthToken.Token); | ||||
|                 role = token.Claims.FirstOrDefault(claim => claim.Type == ClaimTypes.Role)?.Value; | ||||
|  | ||||
|                 switch (role) | ||||
|                 { | ||||
|                     case Constants.ApplicantRole: break; | ||||
|                     case Constants.ApprovingAuthorityRole: break; | ||||
|                     case Constants.AdminRole: break; | ||||
|                     default: throw new UnknownRoleException(); | ||||
|                 } | ||||
|             } | ||||
|  | ||||
|             if (CurrentRole != role) | ||||
|             { | ||||
|                 CurrentRole = role; | ||||
|                 OnRoleChanged?.Invoke(); | ||||
|             } | ||||
|         } | ||||
| } | ||||
		Reference in New Issue
	
	Block a user