diff --git a/SoftwareInstallation/ConfectioneryRestApi/Controllers/ShopController.cs b/SoftwareInstallation/ConfectioneryRestApi/Controllers/ShopController.cs index f46704e..4a0698a 100644 --- a/SoftwareInstallation/ConfectioneryRestApi/Controllers/ShopController.cs +++ b/SoftwareInstallation/ConfectioneryRestApi/Controllers/ShopController.cs @@ -6,6 +6,8 @@ using SoftwareInstallationDatabaseImplement.Models; using SoftwareInstallationDataModels.Models; using Microsoft.AspNetCore.Mvc; using System.Text.Json; +using System.Net.Http.Headers; +using System.Text; namespace SoftwareInstallationRestApi.Controllers { diff --git a/SoftwareInstallation/ConfectioneryRestApi/appsettings.json b/SoftwareInstallation/ConfectioneryRestApi/appsettings.json index 10f68b8..2a54cc6 100644 --- a/SoftwareInstallation/ConfectioneryRestApi/appsettings.json +++ b/SoftwareInstallation/ConfectioneryRestApi/appsettings.json @@ -5,5 +5,6 @@ "Microsoft.AspNetCore": "Warning" } }, - "AllowedHosts": "*" + "AllowedHosts": "*", + "PasswordToAccessShop": "12345" } diff --git a/SoftwareInstallation/ConfectioneryShopApp/APIClient.cs b/SoftwareInstallation/ConfectioneryShopApp/APIClient.cs index 65803ee..86c8608 100644 --- a/SoftwareInstallation/ConfectioneryShopApp/APIClient.cs +++ b/SoftwareInstallation/ConfectioneryShopApp/APIClient.cs @@ -8,7 +8,7 @@ namespace SoftwareInstallationShopApp { private static readonly HttpClient _client = new(); - public static bool IsAccessAllowed { get; set; } = false; + public static bool IsAccessAllowed { get; private set; } = false; public static string AccessPassword { get; private set; } = string.Empty; @@ -20,6 +20,11 @@ namespace SoftwareInstallationShopApp _client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); } + public static void Login(string password) + { + IsAccessAllowed = password == AccessPassword; + } + public static T? GetRequest(string requestUrl) { var response = _client.GetAsync(requestUrl); @@ -33,7 +38,6 @@ namespace SoftwareInstallationShopApp throw new Exception(result); } } - public static void PostRequest(string requestUrl, T model) { var json = JsonConvert.SerializeObject(model); diff --git a/SoftwareInstallation/ConfectioneryShopApp/Controllers/HomeController.cs b/SoftwareInstallation/ConfectioneryShopApp/Controllers/HomeController.cs index a720005..9fffa3e 100644 --- a/SoftwareInstallation/ConfectioneryShopApp/Controllers/HomeController.cs +++ b/SoftwareInstallation/ConfectioneryShopApp/Controllers/HomeController.cs @@ -53,10 +53,10 @@ namespace SoftwareInstallationShopApp.Controllers { if (string.IsNullOrEmpty(password)) { - throw new Exception("Введите пароль"); + throw new Exception("введите пароль"); } - APIClient.IsAccessAllowed = password.Equals(APIClient.AccessPassword); - if (APIClient.IsAccessAllowed is false) + APIClient.Login(password); + if (!APIClient.IsAccessAllowed) { throw new Exception("Неверный пароль"); }