Files
laatzen/LaaProductionWeb/LaaProductionWeb/Controllers/HomeController.cs
T

52 lines
1.4 KiB
C#

namespace LaaProductionWeb.Controllers
{
using LaaProductionWeb.App_Infrastructure;
using LaaProductionWeb.Services.Interfaces;
using System.Web.Mvc;
[AllowAnonymous]
public class HomeController : Controller
{
private readonly IAccountService accountService;
public HomeController(IAccountService accountService)
=> this.accountService = accountService;
[HttpGet]
public ActionResult Index()
=> this.View();
[HttpPost]
public ActionResult Index(string username, string password)
{
if (string.IsNullOrWhiteSpace(username))
{
this.ModelState.AddModelError(nameof(username), "Benutzername ist erforderlich.");
}
if (string.IsNullOrWhiteSpace(password))
{
this.ModelState.AddModelError(nameof(password), "Kennwort ist erforderlich.");
}
if (this.ModelState.IsValid)
{
var userId = this.accountService.Login(username, password);
if (this.HttpContext.SignIn(userId))
{
return this.Redirect($"~{this.Request.UrlReferrer.LocalPath}");
}
}
return this.View();
}
public ActionResult Logout()
{
this.HttpContext.SignOut();
return this.View(nameof(Index));
}
}
}