aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/Web/Tango.MachineService/Controllers
diff options
context:
space:
mode:
authorShlomo Hecht <shlomo@twine-s.com>2019-02-26 16:07:35 +0200
committerShlomo Hecht <shlomo@twine-s.com>2019-02-26 16:07:35 +0200
commitecda365478dfce97c5bba25603226bc42e864754 (patch)
treecfe16b86491f0f2b4e155f22847b62fc755faf75 /Software/Visual_Studio/Web/Tango.MachineService/Controllers
parenta2e2cea4eed379224e266a8b42f8842cf3564e17 (diff)
parent083488b18d562882af66b7cb25e45429996618f0 (diff)
downloadTango-ecda365478dfce97c5bba25603226bc42e864754.tar.gz
Tango-ecda365478dfce97c5bba25603226bc42e864754.zip
Merge branch 'master' of https://twinetfs.visualstudio.com/Tango/_git/Tango
Diffstat (limited to 'Software/Visual_Studio/Web/Tango.MachineService/Controllers')
-rw-r--r--Software/Visual_Studio/Web/Tango.MachineService/Controllers/AccountController.cs57
-rw-r--r--Software/Visual_Studio/Web/Tango.MachineService/Controllers/DownloadsController.cs29
2 files changed, 84 insertions, 2 deletions
diff --git a/Software/Visual_Studio/Web/Tango.MachineService/Controllers/AccountController.cs b/Software/Visual_Studio/Web/Tango.MachineService/Controllers/AccountController.cs
new file mode 100644
index 000000000..0a395b00e
--- /dev/null
+++ b/Software/Visual_Studio/Web/Tango.MachineService/Controllers/AccountController.cs
@@ -0,0 +1,57 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Net;
+using System.Security.Authentication;
+using System.Web;
+using System.Web.Mvc;
+using System.Web.Security;
+using Tango.BL;
+using Tango.MachineService.Models;
+using Tango.Web.ActiveDirectory;
+using Tango.Web.Helpers;
+
+namespace Tango.MachineService.Controllers
+{
+ public class AccountController : Controller
+ {
+ private ActiveDirectoryManager _ad_manager;
+
+ public AccountController()
+ {
+ _ad_manager = new ActiveDirectoryManager();
+ }
+
+ public ActionResult Login()
+ {
+ if (HttpContext.User.Identity.IsAuthenticated)
+ {
+ return RedirectToAction("Index", "Downloads", null);
+ }
+
+ return View();
+ }
+
+ [HttpPost]
+ public ActionResult Login(AccountLogin request)
+ {
+ var authResult = _ad_manager.ValidateUserCredentials(request.Email, request.Password);
+
+ if (!_ad_manager.CanUserAccessCurrentEnvironment(request.Email))
+ {
+ throw new AuthenticationException($"You do not have permissions to access the {MachineServiceConfig.DEPLOYMENT_SLOT.ToDescription()} environment.");
+ }
+
+
+ FormsAuthentication.SetAuthCookie(request.Email, true);
+ return new HttpStatusCodeResult(HttpStatusCode.OK);
+ }
+
+ [Authorize]
+ public ActionResult Logout()
+ {
+ FormsAuthentication.SignOut();
+ return Login();
+ }
+ }
+} \ No newline at end of file
diff --git a/Software/Visual_Studio/Web/Tango.MachineService/Controllers/DownloadsController.cs b/Software/Visual_Studio/Web/Tango.MachineService/Controllers/DownloadsController.cs
index 126b794ea..ecdbf662c 100644
--- a/Software/Visual_Studio/Web/Tango.MachineService/Controllers/DownloadsController.cs
+++ b/Software/Visual_Studio/Web/Tango.MachineService/Controllers/DownloadsController.cs
@@ -3,15 +3,40 @@ using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
+using Tango.MachineService.Filters;
+using Tango.MachineService.Models;
+using Tango.MachineService.Views.Downloads;
namespace Tango.MachineService.Controllers
{
public class DownloadsController : Controller
{
- // GET: Downloads
+ [Authorize]
public ActionResult Index()
{
- return View();
+ List<DownloadModel> downloads = new List<DownloadModel>();
+ for (int i = 0; i < 10; i++)
+ {
+ downloads.Add(new DownloadModel()
+ {
+ Name = "Downloads " + i,
+ Comments = "Some comments...\nWith a new line",
+ Date = DateTime.Now.ToString(),
+ User = "Roy",
+ ID = i.ToString(),
+ });
+ }
+
+ IndexViewModel model = new IndexViewModel();
+ model.Downloads = downloads;
+
+ return View(model);
+ }
+
+ [Authorize]
+ public ActionResult Download(String id)
+ {
+ return File(new byte[] { 25, 255, 255 }, System.Net.Mime.MediaTypeNames.Application.Octet,"Machine Studio v1.0.exe");
}
}
} \ No newline at end of file