protected void btnActivate_OnClick(object sender, EventArgs e) { // Get the current user LoginSessionRepository loginRepository = new LoginSessionRepository(); string foundUserSessionID = loginRepository.GetSessionIDFromCookies(Request); LoginSession currentUser = null; if (!string.IsNullOrEmpty(foundUserSessionID)) { // A cookie exists, lets see if it corresponds to a valid session ID currentUser = loginRepository.LoadIfValid(foundUserSessionID, Request.ServerVariables["REMOTE_ADDR"], Request.ServerVariables["HTTP_USER_AGENT"]); } if (currentUser != null) { // Parse the number int count = Parsers.ParseInt(drpBatchCount.SelectedValue); if (count > 0) { GuestAccountController guestrepo = new GuestAccountController(); string batchID = guestrepo.RequisitionBatch(currentUser, txtReason.Text, count); // Wait a few seconds System.Threading.Thread.Sleep(1000 * 3); // Redirect to the batch info page redirectToInfoPage(batchID); } } }
protected void Page_Load(object sender, EventArgs e) { lblMaxBatchSize.Text = Settings.MaxBatchSize.ToString(); LoginSessionRepository loginRepository = new LoginSessionRepository(); string foundUserSessionID = loginRepository.GetSessionIDFromCookies(Request); LoginSession currentUser = null; if (!string.IsNullOrEmpty(foundUserSessionID)) { // A cookie exists, lets see if it corresponds to a valid session ID currentUser = loginRepository.LoadIfValid(foundUserSessionID, Request.ServerVariables["REMOTE_ADDR"], Request.ServerVariables["HTTP_USER_AGENT"]); } if (currentUser != null) { if (!currentUser.CanViewLogs) { redirectToIndex(); } } if (!IsPostBack) { tblControls.Visible = true; tblIndexInstructions.Visible = true; GuestAccountController guestRepo = new GuestAccountController(); int availableAccounts = guestRepo.GetAvailableGuestAccounts().Count(); lblAvailableGuestAccounts.Text = availableAccounts.ToString(); int maxBatchSize = Settings.MaxBatchSize; if (availableAccounts < maxBatchSize) { maxBatchSize = availableAccounts; } drpBatchCount.Items.Clear(); for (int x = 2; x <= Settings.MaxBatchSize; x++) { drpBatchCount.Items.Add(new ListItem() { Text = x.ToString(), Value = x.ToString() }); } } }
protected void btnActivate_OnClick(object sender, EventArgs e) { // Get the current user LoginSessionRepository loginRepository = new LoginSessionRepository(); string foundUserSessionID = loginRepository.GetSessionIDFromCookies(Request); LoginSession currentUser = null; if (!string.IsNullOrEmpty(foundUserSessionID)) { // A cookie exists, lets see if it corresponds to a valid session ID currentUser = loginRepository.LoadIfValid(foundUserSessionID, Request.ServerVariables["REMOTE_ADDR"], Request.ServerVariables["HTTP_USER_AGENT"]); } if (currentUser != null) { // Check to make sure that they've enterd a reason GuestAccountController guestrepo = new GuestAccountController(); GuestAccount activatedAccount = guestrepo.RequisitionAccount(currentUser, txtReason.Text.Trim()); if (activatedAccount != null) { lblUsername.Text = activatedAccount.sAMAccountName; lblPassword.Text = activatedAccount.Password; lblExpires.Text = DateTime.Today.AddDays(1).AddMinutes(-1).ToString(); lblAccountActiveTime.Text = DateTime.Now.AddMinutes(15).ToShortTimeString(); tblControls.Visible = false; tblIndexInstructions.Visible = false; tblNewAccountInfo.Visible = true; tblNewAccountInstructions.Visible = true; tblActiveAccounts.Visible = false; } } }
protected void Page_Load(object sender, EventArgs e) { GuestAccountController guestRepo = new GuestAccountController(); List <GuestAccount> allGuestAccounts = guestRepo.GetAllGuestAccounts(); Response.Clear(); Response.ContentEncoding = Encoding.UTF8; Response.ContentType = "application/json; charset=utf-8"; Response.Headers.Add("Access-Control-Allow-Origin", "*"); Response.Write("{\n"); Response.Write("\"TotalGuestAccounts\" : " + allGuestAccounts.Count() + ",\n"); Response.Write("\"TotalActive\" : " + allGuestAccounts.Count(g => g.IsEnabled) + ",\n"); Response.Write("\"ActiveAndDontExpire\" : " + allGuestAccounts.Count(g => g.IsEnabled && !g.Expires) + ",\n"); Response.Write("\"TotalAvailable\" : " + allGuestAccounts.Count(g => !g.IsEnabled) + ",\n"); Response.Write("\"Active\": [\n"); int counter = 0; foreach (GuestAccount guest in allGuestAccounts.Where(g => g.IsEnabled)) { Response.Write("{\n"); Response.Write("\"UserName\": \"" + guest.sAMAccountName + "\",\n"); Response.Write("\"RequestedBy\": \"" + guest.Comment + "\",\n"); Response.Write("\"Expires\": \"" + guest.Expires.ToYesOrNo() + "\"\n"); Response.Write("}\n"); counter++; if (counter < allGuestAccounts.Count(g => g.IsEnabled)) { Response.Write(","); } } Response.Write("]\n"); Response.Write("}\n"); Response.End(); }
protected void Page_Load(object sender, EventArgs e) { lblAllowedRequisitionsPerDay.Text = Settings.AllowedRequisitionsPerDay.ToString(); lblAllowedRequisitionsPerDay2.Text = Settings.AllowedRequisitionsPerDay.ToString(); if (!IsPostBack) { tblControls.Visible = true; tblIndexInstructions.Visible = true; tblNewAccountInfo.Visible = false; tblNewAccountInstructions.Visible = false; } // Get the current user LoginSessionRepository loginRepository = new LoginSessionRepository(); string foundUserSessionID = loginRepository.GetSessionIDFromCookies(Request); LoginSession currentUser = null; if (!string.IsNullOrEmpty(foundUserSessionID)) { // A cookie exists, lets see if it corresponds to a valid session ID currentUser = loginRepository.LoadIfValid(foundUserSessionID, Request.ServerVariables["REMOTE_ADDR"], Request.ServerVariables["HTTP_USER_AGENT"]); } if (currentUser != null) { if (currentUser.CanUseBatches) { tblCellBatch.Visible = true; } else { tblCellBatch.Visible = false; } if (currentUser.CanViewLogs) { tblCellLog.Visible = true; } else { tblCellLog.Visible = false; } // Find any guest accounts that the logged in user has already requisitions GuestAccountController guestRepo = new GuestAccountController(); List <GuestAccount> alreadyProvisionedGuestAccounts = guestRepo.GetActiveAccountsRequisitionedBy(currentUser); if (alreadyProvisionedGuestAccounts.Count > 0) { lblCount.Text = "<div class=\"already_active_text\">You have already activated " + alreadyProvisionedGuestAccounts.Count + " of a maximum of " + Settings.AllowedRequisitionsPerDay + " guest account(s) today</div>"; } if ((alreadyProvisionedGuestAccounts.Count >= Settings.AllowedRequisitionsPerDay) && (!currentUser.CanBypassLimits)) { tblControls.Visible = false; tblNewAccountInfo.Visible = false; tblNewAccountInstructions.Visible = false; tblTooMany.Visible = true; } if (alreadyProvisionedGuestAccounts.Count > 0) { tblActiveAccounts.Visible = true; tblActiveAccounts.Rows.Clear(); tblActiveAccounts.Rows.Add(alreadyActiveHeadings()); LogRepository logRepo = new LogRepository(); List <LoggedActivation> provisionedAccounts = logRepo.GetActivationsToday(currentUser); // Make a list of active usernames that we can compare to List <string> activeUsernames = alreadyProvisionedGuestAccounts.Select(g => g.sAMAccountName).ToList(); List <string> alreadyDisplayed = new List <string>(); foreach (LoggedActivation guest in provisionedAccounts.OrderByDescending(g => g.Date)) { if (activeUsernames.Contains(guest.GuestAccountName)) { if (!alreadyDisplayed.Contains(guest.GuestAccountName)) { alreadyDisplayed.Add(guest.GuestAccountName); tblActiveAccounts.Rows.Add(alreadyActiveRow(guest)); } } } } } }