using CandidateReviewClientApp; using CandidateReviewClientApp.Models; using CandidateReviewContracts.BindingModels; using CandidateReviewContracts.ViewModels; using CandidateReviewDataModels.Enums; using Microsoft.AspNetCore.Mvc; using System.Diagnostics; namespace CandidateReviewUserApp.Controllers { public class HomeController : Controller { private readonly ILogger _logger; public HomeController(ILogger logger) { _logger = logger; } public IActionResult Index() { return View(); } public IActionResult Privacy() { return View(); } [HttpGet] public IActionResult Enter() { return View(); } [HttpPost] public void Enter(string login, string password) { if (string.IsNullOrEmpty(login) || string.IsNullOrEmpty(password)) { throw new Exception("Введите логин и пароль"); } APIClient.User = APIClient.GetRequest($"api/user/login?login={login}&password={password}"); if (APIClient.User == null) { throw new Exception("Неверный логин/пароль"); } Response.Redirect("/Home/Index"); } [HttpGet] public IActionResult Register() { return View(); } [HttpPost] public void Register(string login, string password, string surname, string name, string lastname) { if (string.IsNullOrEmpty(login) || string.IsNullOrEmpty(password) || string.IsNullOrEmpty(surname) || string.IsNullOrEmpty(name)) { throw new Exception("Введите логин, пароль и ФИО"); } RoleEnum role = RoleEnum.Неизвестен; if (login.Equals("tania.art03@gmail.com", StringComparison.OrdinalIgnoreCase)) { role = RoleEnum.Сотрудник; } else if (login.Equals("t.artamonova73@icloud.com", StringComparison.OrdinalIgnoreCase)) { role = RoleEnum.Пользователь; } APIClient.PostRequest("api/user/register", new UserBindingModel { Surname = surname, Name = name, LastName = lastname ?? null, Email = login, Password = password, EmailConfirmed = false, Role = role }); Response.Redirect("/Home/Enter"); return; } [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)] public IActionResult Error() { return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier }); } } }