Koscheev.M. S. Lab work 5 Hard #14
@ -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
|
||||
{
|
||||
|
@ -5,5 +5,6 @@
|
||||
"Microsoft.AspNetCore": "Warning"
|
||||
}
|
||||
},
|
||||
"AllowedHosts": "*"
|
||||
"AllowedHosts": "*",
|
||||
"PasswordToAccessShop": "12345"
|
||||
}
|
||||
|
@ -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<T>(string requestUrl)
|
||||
{
|
||||
var response = _client.GetAsync(requestUrl);
|
||||
@ -33,7 +38,6 @@ namespace SoftwareInstallationShopApp
|
||||
throw new Exception(result);
|
||||
}
|
||||
}
|
||||
|
||||
public static void PostRequest<T>(string requestUrl, T model)
|
||||
{
|
||||
var json = JsonConvert.SerializeObject(model);
|
||||
|
@ -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("Неверный пароль");
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user