using HeuristicLab.Clients.Access; using HeuristicLab.Clients.Common; using HeuristicLab.Clients.Common.Properties; using HeuristicLab.Clients.Hive.WebJobManager.Services; using Microsoft.AspNet.Mvc; using System.ServiceModel.Security; namespace HeuristicLab.Clients.Hive.WebJobManager.Controllers { public class HomeController : Controller { private ILoginViewModelService loginViewModelService; private HiveServiceClient client; public HomeController(ILoginViewModelService loginViewModelService) { this.loginViewModelService = loginViewModelService; } public IActionResult Index() { ViewBag.Title = "Login"; return View(loginViewModelService.GetLoginViewModel()); } public IActionResult Login(string loginName, string password) { if (!string.IsNullOrEmpty(loginName) && !string.IsNullOrEmpty(password)) { var model = loginViewModelService.GetLoginViewModel(); HiveServiceLocatorWebManagerService hiveServiceLocator = (HiveServiceLocatorWebManagerService)HiveServiceLocatorWebManagerService.Instance; HeuristicLab.Clients.Common.Properties.Settings.Default.UserName = loginName; HeuristicLab.Clients.Common.Properties.Settings.Default.Password = Common.CryptoService.EncryptString(password); HeuristicLab.Clients.Common.Properties.Settings.Default.Save(); hiveServiceLocator.Username = loginName; hiveServiceLocator.Password = password; client = hiveServiceLocator.getHiveServiceClient(); try { var test = client.GetJobs();//Throws messageSecurityException if login failss ViewBag.Title = "Login succesful"; return View("LoginHome"); } catch(MessageSecurityException e) { ViewBag.Title = "Login"; model.errorMessage = "Wrong login, try again"; return View("Index", model); } } else { ViewBag.Title = "Login"; var model = loginViewModelService.GetLoginViewModel(); model.errorMessage = "You should fill in both fields"; return View("Index", model); } } } }