< Summary

Information
Class: OzonOrdersWeb.Areas.Identity.Pages.Account.ConfirmEmailModel
Assembly: OzonOrdersWeb
File(s): /home/runner/work/Studio2Prod/Studio2Prod/OzonOrdersWeb/Areas/Identity/Pages/Account/ConfirmEmail.cshtml.cs
Line coverage
0%
Covered lines: 0
Uncovered lines: 18
Coverable lines: 18
Total lines: 52
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 10
Branch coverage: 0%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%210%
get_StatusMessage()100%210%
OnGetAsync()0%110100%

File(s)

/home/runner/work/Studio2Prod/Studio2Prod/OzonOrdersWeb/Areas/Identity/Pages/Account/ConfirmEmail.cshtml.cs

#LineLine coverage
 1// Licensed to the .NET Foundation under one or more agreements.
 2// The .NET Foundation licenses this file to you under the MIT license.
 3#nullable disable
 4
 5using System.Text;
 6using Microsoft.AspNetCore.Identity;
 7using Microsoft.AspNetCore.Mvc;
 8using Microsoft.AspNetCore.Mvc.RazorPages;
 9using Microsoft.AspNetCore.WebUtilities;
 10using OzonRepositories.Context.Identity;
 11
 12namespace OzonOrdersWeb.Areas.Identity.Pages.Account;
 13
 14public class ConfirmEmailModel : PageModel
 15{
 16    private readonly UserManager<CustomIdentityUser> _userManager;
 17
 018    public ConfirmEmailModel(UserManager<CustomIdentityUser> userManager)
 19    {
 020        _userManager = userManager;
 021    }
 22
 23    [TempData]
 024    public string StatusMessage { get; set; }
 25
 26    public async Task<IActionResult> OnGetAsync(string userId, string code, string returnUrl = null)
 27    {
 028        if (userId == null || code == null)
 29        {
 030            return RedirectToPage("/Index");
 31        }
 32
 033        var user = await _userManager.FindByIdAsync(userId);
 034        if (user == null)
 35        {
 036            return NotFound($"Не удалось загрузить пользователя с ID '{userId}'.");
 37        }
 38
 039        var decodedCode = Encoding.UTF8.GetString(WebEncoders.Base64UrlDecode(code));
 040        var result = await _userManager.ConfirmEmailAsync(user, decodedCode);
 041        StatusMessage = result.Succeeded
 042            ? "Спасибо! Email подтвержден. Теперь ожидайте одобрения администратора."
 043            : "Ошибка подтверждения email.";
 44
 045        if (!string.IsNullOrWhiteSpace(returnUrl))
 46        {
 047            return Redirect($"/Identity/Account/Login?ReturnUrl={Uri.EscapeDataString(returnUrl)}");
 48        }
 49
 050        return Page();
 051    }
 52}