fix
This commit is contained in:
parent
1dab9faa62
commit
fb558a7ff2
@ -6,6 +6,8 @@ using SoftwareInstallationDatabaseImplement.Models;
|
|||||||
using SoftwareInstallationDataModels.Models;
|
using SoftwareInstallationDataModels.Models;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using System.Text.Json;
|
using System.Text.Json;
|
||||||
|
using System.Net.Http.Headers;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
namespace SoftwareInstallationRestApi.Controllers
|
namespace SoftwareInstallationRestApi.Controllers
|
||||||
{
|
{
|
||||||
|
@ -5,5 +5,6 @@
|
|||||||
"Microsoft.AspNetCore": "Warning"
|
"Microsoft.AspNetCore": "Warning"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"AllowedHosts": "*"
|
"AllowedHosts": "*",
|
||||||
|
"PasswordToAccessShop": "12345"
|
||||||
}
|
}
|
||||||
|
@ -8,7 +8,7 @@ namespace SoftwareInstallationShopApp
|
|||||||
{
|
{
|
||||||
private static readonly HttpClient _client = new();
|
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;
|
public static string AccessPassword { get; private set; } = string.Empty;
|
||||||
|
|
||||||
@ -20,6 +20,11 @@ namespace SoftwareInstallationShopApp
|
|||||||
_client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
|
_client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void Login(string password)
|
||||||
|
{
|
||||||
|
IsAccessAllowed = password == AccessPassword;
|
||||||
|
}
|
||||||
|
|
||||||
public static T? GetRequest<T>(string requestUrl)
|
public static T? GetRequest<T>(string requestUrl)
|
||||||
{
|
{
|
||||||
var response = _client.GetAsync(requestUrl);
|
var response = _client.GetAsync(requestUrl);
|
||||||
@ -33,7 +38,6 @@ namespace SoftwareInstallationShopApp
|
|||||||
throw new Exception(result);
|
throw new Exception(result);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void PostRequest<T>(string requestUrl, T model)
|
public static void PostRequest<T>(string requestUrl, T model)
|
||||||
{
|
{
|
||||||
var json = JsonConvert.SerializeObject(model);
|
var json = JsonConvert.SerializeObject(model);
|
||||||
|
@ -53,10 +53,10 @@ namespace SoftwareInstallationShopApp.Controllers
|
|||||||
{
|
{
|
||||||
if (string.IsNullOrEmpty(password))
|
if (string.IsNullOrEmpty(password))
|
||||||
{
|
{
|
||||||
throw new Exception("Введите пароль");
|
throw new Exception("введите пароль");
|
||||||
}
|
}
|
||||||
APIClient.IsAccessAllowed = password.Equals(APIClient.AccessPassword);
|
APIClient.Login(password);
|
||||||
if (APIClient.IsAccessAllowed is false)
|
if (!APIClient.IsAccessAllowed)
|
||||||
{
|
{
|
||||||
throw new Exception("Неверный пароль");
|
throw new Exception("Неверный пароль");
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user