109 lines
3.4 KiB
C#
109 lines
3.4 KiB
C#
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using System.Diagnostics;
|
|
using StoreKeeperClient;
|
|
using ComputerHardwareStoreContracts.BindingModels;
|
|
using StoreKeeperClient.Models;
|
|
using ComputerHardwareStoreContracts.ViewModels;
|
|
|
|
namespace StorekeeperClient.Controllers
|
|
{
|
|
public class HomeController : Controller
|
|
{
|
|
private readonly ILogger<HomeController> _logger;
|
|
|
|
public HomeController(ILogger<HomeController> logger)
|
|
{
|
|
_logger = logger;
|
|
}
|
|
|
|
public IActionResult Register()
|
|
{
|
|
return View();
|
|
}
|
|
|
|
[HttpPost]
|
|
public void Register(string login, string name, string password)
|
|
{
|
|
if (string.IsNullOrEmpty(login) || string.IsNullOrEmpty(name) || string.IsNullOrEmpty(password))
|
|
{
|
|
throw new Exception("Введите логин, email, пароль");
|
|
}
|
|
APIClient.PostRequest("api/storekeeper/register", new StoreKeeperBindingModel
|
|
{
|
|
Login = login,
|
|
Name = name,
|
|
Password = password
|
|
});
|
|
Response.Redirect("Enter");
|
|
return;
|
|
}
|
|
|
|
public IActionResult Index()
|
|
{
|
|
return View();
|
|
}
|
|
|
|
[HttpGet]
|
|
public IActionResult Privacy()
|
|
{
|
|
if (APIClient.User == null)
|
|
{
|
|
return Redirect("~/Home/Enter");
|
|
}
|
|
return View(APIClient.User);
|
|
}
|
|
|
|
[HttpPost]
|
|
public IActionResult Privacy(string login, string name, string password)
|
|
{
|
|
if (APIClient.User == null)
|
|
{
|
|
throw new Exception("Вы как сюда попали? Сюда вход только авторизованным");
|
|
}
|
|
if (string.IsNullOrEmpty(login) || string.IsNullOrEmpty(name) || string.IsNullOrEmpty(password))
|
|
{
|
|
throw new Exception("Введите логин, пароль и почту");
|
|
}
|
|
APIClient.PostRequest("api/user/updatedata", new StoreKeeperBindingModel
|
|
{
|
|
Id = APIClient.User.Id,
|
|
Login = login,
|
|
Name = name,
|
|
Password = password
|
|
});
|
|
|
|
APIClient.User.Login = login;
|
|
APIClient.User.Name = name;
|
|
APIClient.User.Password = password;
|
|
|
|
return RedirectToAction("MainStorekeeper", "Storekeeper");
|
|
}
|
|
|
|
[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]
|
|
public IActionResult Enter(string login, string password)
|
|
{
|
|
if (string.IsNullOrEmpty(login) || string.IsNullOrEmpty(password))
|
|
{
|
|
throw new Exception("Введите почту и пароль");
|
|
}
|
|
APIClient.User = APIClient.GetRequest<StoreKeeperViewModel>($"api/user/login?login={login}&password={password}");
|
|
if (APIClient.User == null)
|
|
{
|
|
throw new Exception("Неверные почта и/или пароль");
|
|
}
|
|
return RedirectToAction("MainStorekeeper", "Storekeeper");
|
|
}
|
|
}
|
|
} |