< Summary

Information
Class: Syki.Front.Features.Cross.GetMfaKey.MfaQrCode
Assembly: Front
File(s): /home/runner/work/syki/syki/Front/Features/Cross/GetMfaKey/MfaQrCode.razor
Tag: 22_11348620282
Line coverage
0%
Covered lines: 0
Uncovered lines: 17
Coverable lines: 17
Total lines: 73
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 6
Branch coverage: 0%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
get_AuthState()100%210%
OnInitializedAsync()100%210%
GetUserEmail()0%620%
GetQrCodeImageSrc()0%620%

File(s)

/home/runner/work/syki/syki/Front/Features/Cross/GetMfaKey/MfaQrCode.razor

#LineLine coverage
 1@namespace Syki.Front.Features.Cross.GetMfaKey
 2
 3<MudPaper>
 4    <MudCard Class="px-4 py-0" Elevation="0">
 5        <MudCardContent>
 6            <MudStack AlignItems="AlignItems.Center">
 7                <MudAlert NoIcon="true" Severity="Severity.Info" Variant="Variant.Text">
 8                    <MudStack Row="true" Justify="Justify.SpaceAround">
 9                        <MudText>Utilize o app Google Authenticator para ler o QR-Code</MudText>
 10                    </MudStack>
 11                </MudAlert>
 012                @if (_qrCodeLoading)
 13                {
 14                    <MudContainer MaxWidth="MaxWidth.False" Style="max-width: 380px" Class="px-0 d-flex align-center jus
 15                        <MudProgressCircular Class="py-10" Style="width: 50%; height: 50%" Color="Color.Dark" Indetermin
 16                    </MudContainer>
 17                }
 18                else
 19                {
 20                    <MudContainer MaxWidth="MaxWidth.False" Style="max-width: 380px" Class="px-0">
 21                        <MudImage Src="@(GetQrCodeImageSrc())" Fluid="true" Elevation="25" Class="rounded-lg"/>
 22                    </MudContainer>
 23                    <MudContainer MaxWidth="MaxWidth.False" Style="max-width: 380px" Class="px-0">
 24                        <SykiTextField Value="@_key" CopyAdornment="true" ReadOnly="true" />
 25                    </MudContainer>
 26                }
 27            </MudStack>
 28        </MudCardContent>
 29    </MudCard>
 30</MudPaper>
 31
 32@inject GetMfaKeyClient Client
 33
 34@code
 35{
 36    [CascadingParameter]
 037    public Task<AuthenticationState> AuthState { get; set; }
 38
 39    private string _key;
 40    private bool _qrCodeLoading;
 41    private Byte[] _codeBytes;
 42
 43    protected override async Task OnInitializedAsync()
 44    {
 045        _qrCodeLoading = true;
 46
 047        var result = await Client.Get();
 048        var email = await GetUserEmail();
 049        _key = result.Key;
 050        _codeBytes = _key.GenerateQrCodeBytes(email);
 51
 052        _qrCodeLoading = false;
 053    }
 54
 55    private async Task<string> GetUserEmail()
 56    {
 057        var state = await AuthState;
 58
 059        var claim = state.User.FindFirst("email");
 060        if (claim != null)
 61        {
 062            return claim.Value;
 63        }
 64
 065        return "";
 066    }
 67
 68    private string GetQrCodeImageSrc()
 69    {
 070        if (_codeBytes == null) return "";
 071        return string.Format("data:image/png;base64,{0}", Convert.ToBase64String(_codeBytes));
 72    }
 73}