| | 1 | | @using Syki.Front.Features.Cross.SetupMfa |
| | 2 | | @using Syki.Front.Features.Cross.GetMfaKey |
| | 3 | |
|
| | 4 | | @namespace Syki.Front.Pages.Cross |
| | 5 | |
|
| | 6 | | @page "/account" |
| | 7 | |
|
| | 8 | | <SykiPageTitle Title="Conta" /> |
| | 9 | |
|
| | 10 | | <MudContainer Class="mt-10 px-4" MaxWidth="MaxWidth.Small"> |
| | 11 | | <MudContainer Class="px-0 mb-4"> |
| | 12 | | <MudGrid Spacing="4"> |
| | 13 | | <MudItem xs="12" sm="12" md="12" lg="12"> |
| | 14 | | <MudStack Row Justify="Justify.Center"> |
| | 15 | | <MudStack Spacing="2"> |
| | 16 | | <style> |
| | 17 | | .mud-badge.mud-badge-icon .mud-icon-badge { |
| | 18 | | font-size: 18px; |
| | 19 | | } |
| | 20 | | </style> |
| | 21 | | <MudFileUpload T="IBrowserFile" OnFilesChanged="@UploadProfilePhoto" MaximumFileCount="1"> |
| | 22 | | <ActivatorContent> |
| | 23 | | <MudBadge Icon="@Icons.Material.Filled.Edit" Color="Color.Primary" Overlap="true" Origin |
| | 24 | | <MudImage ObjectFit="ObjectFit.Cover" Style="border-radius: 50%;" Width="180" Height |
| | 25 | | </MudBadge> |
| | 26 | | </ActivatorContent> |
| | 27 | | </MudFileUpload> |
| 0 | 28 | | <MudText Typo="Typo.h5" Style="font-weight: bold" Class="ml-2">@_data.Name</MudText> |
| 0 | 29 | | <MudText Class="ml-2" Style="margin-top: -8px;">@_data.Role.GetDescription()</MudText> |
| | 30 | | </MudStack> |
| | 31 | | </MudStack> |
| | 32 | | </MudItem> |
| | 33 | | <MudItem xs="12" sm="12" md="12" lg="12"> |
| | 34 | | <InfoCard Icon="@Icons.Material.Filled.Email" Title="Email" Content="@_data.Email" /> |
| | 35 | | </MudItem> |
| 0 | 36 | | @if (_data.Course.HasValue()) |
| | 37 | | { |
| | 38 | | <MudItem xs="12" sm="12" md="12" lg="12"> |
| | 39 | | <InfoCard Icon="@Icons.Material.Filled.Class" Title="Curso" Content="@_data.Course" /> |
| | 40 | | </MudItem> |
| | 41 | | } |
| | 42 | | <MudItem xs="12" sm="12" md="12" lg="12"> |
| | 43 | | <InfoCard Icon="@Icons.Material.Filled.School" Title="Instituição" Content="@_data.Institution" /> |
| | 44 | | </MudItem> |
| | 45 | | </MudGrid> |
| | 46 | | </MudContainer> |
| | 47 | | </MudContainer> |
| | 48 | |
|
| | 49 | | @inject ISnackbar Snackbar |
| | 50 | | @inject GetUserAccountClient GetUserAccountClient |
| | 51 | | @inject IBrowserViewportService BrowserViewportService |
| | 52 | | @inject UpdateUserAccountClient UpdateUserAccountClient |
| | 53 | | @inject CreatePreSignedUrlForUploadClient CreatePreSignedUrlForUploadClient |
| | 54 | |
|
| | 55 | |
|
| | 56 | | @code |
| | 57 | | { |
| 0 | 58 | | private GetUserAccountOut _data = new(); |
| | 59 | |
|
| | 60 | | protected override async Task OnInitializedAsync() |
| | 61 | | { |
| 0 | 62 | | _data = await GetUserAccountClient.Get(); |
| 0 | 63 | | } |
| | 64 | |
|
| 0 | 65 | | private long _maxFileSize = 2 * 1024 * 1024; |
| | 66 | | private async Task UploadProfilePhoto(InputFileChangeEventArgs evt) |
| | 67 | | { |
| 0 | 68 | | if (evt.File.Size > _maxFileSize) |
| | 69 | | { |
| 0 | 70 | | Snackbar.Add("O tamanho máximo permitido é de 2Mb", Severity.Error); |
| 0 | 71 | | return; |
| | 72 | | } |
| | 73 | |
|
| 0 | 74 | | var data = evt.File.OpenReadStream(maxAllowedSize: _maxFileSize); |
| 0 | 75 | | var memoryStream = new MemoryStream(); |
| 0 | 76 | | await data.CopyToAsync(memoryStream); |
| 0 | 77 | | memoryStream.Seek(0, SeekOrigin.Begin); |
| | 78 | |
|
| 0 | 79 | | var randomFileName = $"{Guid.CreateVersion7().ToHashCode().ToString()}.{evt.File.Name.Split(".").Last()}"; |
| 0 | 80 | | var responseUrl = await CreatePreSignedUrlForUploadClient.Create(StorageContainer.ProfilePhotos, randomFileName) |
| 0 | 81 | | var url = responseUrl.IsSuccess ? responseUrl.Success.Url : ""; |
| | 82 | |
|
| 0 | 83 | | using var httpClient = new HttpClient() { BaseAddress = new Uri(url) }; |
| 0 | 84 | | httpClient.DefaultRequestHeaders.Add("x-ms-blob-type", "BlockBlob"); |
| 0 | 85 | | await httpClient.PutAsync("", new StreamContent(memoryStream)); |
| | 86 | |
|
| 0 | 87 | | _data.ProfilePhoto = url.Split("?").First(); |
| | 88 | |
|
| 0 | 89 | | await UpdateUserAccountData(); |
| 0 | 90 | | } |
| | 91 | |
|
| | 92 | | private async Task UpdateUserAccountData() |
| | 93 | | { |
| 0 | 94 | | var response = await UpdateUserAccountClient.Update(_data.Name, _data.ProfilePhoto); |
| 0 | 95 | | if (response.IsSuccess) |
| | 96 | | { |
| 0 | 97 | | await OnInitializedAsync(); |
| 0 | 98 | | Snackbar.Add("Foto atualizada com sucesso!", Severity.Success); |
| | 99 | | } |
| | 100 | | else |
| | 101 | | { |
| 0 | 102 | | var error = response.Error; |
| 0 | 103 | | Snackbar.Add(error.Message, Severity.Error); |
| | 104 | | } |
| 0 | 105 | | } |
| | 106 | | } |