LabWork05_Hard: Фикс авторизации
This commit is contained in:
parent
4f91314c47
commit
f3562db8c4
@ -7,8 +7,17 @@ namespace AutomobilePlantShopApp
|
|||||||
public static class APIClient
|
public static class APIClient
|
||||||
{
|
{
|
||||||
private static readonly HttpClient _client = new();
|
private static readonly HttpClient _client = new();
|
||||||
public static bool isAuth { get; set; } = false;
|
public static bool isAuth { get; private set; } = false;
|
||||||
public static string ConfigPassword { get; private set; } = string.Empty;
|
public static string ConfigPassword { get; private set; } = string.Empty;
|
||||||
|
|
||||||
|
public static bool Login(string password)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(password))
|
||||||
|
{
|
||||||
|
throw new Exception("Введите пароль");
|
||||||
|
}
|
||||||
|
return isAuth = password.Equals(ConfigPassword);
|
||||||
|
}
|
||||||
public static void Connect(IConfiguration configuration)
|
public static void Connect(IConfiguration configuration)
|
||||||
{
|
{
|
||||||
ConfigPassword = configuration["Password"];
|
ConfigPassword = configuration["Password"];
|
||||||
|
@ -45,15 +45,10 @@ namespace AutomobilePlantShopApp.Controllers
|
|||||||
[HttpPost]
|
[HttpPost]
|
||||||
public void Enter(string password)
|
public void Enter(string password)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrEmpty(password))
|
if (!APIClient.Login(password))
|
||||||
{
|
|
||||||
throw new Exception("Введите пароль");
|
|
||||||
}
|
|
||||||
if (!password.Equals(APIClient.ConfigPassword))
|
|
||||||
{
|
{
|
||||||
throw new Exception("Неверный пароль");
|
throw new Exception("Неверный пароль");
|
||||||
}
|
}
|
||||||
APIClient.isAuth = true;
|
|
||||||
Response.Redirect("Index");
|
Response.Redirect("Index");
|
||||||
}
|
}
|
||||||
[HttpGet]
|
[HttpGet]
|
||||||
|
Loading…
Reference in New Issue
Block a user