namespace LaaProduction.Web.Controllers { using LaaProductionHttp.Interfaces; using LaaProduction.Web.App_Infrastructure; using LaaProduction.Services.Interfaces; using LaaProductionDI; using System.Threading.Tasks; using System.Web.Mvc; [AllowAnonymous] public class HomeController : Controller { private readonly IAccountService accountService; private readonly IHttpClient httpClient; public HomeController() { this.accountService = LaaServiceProvider.GetService(); this.httpClient = LaaServiceProvider.GetService(); } [HttpGet] public ActionResult Index() => this.View(); [HttpPost] public async Task 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."); } password = password.ComputeHash(); var software = typeof(HomeController) .Assembly .GetName() .Name; var token = await this.httpClient .Post("/Personalization/Login") .WhitJsonBody(new { username, password, software }) .SendAsync(); if (!token.Succeeded) { foreach (var error in token.Errors) { this.ModelState.AddModelError(error.Key, error.Value); } if (!string.IsNullOrWhiteSpace(token.Message)) { this.ModelState.AddModelError(nameof(token.Message), token.Message); } } else { this.HttpContext.SignIn(token.Value); return this.Redirect(this.HttpContext.GetUrlReferer()); } return this.View(); } public ActionResult Logout() { this.HttpContext.SignOut(); return this.Redirect("/"); } } }