109 lines
3.4 KiB
C#
Raw Normal View History

2024-05-30 07:44:40 +04:00

2024-05-02 09:33:43 +04:00
using Microsoft.AspNetCore.Mvc;
using System.Diagnostics;
2024-05-30 07:44:40 +04:00
using StoreKeeperClient;
2024-05-28 20:21:49 +04:00
using ComputerHardwareStoreContracts.BindingModels;
2024-05-30 07:44:40 +04:00
using StoreKeeperClient.Models;
using ComputerHardwareStoreContracts.ViewModels;
2024-05-02 09:33:43 +04:00
2024-05-30 07:44:40 +04:00
namespace StorekeeperClient.Controllers
2024-05-02 09:33:43 +04:00
{
2024-05-30 07:44:40 +04:00
public class HomeController : Controller
2024-05-02 09:33:43 +04:00
{
private readonly ILogger<HomeController> _logger;
public HomeController(ILogger<HomeController> logger)
{
_logger = logger;
}
public IActionResult Register()
{
return View();
}
2024-05-30 07:44:40 +04:00
2024-05-29 17:25:32 +04:00
[HttpPost]
2024-05-30 07:44:40 +04:00
public void Register(string login, string name, string password)
2024-05-29 17:25:32 +04:00
{
if (string.IsNullOrEmpty(login) || string.IsNullOrEmpty(name) || string.IsNullOrEmpty(password))
{
2024-05-30 07:44:40 +04:00
throw new Exception("Введите логин, email, пароль");
2024-05-29 17:25:32 +04:00
}
APIClient.PostRequest("api/storekeeper/register", new StoreKeeperBindingModel
{
Login = login,
2024-05-30 07:44:40 +04:00
Name = name,
Password = password
2024-05-29 17:25:32 +04:00
});
Response.Redirect("Enter");
return;
}
2024-05-29 18:48:47 +04:00
2024-05-30 07:44:40 +04:00
public IActionResult Index()
2024-05-02 09:33:43 +04:00
{
2024-05-30 07:44:40 +04:00
return View();
2024-05-02 09:33:43 +04:00
}
[HttpGet]
2024-05-30 07:44:40 +04:00
public IActionResult Privacy()
2024-05-29 18:48:47 +04:00
{
2024-05-30 07:44:40 +04:00
if (APIClient.User == null)
2024-05-29 18:48:47 +04:00
{
return Redirect("~/Home/Enter");
}
2024-05-30 07:44:40 +04:00
return View(APIClient.User);
2024-05-29 18:48:47 +04:00
}
[HttpPost]
2024-05-30 07:44:40 +04:00
public IActionResult Privacy(string login, string name, string password)
2024-05-29 18:48:47 +04:00
{
2024-05-30 07:44:40 +04:00
if (APIClient.User == null)
2024-05-29 18:48:47 +04:00
{
throw new Exception("Вы как сюда попали? Сюда вход только авторизованным");
}
2024-05-30 07:44:40 +04:00
if (string.IsNullOrEmpty(login) || string.IsNullOrEmpty(name) || string.IsNullOrEmpty(password))
2024-05-29 18:48:47 +04:00
{
2024-05-30 07:44:40 +04:00
throw new Exception("Введите логин, пароль и почту");
2024-05-29 18:48:47 +04:00
}
2024-05-30 07:44:40 +04:00
APIClient.PostRequest("api/user/updatedata", new StoreKeeperBindingModel
2024-05-29 18:48:47 +04:00
{
2024-05-30 07:44:40 +04:00
Id = APIClient.User.Id,
Login = login,
Name = name,
Password = password
2024-05-29 18:48:47 +04:00
});
2024-05-30 07:44:40 +04:00
APIClient.User.Login = login;
APIClient.User.Name = name;
APIClient.User.Password = password;
2024-05-02 09:33:43 +04:00
2024-05-30 07:44:40 +04:00
return RedirectToAction("MainStorekeeper", "Storekeeper");
2024-05-02 09:33:43 +04:00
}
2024-05-30 07:44:40 +04:00
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
public IActionResult Error()
2024-05-02 09:33:43 +04:00
{
2024-05-30 07:44:40 +04:00
return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
2024-05-02 09:33:43 +04:00
}
2024-05-30 07:44:40 +04:00
public IActionResult Enter()
2024-05-02 09:33:43 +04:00
{
2024-05-30 07:44:40 +04:00
return View();
2024-05-02 09:33:43 +04:00
}
[HttpPost]
2024-05-30 07:44:40 +04:00
public IActionResult Enter(string login, string password)
{
2024-05-30 07:44:40 +04:00
if (string.IsNullOrEmpty(login) || string.IsNullOrEmpty(password))
{
2024-05-30 07:44:40 +04:00
throw new Exception("Введите почту и пароль");
}
2024-05-30 07:44:40 +04:00
APIClient.User = APIClient.GetRequest<StoreKeeperViewModel>($"api/user/login?login={login}&password={password}");
if (APIClient.User == null)
{
throw new Exception("Неверные почта и/или пароль");
}
return RedirectToAction("MainStorekeeper", "Storekeeper");
2024-05-02 09:33:43 +04:00
}
}
2024-05-30 07:44:40 +04:00
}