private void Initialize() { _claimsIdentity = ((IClaimsPrincipal)(Thread.CurrentPrincipal)).Identities[0]; foreach (var c in _claimsIdentity.Claims) { _strClaimType = c.ClaimType; if (_strClaimType.EndsWith("domain")) _domain = c.Value; if (_strClaimType.EndsWith("EmailAddress")) _email = c.Value; } _user = _restAPI.GetUserByEmail(_email); _employeepuid = new Guid(_user.ObjectId.ToString()); List<ReferencedObject> directReports = _restAPI.GetLinks(_employeepuid, "DirectReports"); List<ReferencedObject> manager = _restAPI.GetLinks(_employeepuid, "Manager"); if (manager != null && manager.Count != 0) { new Guid(manager[0].ObjectId.ToString()); } }
public ActionResult AddUser(Guid employeeId) { Initialize(); var authorizedUsers = new AuthorizedUser(); _user = _restAPI.GetUser(employeeId); authorizedUsers.isAuthorized = true; authorizedUsers.EmployeeGUID = employeeId; authorizedUsers.EmployeeName = _user.DisplayName; authorizedUsers.EmployeeDepartment = _user.Department; authorizedUsers.domain = _domain; _db.AuthorizedUsers.Add(authorizedUsers); _db.SaveChanges(); return RedirectToAction("AddUsers"); }
private void Initialize() { _isAuthenticated = (bool)(ViewData["IsAuthenticated"] ?? false); _isAllowed = (bool)(ViewData["IsAuthorized"] ?? false); _isAdmin = (bool)(ViewData["IsAdministrator"] ?? false); if (_isAuthenticated) { foreach (Claim c in _claimsIdentity.Claims) { _strClaimType = c.ClaimType; if (_strClaimType.EndsWith("domain")) ; if (_strClaimType.EndsWith("FirstName")) ; if (_strClaimType.EndsWith("LastName")) ; if (_strClaimType.EndsWith("EmailAddress")) _email = c.Value; } RestApiInterface restAPI = RestApiInterface.Instance; _user = restAPI.GetUserByEmail(_email); _employeepuid = new Guid(_user.ObjectId.ToString()); List<ReferencedObject> directReports = restAPI.GetLinks(_employeepuid, "DirectReports"); List<ReferencedObject> manager = restAPI.GetLinks(_employeepuid, "Manager"); if (manager != null && manager.Count != 0) { new Guid(manager[0].ObjectId.ToString()); } } }
public override void OnActionExecuting(ActionExecutingContext filterContext) { HttpRequestBase request = filterContext.HttpContext.Request; HttpResponseBase response = filterContext.HttpContext.Response; if (request != null && response != null) { IsAuthenticated= request.IsAuthenticated; } if (IsAuthenticated) { Initializer(); var restAPI = RestApiInterface.Instance; // var restAPI = new RestApiInterface(); _user = restAPI.GetUserByEmail(_email); filterContext.Controller.ViewData["IsAuthenticated"] = true; var k = from r in _db.AuthorizedUsers where r.EmployeeGUID == _user.ObjectId select r; if (k.Any()) { filterContext.Controller.ViewData["IsAuthorized"] = true; } if (restAPI.IsAdministrator(new Guid(_user.ObjectId.ToString()))) { filterContext.Controller.ViewData["IsAdministrator"] = true; } if (restAPI.IsManager(new Guid(_user.ObjectId.ToString()))) { filterContext.Controller.ViewData["IsManager"] = true; } filterContext.Controller.ViewData["Name"] = _user.DisplayName; filterContext.Controller.ViewData["Street"] = _user.StreetAddress; filterContext.Controller.ViewData["City"] = _user.City; filterContext.Controller.ViewData["PostalCode"] = _user.PostalCode; filterContext.Controller.ViewData["Department"] = _user.Department; filterContext.Controller.ViewData["JobTitle"] = _user.JobTitle; filterContext.Controller.ViewData["UserPrincipalName"] = _user.UserPrincipalName; } base.OnActionExecuting(filterContext); }