2023-04-08 17:14:55 +04:00
|
|
|
|
using HardwareShopStorekeeperApp.Models;
|
2023-04-02 02:24:16 +04:00
|
|
|
|
using HardwareShopContracts.BindingModels;
|
|
|
|
|
using HardwareShopContracts.ViewModels;
|
|
|
|
|
using HardwareShopDataModels.Enums;
|
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
using System.Diagnostics;
|
|
|
|
|
|
2023-04-08 17:14:55 +04:00
|
|
|
|
namespace HardwareShopStorekeeperApp.Controllers
|
2023-04-02 02:24:16 +04:00
|
|
|
|
{
|
|
|
|
|
public class HomeController : Controller
|
|
|
|
|
{
|
|
|
|
|
private readonly ILogger<HomeController> _logger;
|
|
|
|
|
|
|
|
|
|
public HomeController(ILogger<HomeController> logger)
|
|
|
|
|
{
|
|
|
|
|
_logger = logger;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public IActionResult Register()
|
|
|
|
|
{
|
|
|
|
|
return View();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpPost]
|
2023-05-16 15:41:04 +04:00
|
|
|
|
public void Register(string login, string email, string password)
|
2023-04-02 02:24:16 +04:00
|
|
|
|
{
|
2023-05-16 15:41:04 +04:00
|
|
|
|
if (string.IsNullOrEmpty(login) || string.IsNullOrEmpty(email) || string.IsNullOrEmpty(password))
|
2023-04-02 02:24:16 +04:00
|
|
|
|
{
|
2023-05-16 15:41:04 +04:00
|
|
|
|
throw new Exception("Введите логин, email, пароль");
|
2023-04-02 02:24:16 +04:00
|
|
|
|
}
|
2023-05-16 15:41:04 +04:00
|
|
|
|
APIClient.PostRequest("api/user/register", new UserBindingModel
|
2023-04-02 02:24:16 +04:00
|
|
|
|
{
|
|
|
|
|
Login = login,
|
|
|
|
|
Email = email,
|
|
|
|
|
Password = password,
|
2023-05-16 15:41:04 +04:00
|
|
|
|
Role = UserRole.Кладовщик
|
2023-04-02 02:24:16 +04:00
|
|
|
|
});
|
|
|
|
|
Response.Redirect("Enter");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public IActionResult Index()
|
|
|
|
|
{
|
|
|
|
|
return View();
|
|
|
|
|
}
|
|
|
|
|
|
2023-05-19 15:49:30 +04:00
|
|
|
|
[HttpGet]
|
2023-04-02 02:24:16 +04:00
|
|
|
|
public IActionResult Privacy()
|
|
|
|
|
{
|
2023-05-19 15:49:30 +04:00
|
|
|
|
if (APIClient.User == null)
|
|
|
|
|
{
|
|
|
|
|
return Redirect("~/Home/Enter");
|
|
|
|
|
}
|
|
|
|
|
return View(APIClient.User);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpPost]
|
2023-05-19 17:30:44 +04:00
|
|
|
|
public IActionResult Privacy(string login, string email, string password)
|
2023-05-19 15:49:30 +04:00
|
|
|
|
{
|
|
|
|
|
if (APIClient.User == null)
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("Вы как сюда попали? Сюда вход только авторизованным");
|
|
|
|
|
}
|
|
|
|
|
if (string.IsNullOrEmpty(login) || string.IsNullOrEmpty(email) || string.IsNullOrEmpty(password))
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("Введите логин, пароль и почту");
|
|
|
|
|
}
|
|
|
|
|
APIClient.PostRequest("api/user/updatedata", new UserBindingModel
|
|
|
|
|
{
|
|
|
|
|
Id = APIClient.User.Id,
|
|
|
|
|
Login = login,
|
|
|
|
|
Email = email,
|
|
|
|
|
Password = password
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
APIClient.User.Login = login;
|
|
|
|
|
APIClient.User.Email = email;
|
|
|
|
|
APIClient.User.Password = password;
|
|
|
|
|
|
2023-05-19 17:30:44 +04:00
|
|
|
|
return RedirectToAction("MainStorekeeper", "Storekeeper");
|
2023-04-02 02:24:16 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
|
|
|
|
|
public IActionResult Error()
|
|
|
|
|
{
|
|
|
|
|
return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public IActionResult Enter()
|
|
|
|
|
{
|
|
|
|
|
return View();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpPost]
|
2023-04-03 10:45:33 +04:00
|
|
|
|
public IActionResult Enter(string email, string password)
|
2023-04-02 02:24:16 +04:00
|
|
|
|
{
|
|
|
|
|
if (string.IsNullOrEmpty(email) || string.IsNullOrEmpty(password))
|
|
|
|
|
{
|
2023-04-02 16:22:58 +04:00
|
|
|
|
throw new Exception("Введите почту и пароль");
|
2023-04-02 02:24:16 +04:00
|
|
|
|
}
|
2023-05-16 15:41:04 +04:00
|
|
|
|
APIClient.User = APIClient.GetRequest<UserViewModel>($"api/user/login?email={email}&password={password}");
|
2023-05-19 15:26:48 +04:00
|
|
|
|
if (APIClient.User == null || APIClient.User.Role != UserRole.Кладовщик)
|
2023-04-02 02:24:16 +04:00
|
|
|
|
{
|
2023-04-02 16:22:58 +04:00
|
|
|
|
throw new Exception("Неверные почта и/или пароль");
|
2023-04-02 02:24:16 +04:00
|
|
|
|
}
|
2023-04-04 02:09:53 +04:00
|
|
|
|
return RedirectToAction("MainStorekeeper", "Storekeeper");
|
2023-04-02 02:24:16 +04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|