Koscheev.M. S. Lab work 5 Hard #14

Closed
1maksim1 wants to merge 4 commits from Lab5_Hard into Lab4_Hard
4 changed files with 13 additions and 6 deletions
Showing only changes of commit fb558a7ff2 - Show all commits

View File

@ -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
{

View File

@ -5,5 +5,6 @@
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*"
"AllowedHosts": "*",
"PasswordToAccessShop": "12345"
}

View File

@ -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);

View File

@ -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("Неверный пароль");
}