list of authorities, changing authority auth data
This commit is contained in:
		| @@ -1,4 +1,5 @@ | ||||
| @page "/applications/{ApplicationId}" | ||||
| @using System.Net | ||||
| @using BlazorWebAssemblyVisaApiClient.Common.Exceptions | ||||
| @using BlazorWebAssemblyVisaApiClient.Components | ||||
| @using BlazorWebAssemblyVisaApiClient.Infrastructure.Helpers | ||||
| @@ -210,6 +211,11 @@ | ||||
|         } | ||||
|         catch (Exception e) | ||||
|         { | ||||
|  | ||||
|             if (e is ApiException<ProblemDetails> { Result.Status: (int)HttpStatusCode.Conflict }) | ||||
|             { | ||||
|                 Nav.NavigateTo("/applications"); | ||||
|             } | ||||
|             ErrorHandler.Handle(e); | ||||
|         } | ||||
|     } | ||||
|   | ||||
| @@ -0,0 +1,42 @@ | ||||
| @page "/authorities" | ||||
| @using VisaApiClient | ||||
| @inherits BlazorWebAssemblyVisaApiClient.Components.Base.VisaClientComponentBase | ||||
|  | ||||
| <table class="table table-bordered table-hover"> | ||||
|     <thead> | ||||
|     <tr> | ||||
|         <th>Email</th><th></th> | ||||
|     </tr> | ||||
|     </thead> | ||||
|     <tbody> | ||||
|     @foreach (var authority in authorities) | ||||
|     { | ||||
|         var path = $"authorities/{authority.Id}/{authority.Email}"; | ||||
|         <tr> | ||||
|             <td>@authority.Email</td> | ||||
|             <td> | ||||
|                 <NavLink href="@path"> | ||||
|                     <button class="btn-outline-primary">Change</button> | ||||
|                 </NavLink> | ||||
|             </td> | ||||
|         </tr> | ||||
|     } | ||||
|     </tbody> | ||||
| </table> | ||||
|  | ||||
| @code { | ||||
|     private IEnumerable<UserModel> authorities = []; | ||||
|  | ||||
|     protected override async Task OnInitializedAsync() | ||||
|     { | ||||
|         try | ||||
|         { | ||||
|             authorities = await Client.GetAuthorityAccountsAsync(); | ||||
|         } | ||||
|         catch (Exception e) | ||||
|         { | ||||
|             ErrorHandler.Handle(e); | ||||
|         } | ||||
|     } | ||||
|  | ||||
| } | ||||
| @@ -0,0 +1,83 @@ | ||||
| @page "/authorities/{authorityId}/{oldEmail}" | ||||
| @inherits BlazorWebAssemblyVisaApiClient.Components.Base.VisaClientComponentBase | ||||
| @using BlazorWebAssemblyVisaApiClient.Common.Exceptions | ||||
| @using BlazorWebAssemblyVisaApiClient.Infrastructure.Services.UserDataProvider | ||||
| @using VisaApiClient | ||||
| @using BlazorWebAssemblyVisaApiClient.Components | ||||
| @using BlazorWebAssemblyVisaApiClient.Infrastructure.Helpers | ||||
| @using FluentValidation | ||||
|  | ||||
| <EditForm Model="model" class="with-centered-content"> | ||||
|     <div > | ||||
|         <label> | ||||
|             New email:<br/> | ||||
|             <InputText class="rounded" @bind-Value="model.Email"/> | ||||
|         </label><br/><p/> | ||||
|  | ||||
|         <label> | ||||
|             New password (leave blank if shouldn't be changed):<br/> | ||||
|             <InputText class="rounded" @bind-Value="model.Password"/> | ||||
|         </label><br/><p/> | ||||
|  | ||||
|         <button class="btn-primary rounded" @onclick="Save">Save</button><br/> | ||||
|         <Status @ref="status"/> | ||||
|     </div> | ||||
| </EditForm> | ||||
|  | ||||
| @code | ||||
| { | ||||
|     private Status status = null!; | ||||
|     private ChangeAuthData model = new(); | ||||
|  | ||||
|     [Parameter] public string AuthorityId { get; set; } = null!; | ||||
|  | ||||
|     [Parameter] public string OldEmail { get; set; } = null!; | ||||
|  | ||||
|     [Inject] private IUserDataProvider UserDataProvider { get; set; } = null!; | ||||
|  | ||||
|     [Inject] private IValidator<ChangeUserAuthDataRequest> ChangeUserAuthDataRequestValidator { get; set; } = null!; | ||||
|  | ||||
|     protected override void OnInitialized() | ||||
|     { | ||||
|         try | ||||
|         { | ||||
|             if (UserDataProvider.CurrentRole is not Constants.AdminRole) | ||||
|             { | ||||
|                 throw new NotLoggedInException(); | ||||
|             } | ||||
|  | ||||
|             model.Email = OldEmail; | ||||
|         } | ||||
|         catch (Exception e) | ||||
|         { | ||||
|             ErrorHandler.Handle(e); | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     private async Task Save() | ||||
|     { | ||||
|         var request = new ChangeUserAuthDataRequest | ||||
|         { | ||||
|             UserId = Guid.Parse(AuthorityId), | ||||
|             NewAuthData = model | ||||
|         }; | ||||
|  | ||||
|         var validationResult = await ChangeUserAuthDataRequestValidator.ValidateAsync(request); | ||||
|         if (!validationResult.IsValid) | ||||
|         { | ||||
|             status.SetError(validationResult.ToErrorsString()); | ||||
|             return; | ||||
|         } | ||||
|  | ||||
|         try | ||||
|         { | ||||
|             status.SetMessage("Wait..."); | ||||
|             await Client.ChangeAuthorityAuthDataAsync(request); | ||||
|             status.SetSuccess("Success"); | ||||
|         } | ||||
|         catch (Exception e) | ||||
|         { | ||||
|             ErrorHandler.Handle(e); | ||||
|         } | ||||
|     } | ||||
| } | ||||
| @@ -102,7 +102,7 @@ | ||||
|             </label><br/> | ||||
|             <ValidationMessage For="() => editableVisa.ExpirationDate"></ValidationMessage><br/> | ||||
|  | ||||
|             <input type="button" class="btn-outline-primary" | ||||
|             <input type="button" class="btn-outline-primary rounded" | ||||
|                    disabled="@(requestModel.PastVisas.Count == ConfigurationConstraints.MaxPastVisas)" | ||||
|                    @onclick="AddPastVisa" value="Add"/> | ||||
|             <Status @ref="pastVisaStatus"/> | ||||
| @@ -157,7 +157,7 @@ | ||||
|             </label><br/> | ||||
|             <ValidationMessage For="() => editableVisit.EndDate"></ValidationMessage><br/> | ||||
|  | ||||
|             <input type="button" class="btn-outline-primary" | ||||
|             <input type="button" class="btn-outline-primary rounded" | ||||
|                    disabled="@(requestModel.PastVisits.Count == ConfigurationConstraints.MaxPastVisits)" | ||||
|                    @onclick="AddPastVisit" value="Add"/> | ||||
|             <Status @ref="pastVisitStatus"/> | ||||
| @@ -185,7 +185,7 @@ | ||||
|             </div> | ||||
|         } | ||||
|  | ||||
|         <br/><input type="submit" class="btn-outline-primary" value="Register"/> | ||||
|         <br/><input type="submit" class="btn-outline-primary rounded" value="Register"/> | ||||
|         <ValidationSummary/> | ||||
|         <Status @ref="status"/> | ||||
|     </EditForm> | ||||
|   | ||||
		Reference in New Issue
	
	Block a user