CourseWork_Bank/Bank/BankClientApp/Controllers/AuthorizationController.cs
2024-05-01 00:31:46 +03:00

61 lines
2.1 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using BankContracts.BindingModels;
using BankContracts.BusinessLogicContracts;
using BankContracts.SearchModels;
using Microsoft.AspNetCore.Mvc;
namespace BankClientApp.Controllers
{
public class AuthorizationController : Controller
{
private readonly ILogger<HomeController> _logger;
private readonly IClientLogic _clientLogic;
public AuthorizationController(ILogger<HomeController> logger, IClientLogic clientLogic)
{
_clientLogic = clientLogic;
_logger = logger;
}
[HttpGet]
public IActionResult Register()
{
return View();
}
[HttpPost]
public void Register(ClientBindingModel model)
{
if (string.IsNullOrEmpty(model.PhoneNumber) ||
string.IsNullOrEmpty(model.FirstName) ||
string.IsNullOrEmpty(model.MiddleName) ||
string.IsNullOrEmpty(model.LastName) ||
string.IsNullOrEmpty(model.Password))
{
throw new Exception("Все поля должны быть заполнены");
}
_clientLogic.Create(model);
_logger.LogInformation("Зарегистрирован клиент");
Response.Redirect("Enter");
}
public IActionResult Enter()
{
return View();
}
[HttpPost]
public void Enter(ClientSearchModel model)
{
if (string.IsNullOrEmpty(model.PhoneNumber) || string.IsNullOrEmpty(model.Password))
{
throw new Exception("Все поля должны быть заполнены");
}
var result = _clientLogic.ReadElement(model);
HttpContext.Session.SetString(SessionKeys.ClientPhoneNumber, model.PhoneNumber);
HttpContext.Session.SetString(SessionKeys.ClientPassword, model.Password);
_logger.LogInformation("Был осуществел вход за клиента {@client} и добавлены его данные в сессию", result);
Response.Redirect("../../Home/Index");
}
}
}