protected override void OnLoad(EventArgs e) { base.OnLoad(e); if (!Page.IsPostBack) { string macAttr = GetAttributeValue("MacAddressParam"); string macAddress = RockPage.PageParameter(GetAttributeValue("MacAddressParam")); Regex regex = new Regex("^([0-9a-fA-F]{2}(?:[:-]?[0-9a-fA-F]{2}){5})$"); if (string.IsNullOrWhiteSpace(macAddress) || !macAddress.IsValidMacAddress()) { nbAlert.Text = "Missing or invalid MAC Address"; nbAlert.Visible = true; return; } // Save the supplied MAC address to the page removing any non-Alphanumeric characters macAddress = macAddress.RemoveAllNonAlphaNumericCharacters(); hfMacAddress.Value = macAddress; // See if user is logged and link the alias to the device. if (CurrentPerson == null) { nbAlert.Text = "You are not logged in"; nbAlert.Visible = true; return; } hfPersonAliasId.Value = CurrentPersonAliasId.ToString(); RefreshContent(); } }
protected override void OnLoad(EventArgs e) { base.OnLoad(e); if (CurrentPersonAliasId.HasValue) { int cacheDuration = GetAttributeValue(AttributeKey.CacheDuration).AsInteger(); string cacheKey = "MyAlerts:PersonAliasId:" + CurrentPersonAliasId.ToString(); int? totalAlerts = null; if (cacheDuration > 0) { totalAlerts = GetCacheItem(cacheKey) as int?; } if (!totalAlerts.HasValue) { using (var rockContext = new RockContext()) { totalAlerts = 0; if (GetAttributeValue(AttributeKey.IncludeWorkflows).AsBoolean()) { totalAlerts += GetWorkflows(rockContext).Count(); } if (GetAttributeValue(AttributeKey.IncludeConnections).AsBoolean()) { totalAlerts += GetConnections(rockContext).Count(); } if (GetAttributeValue(AttributeKey.IncludeProjects).AsBoolean()) { totalAlerts += GetProjectCount(rockContext); } if (GetAttributeValue(AttributeKey.IncludeTasks).AsBoolean()) { totalAlerts += GetTaskCount(rockContext); } } } if (cacheDuration > 0) { AddCacheItem(cacheKey, totalAlerts, cacheDuration); } if (totalAlerts > 0) { // add a badge for the count of alerts var spanLiteral = string.Format("<span class='badge badge-danger'>{0}</span>", totalAlerts); lbAlerts.Controls.Add(new LiteralControl(spanLiteral)); } } }
protected override void OnLoad(EventArgs e) { base.OnLoad(e); nbAlert.Visible = false; // Go through the UA ignore list and don't load anything we don't care about or want. foreach (string userAgentToIgnore in _userAgentsToIgnore) { if (Request.UserAgent.StartsWith(userAgentToIgnore)) { return; } } if (!IsPostBack) { string macAddress = RockPage.PageParameter(GetAttributeValue("MacAddressParam")); Regex regex = new Regex("^([0-9a-fA-F]{2}(?:[:-]?[0-9a-fA-F]{2}){5})$"); if (string.IsNullOrWhiteSpace(macAddress) || !regex.IsMatch(macAddress)) { nbAlert.Text = "Missing or invalid MAC Address"; nbAlert.Visible = true; ShowControls(false); return; } string releaseLink = GetAttributeValue("ReleaseLink"); Uri uriResult; Boolean validUrl = Uri.TryCreate(releaseLink, UriKind.Absolute, out uriResult) && (uriResult.Scheme == Uri.UriSchemeHttp || uriResult.Scheme == Uri.UriSchemeHttps); if (string.IsNullOrWhiteSpace(releaseLink) || !validUrl) { nbAlert.Text = "Missing or invalid Release Link"; nbAlert.Visible = true; ShowControls(false); return; } // Save the supplied MAC address to the page removing any non-Alphanumeric characters macAddress = string.Concat(macAddress.Where(c => char.IsLetterOrDigit(c))); hfMacAddress.Value = macAddress; RockContext rockContext = new RockContext(); // create or get device PersonalDeviceService personalDeviceService = new PersonalDeviceService(rockContext); PersonalDevice personalDevice = null; bool isAnExistingDevice = DoesPersonalDeviceExist(macAddress); if (isAnExistingDevice) { personalDevice = VerifyDeviceInfo(macAddress); } else { personalDevice = CreateDevice(macAddress); CreateDeviceCookie(macAddress); } // See if user is logged and link the alias to the device. if (CurrentPerson != null) { Prefill(CurrentPerson); RockPage.LinkPersonAliasToDevice(( int )CurrentPersonAliasId, macAddress); hfPersonAliasId.Value = CurrentPersonAliasId.ToString(); } else if (isAnExistingDevice) { // if the user is not logged in but we have the device lets try to get a person if (personalDevice.PersonAliasId != null) { // Get the person PersonService personService = new PersonService(rockContext); Person person = personService.Get(personalDevice.PersonAlias.PersonId); if (person != null) { Prefill(person); RockPage.LinkPersonAliasToDevice(( int )personalDevice.PersonAliasId, macAddress); hfPersonAliasId.Value = personalDevice.PersonAliasId.ToString(); } } } // Direct connect if no controls are visible if (!ShowControls()) { // Nothing to show means nothing to enter. Redirect user back to FP with the primary alias ID and query string if (IsUserAuthorized(Rock.Security.Authorization.ADMINISTRATE)) { nbAlert.Text = string.Format("If you did not have Administrative permissions on this block you would have been redirected to: <a href='{0}'>{0}</a>.", CreateRedirectUrl(null)); } else { Response.Redirect(CreateRedirectUrl(null)); return; } } } }
protected void activeWorkflowCount() { // Check for current person if (CurrentPersonAliasId.HasValue) { int cacheDuration = GetAttributeValue("CacheDuration").AsInteger(); string cacheKey = "WorkflowAlertCount:PersonAliasId:" + CurrentPersonAliasId.ToString(); int? activeIncompleteWorkflows = null; if (cacheDuration > 0) { activeIncompleteWorkflows = this.GetCacheItem(cacheKey) as int?; } if (!activeIncompleteWorkflows.HasValue) { using (var rockContext = new RockContext()) { // Return the count of active workflows assigned to the current user (or user's group) activeIncompleteWorkflows = GetActions(rockContext).Count(); if (cacheDuration > 0) { this.AddCacheItem(cacheKey, activeIncompleteWorkflows, cacheDuration); } } } // set the default display var spanLiteral = ""; if (activeIncompleteWorkflows > 0) { // add the count of how many workflows need to be assigned/completed spanLiteral = string.Format("<span class='badge badge-danger'>{0}</span>", activeIncompleteWorkflows); } lbListingPage.Controls.Add(new LiteralControl(spanLiteral)); } }
protected override void OnLoad(EventArgs e) { base.OnLoad(e); nbAlert.Visible = false; // Go through the UA ignore list and don't load anything we don't care about or want. foreach (string userAgentToIgnore in _userAgentsToIgnore) { if (Request.UserAgent.StartsWith(userAgentToIgnore)) { return; } } if (!IsPostBack) { string macAddress = RockPage.PageParameter(GetAttributeValue("MacAddressParam")); if (string.IsNullOrWhiteSpace(macAddress) || !macAddress.IsValidMacAddress()) { nbAlert.Text = "Missing or invalid MAC Address"; nbAlert.Visible = true; ShowControls(false); return; } string releaseLink = GetAttributeValue("ReleaseLink"); if (string.IsNullOrWhiteSpace(releaseLink) || !releaseLink.IsValidUrl()) { nbAlert.Text = "Missing or invalid Release Link"; nbAlert.Visible = true; ShowControls(false); return; } // Save the supplied MAC address to the page removing any non-Alphanumeric characters macAddress = macAddress.RemoveAllNonAlphaNumericCharacters(); hfMacAddress.Value = macAddress; RockContext rockContext = new RockContext(); // create or get device PersonalDeviceService personalDeviceService = new PersonalDeviceService(rockContext); PersonalDevice personalDevice = null; bool isAnExistingDevice = DoesPersonalDeviceExist(macAddress); if (isAnExistingDevice) { personalDevice = VerifyDeviceInfo(macAddress); } else { personalDevice = CreateDevice(macAddress); } // We are going to create this everytime they hit the captive portal page. Otherwise if the device is saved but not linked to an actual user (not the fake one created here), // and then deleted by the user/browser/software, then they'll never get the cookie again and won't automatically get linked by RockPage. CreateDeviceCookie(macAddress); // See if user is logged and link the alias to the device. if (CurrentPerson != null) { Prefill(CurrentPerson); RockPage.LinkPersonAliasToDevice(( int )CurrentPersonAliasId, macAddress); hfPersonAliasId.Value = CurrentPersonAliasId.ToString(); } else if (isAnExistingDevice) { // if the user is not logged in but we have the device lets try to get a person if (personalDevice.PersonAliasId != null) { // Get the person PersonService personService = new PersonService(rockContext); Person person = personService.Get(personalDevice.PersonAlias.PersonId); if (person != null) { Prefill(person); RockPage.LinkPersonAliasToDevice(( int )personalDevice.PersonAliasId, macAddress); hfPersonAliasId.Value = personalDevice.PersonAliasId.ToString(); } } } // Direct connect if no controls are visible if (!ShowControls()) { // Nothing to show means nothing to enter. Redirect user back to FP with the primary alias ID and query string if (IsUserAuthorized(Rock.Security.Authorization.ADMINISTRATE)) { nbAlert.Text = string.Format("If you did not have Administrative permissions on this block you would have been redirected to: <a href='{0}'>{0}</a>.", CreateRedirectUrl(null)); } else { Response.Redirect(CreateRedirectUrl(null)); return; } } } }