@using BlazorAnimation @using TIAM.Core.Enums @using TIAM.Entities.Transfers @using TIAM.Entities.Users @using TIAM.Models.Dtos.Users @using TIAM.Services @using TIAMSharedUI.Shared.Components.Cards @using TIAMWebApp.Shared.Application.Interfaces @using TIAMWebApp.Shared.Application.Models.ClientSide.UI @using TIAMWebApp.Shared.Application.Models.PageModels @using TIAMWebApp.Shared.Application.Services @inject IServiceProviderDataService ServiceProviderDataService @inject IUserDataService UserDataService; @inject AdminSignalRClient AdminSignalRClient;
@{ if(!IsForgotten) {
@($"{Context.UserDto.Id}")

@Context.UserDto.EmailAddress

@Context.UserDto.PhoneNumber


} }
@RenderDetailsItem("fa-solid fa-key", "Password", Context.UserDto.Password)
@{ if(!IsForgotten) { } }
Save

@msg

@code { [Parameter] public UserModelDtoDetail Context { get; set; } [Parameter] public EventCallback DataChanged { get; set; } [Parameter] public bool IsForgotten { get; set; } = false; private bool PasswordNotSet = true; private bool PasswordNotConfirmed = true; private string _newPassword; public string NewPassword { get => _newPassword; set { if (_newPassword == value) return; _newPassword = value; OnPasswordSet(value); } } public string OldPassword { get; set; } private string? _confirmNewPassword; public string? ConfirmNewPassword { get => _confirmNewPassword; set { if (value == null || _confirmNewPassword == value) return; _confirmNewPassword = value; OnPasswordConfirmed(value); } } string msg; private bool isSaveActive = false; void OnPasswordSet(string password) { msg = $"Password to set: {NewPassword}"; PasswordNotSet = false; StateHasChanged(); } void OnPasswordConfirmed(string password) { if (NewPassword == ConfirmNewPassword) { PasswordNotConfirmed = false; isSaveActive = true; } else { isSaveActive = false; msg = "Password and confirmation not matching!"; } } protected async Task SetPassword() { bool isSuccess; isSaveActive = false; if (IsForgotten) { var forgotPasswordDto = new ForgotPasswordDto(Context.UserDto.EmailAddress, NewPassword); isSuccess = await AdminSignalRClient.PostDataAsync(SignalRTags.UserForgotPassword, forgotPasswordDto) != null; } else { var changePasswordDto = new ChangePasswordDto(Context.Id, OldPassword, NewPassword); isSuccess = await AdminSignalRClient.PostDataAsync(SignalRTags.UserChangePassword, changePasswordDto) != null; } msg = isSuccess ? $"Password saved" : "Some error occured during saving, please try again later"; StateHasChanged(); await DataChanged.InvokeAsync(isSuccess); } protected override async Task OnInitializedAsync() { await base.OnInitializedAsync(); } protected override async Task OnParametersSetAsync() { await base.OnParametersSetAsync(); } RenderFragment RenderDetailsItem(string iconCssClass, string caption, string value) { return @
@value
; } }