2023-04-02 02:24:16 +04:00
|
|
|
|
using HardwareShopClientApp.Models;
|
|
|
|
|
using HardwareShopContracts.BindingModels;
|
|
|
|
|
using HardwareShopContracts.ViewModels;
|
|
|
|
|
using HardwareShopDataModels.Enums;
|
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
using System.Data;
|
|
|
|
|
using System.Diagnostics;
|
|
|
|
|
|
|
|
|
|
namespace HardwareShopClientApp.Controllers
|
|
|
|
|
{
|
|
|
|
|
public class HomeController : Controller
|
|
|
|
|
{
|
|
|
|
|
private readonly ILogger<HomeController> _logger;
|
|
|
|
|
|
|
|
|
|
public HomeController(ILogger<HomeController> logger)
|
|
|
|
|
{
|
|
|
|
|
_logger = logger;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpGet]
|
|
|
|
|
public IActionResult Register()
|
|
|
|
|
{
|
|
|
|
|
return View();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpPost]
|
|
|
|
|
public void Register(string login, string email, string password, int role)
|
|
|
|
|
{
|
|
|
|
|
if (string.IsNullOrEmpty(login) || string.IsNullOrEmpty(email) || string.IsNullOrEmpty(password) || role <= 0)
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("Введите логин, email, пароль и роль");
|
|
|
|
|
}
|
|
|
|
|
APIClient.PostRequest("api/client/register", new UserBindingModel
|
|
|
|
|
{
|
|
|
|
|
Login = login,
|
|
|
|
|
Email = email,
|
|
|
|
|
Password = password,
|
|
|
|
|
Role = (UserRole)role
|
|
|
|
|
});
|
|
|
|
|
Response.Redirect("Enter");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public IActionResult Index()
|
|
|
|
|
{
|
|
|
|
|
if (APIClient.User == null)
|
|
|
|
|
{
|
|
|
|
|
return Redirect("~/Home/Enter");
|
|
|
|
|
}
|
|
|
|
|
return View();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public IActionResult Privacy()
|
|
|
|
|
{
|
|
|
|
|
return View();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
|
|
|
|
|
public IActionResult Error()
|
|
|
|
|
{
|
|
|
|
|
return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[HttpGet]
|
|
|
|
|
public IActionResult Enter()
|
|
|
|
|
{
|
|
|
|
|
return View();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpPost]
|
|
|
|
|
public IActionResult Enter(string email, string password)
|
|
|
|
|
{
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
APIClient.User = APIClient.GetRequest<UserViewModel>($"api/client/login?email={email}&password={password}");
|
|
|
|
|
if (APIClient.User == null)
|
|
|
|
|
{
|
2023-04-02 16:22:58 +04:00
|
|
|
|
throw new Exception("Неверные почта и/или пароль");
|
2023-04-02 02:24:16 +04:00
|
|
|
|
}
|
|
|
|
|
if ((int)APIClient.User.Role == 1)
|
|
|
|
|
{
|
2023-04-02 13:47:04 +04:00
|
|
|
|
return RedirectToAction("MainWorker", "Worker");
|
2023-04-02 02:24:16 +04:00
|
|
|
|
return RedirectToAction("WorkerReport", "Worker");
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2023-04-02 12:36:49 +04:00
|
|
|
|
return Redirect("Index");
|
2023-04-02 02:24:16 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpGet]
|
|
|
|
|
public IActionResult MainWorker()
|
|
|
|
|
{
|
|
|
|
|
return View();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|