< Summary

Information
Class: SlqStudio.Controllers.DatabaseController
Assembly: OzonOrdersWeb
File(s): /home/runner/work/Studio2Prod/Studio2Prod/OzonOrdersWeb/Areas/Studio2/Controllers/DatabaseController.cs
Line coverage
0%
Covered lines: 0
Uncovered lines: 15
Coverable lines: 15
Total lines: 51
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 14
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%
Login()100%210%
Login(...)0%210140%
Logout()100%210%

File(s)

/home/runner/work/Studio2Prod/Studio2Prod/OzonOrdersWeb/Areas/Studio2/Controllers/DatabaseController.cs

#LineLine coverage
 1using Microsoft.AspNetCore.Authorization;
 2using Microsoft.AspNetCore.Mvc;
 3using Microsoft.Extensions.Configuration;
 4
 5namespace SlqStudio.Controllers;
 6
 7[Authorize(Roles = "Admin")]
 8[Area("Studio2")]
 9public class DatabaseController : Controller
 10{
 11    private readonly IConfiguration _configuration;
 12    private const string DatabaseUrl = "https://db.interparts.ru/";
 13
 014    public DatabaseController(IConfiguration configuration)
 15    {
 016        _configuration = configuration;
 017    }
 18
 19    // GET: /Database/Login
 20    public IActionResult Login()
 21    {
 022        return View();
 23    }
 24
 25    [HttpPost]
 26    public IActionResult Login(string name, string password)
 27    {
 28        // Используем те же учетные данные, что и для Config
 029        var configUser = _configuration.GetSection("ConfigUser");
 030        var configName = configUser["Name"]?.ToString();
 031        var configPassword = configUser["Password"]?.ToString();
 32
 033        if (!string.IsNullOrEmpty(configName) && !string.IsNullOrEmpty(configPassword) &&
 034            name == configName && password == configPassword)
 35        {
 036            HttpContext.Session.SetString("IsDatabaseAuthorized", "true");
 37            // Сразу редиректим на внешний URL базы данных
 038            return Redirect(DatabaseUrl);
 39        }
 40
 041        ViewBag.Error = "Неверное имя пользователя или пароль.";
 042        return View();
 43    }
 44
 45    public IActionResult Logout()
 46    {
 047        HttpContext.Session.Remove("IsDatabaseAuthorized");
 048        return RedirectToAction("Login");
 49    }
 50}
 51