1 | using HeuristicLab.Clients.Access;
|
---|
2 | using HeuristicLab.Clients.Common;
|
---|
3 | using HeuristicLab.Clients.Common.Properties;
|
---|
4 | using HeuristicLab.Clients.Hive.WebJobManager.Services;
|
---|
5 | using Microsoft.AspNet.Mvc;
|
---|
6 | using System.ServiceModel.Security;
|
---|
7 |
|
---|
8 | namespace HeuristicLab.Clients.Hive.WebJobManager.Controllers
|
---|
9 | {
|
---|
10 | public class HomeController : Controller
|
---|
11 | {
|
---|
12 | private ILoginViewModelService loginViewModelService;
|
---|
13 | private HiveServiceClient client;
|
---|
14 | public HomeController(ILoginViewModelService loginViewModelService)
|
---|
15 | {
|
---|
16 | this.loginViewModelService = loginViewModelService;
|
---|
17 | }
|
---|
18 | public IActionResult Index()
|
---|
19 | {
|
---|
20 | ViewBag.Title = "Login";
|
---|
21 | return View(loginViewModelService.GetLoginViewModel());
|
---|
22 | }
|
---|
23 | public IActionResult Login(string loginName, string password)
|
---|
24 | {
|
---|
25 | if (!string.IsNullOrEmpty(loginName) && !string.IsNullOrEmpty(password))
|
---|
26 | {
|
---|
27 | var model = loginViewModelService.GetLoginViewModel();
|
---|
28 | HiveServiceLocatorWebManagerService hiveServiceLocator = (HiveServiceLocatorWebManagerService)HiveServiceLocatorWebManagerService.Instance;
|
---|
29 | HeuristicLab.Clients.Common.Properties.Settings.Default.UserName = loginName;
|
---|
30 | HeuristicLab.Clients.Common.Properties.Settings.Default.Password = Common.CryptoService.EncryptString(password);
|
---|
31 | HeuristicLab.Clients.Common.Properties.Settings.Default.Save();
|
---|
32 | hiveServiceLocator.Username = loginName;
|
---|
33 | hiveServiceLocator.Password = password;
|
---|
34 |
|
---|
35 | client = hiveServiceLocator.getHiveServiceClient();
|
---|
36 | try {
|
---|
37 | var test = client.GetJobs();//Throws messageSecurityException if login failss
|
---|
38 | ViewBag.Title = "Login succesful";
|
---|
39 | return View("LoginHome");
|
---|
40 | }
|
---|
41 | catch(MessageSecurityException e)
|
---|
42 | {
|
---|
43 | ViewBag.Title = "Login";
|
---|
44 | model.errorMessage = "Wrong login, try again";
|
---|
45 | return View("Index", model);
|
---|
46 | }
|
---|
47 |
|
---|
48 | }
|
---|
49 | else
|
---|
50 | {
|
---|
51 | ViewBag.Title = "Login";
|
---|
52 | var model = loginViewModelService.GetLoginViewModel();
|
---|
53 | model.errorMessage = "You should fill in both fields";
|
---|
54 | return View("Index", model);
|
---|
55 | }
|
---|
56 | }
|
---|
57 | }
|
---|
58 | }
|
---|