Free cookie consent management tool by TermsFeed Policy Generator

source: branches/WebJobManager/HeuristicLab.Clients.Hive.WebJobManager/Controllers/HomeController.cs @ 13689

Last change on this file since 13689 was 13689, checked in by jlodewyc, 8 years ago

#2582 Implemented uploading

File size: 2.5 KB
Line 
1using HeuristicLab.Clients.Access;
2using HeuristicLab.Clients.Common;
3using HeuristicLab.Clients.Common.Properties;
4using HeuristicLab.Clients.Hive.WebJobManager.Services;
5using Microsoft.AspNet.Mvc;
6using System.ServiceModel.Security;
7
8namespace 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}
Note: See TracBrowser for help on using the repository browser.