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