diff options
| author | Shlomo Hecht <shlomo@twine-s.com> | 2019-02-26 16:44:52 +0200 |
|---|---|---|
| committer | Shlomo Hecht <shlomo@twine-s.com> | 2019-02-26 16:44:52 +0200 |
| commit | 6f62fafb2ef10b11189e9474ab13f531e614cf49 (patch) | |
| tree | 110aca8a50f72b51bcf9a2b54e7f78b9871c6a88 /Software/Visual_Studio/Web/Tango.MachineService/Controllers/AccountController.cs | |
| parent | b462fdd744f491b04137fd99863f6cb6c623cfa0 (diff) | |
| parent | 47691cbb0207d32c7b86113e3c425138907265d9 (diff) | |
| download | Tango-6f62fafb2ef10b11189e9474ab13f531e614cf49.tar.gz Tango-6f62fafb2ef10b11189e9474ab13f531e614cf49.zip | |
Merge branch 'master' of https://twinetfs.visualstudio.com/Tango/_git/Tango
Diffstat (limited to 'Software/Visual_Studio/Web/Tango.MachineService/Controllers/AccountController.cs')
| -rw-r--r-- | Software/Visual_Studio/Web/Tango.MachineService/Controllers/AccountController.cs | 57 |
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 |
