< Summary

Information
Class: SlqStudio.Controllers.ConfigController
Assembly: OzonOrdersWeb
File(s): /home/runner/work/Studio2Prod/Studio2Prod/OzonOrdersWeb/Areas/Studio2/Controllers/ConfigController.cs
Line coverage
0%
Covered lines: 0
Uncovered lines: 22
Coverable lines: 22
Total lines: 64
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%156120%
EditConfig()0%620%
SaveConfig(...)100%210%

File(s)

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

#LineLine coverage
 1using Microsoft.AspNetCore.Authorization;
 2using Microsoft.AspNetCore.Mvc;
 3using Microsoft.Extensions.Configuration;
 4using Newtonsoft.Json.Linq;
 5using SlqStudio.Application.Services.AppSettingsServices;
 6
 7namespace SlqStudio.Controllers;
 8
 9[Authorize(Roles = "Admin")]
 10[Area("Studio2")]
 11public class ConfigController : Controller
 12    {
 13        private readonly IAppSettingsService _appSettingsService;
 14        private readonly AppSettingsBuilder _appSettingsBuilder;
 015        private readonly string _appSettingsPath = Path.Combine(Directory.GetCurrentDirectory(), "appsettings.json");
 16
 017        public ConfigController(IAppSettingsService appSettingsService, AppSettingsBuilder appSettingsBuilder)
 18        {
 019            _appSettingsService = appSettingsService;
 020            _appSettingsBuilder = appSettingsBuilder;
 021        }
 22
 23        // GET: /Config/Login
 24        public IActionResult Login()
 25        {
 026            return View();
 27        }
 28
 29        [HttpPost]
 30        public IActionResult Login(string name, string password)
 31        {
 032            var config = _appSettingsService.ReadConfig(_appSettingsPath);
 033            var userSection = config["ConfigUser"];
 34
 035            if (userSection != null &&
 036                name == userSection["Name"]?.ToString() &&
 037                password == userSection["Password"]?.ToString())
 38            {
 039                HttpContext.Session.SetString("IsConfigAuthorized", "true");
 40
 041                return RedirectToAction("EditConfig");
 42            }
 43
 044            ViewBag.Error = "Неверное имя пользователя или пароль.";
 045            return View();
 46        }
 47
 48        public IActionResult EditConfig()
 49        {
 050            if (HttpContext.Session.GetString("IsConfigAuthorized") != "true")
 051                return RedirectToAction("Login");
 52
 053            var jsonObj = _appSettingsService.ReadConfig(_appSettingsPath);
 054            return View(jsonObj);
 55        }
 56
 57        [HttpPost]
 58        public IActionResult SaveConfig(IFormCollection form)
 59        {
 060            var updatedConfig = _appSettingsBuilder.BuildAppSettings(form);
 061            _appSettingsService.WriteConfig(updatedConfig, _appSettingsPath);
 062            return RedirectToAction("EditConfig");
 63        }
 64    }