aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/Web/Tango.MachineService/Controllers/AccountController.cs
diff options
context:
space:
mode:
authorRoy Ben-Shabat <Roy@Twine-s.com>2019-02-26 13:56:08 +0200
committerRoy Ben-Shabat <Roy@Twine-s.com>2019-02-26 13:56:08 +0200
commit99fa6ef9b19dc81f10b582ca6749bf1c8cf32c44 (patch)
tree9c5451e2c516e96ada413a6aa4f3f22e49817d8a /Software/Visual_Studio/Web/Tango.MachineService/Controllers/AccountController.cs
parentbbd04cf9e88d147225cc4b0d782fec31cfe21b6e (diff)
downloadTango-99fa6ef9b19dc81f10b582ca6749bf1c8cf32c44.tar.gz
Tango-99fa6ef9b19dc81f10b582ca6749bf1c8cf32c44.zip
Working on machine service downloads site.
Diffstat (limited to 'Software/Visual_Studio/Web/Tango.MachineService/Controllers/AccountController.cs')
-rw-r--r--Software/Visual_Studio/Web/Tango.MachineService/Controllers/AccountController.cs57
1 files changed, 57 insertions, 0 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