61 lines
2.1 KiB
C#
61 lines
2.1 KiB
C#
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");
|
||
}
|
||
}
|
||
}
|