private void AnalyzeDeletions(string address) { var found = false; found |= AnalyzeCount(States.CountByEmail(address), address, "States.Email"); found |= AnalyzeCount(States.CountByAltEmail(address), address, "States.AltEmail"); found |= AnalyzeCount(Counties.CountByEmail(address), address, "Counties.Email"); found |= AnalyzeCount(Counties.CountByAltEmail(address), address, "Counties.AltEmail"); found |= AnalyzeCount(LocalDistricts.CountByEmail(address), address, "LocalDistricts.Email"); found |= AnalyzeCount(LocalDistricts.CountByAltEmail(address), address, "LocalDistricts.AltEmail"); found |= AnalyzeCount(Politicians.CountByEmail(address), address, "Politicians.Email"); found |= AnalyzeCount(Politicians.CountByCampaignEmail(address), address, "Politicians.CampaignEmail"); found |= AnalyzeCount(Politicians.CountByEmailVoteUSA(address), address, "Politicians.EmailVoteUSA"); found |= AnalyzeCount(Politicians.CountByStateEmail(address), address, "Politicians.StateEmail"); //found |= AnalyzeCount(Politicians.CountByLDSEmail(address), address, "Politicians.LDSEmail"); found |= AnalyzeCount(Addresses.EmailExists(address) ? 1 : 0, address, "Addresses.Email"); found |= AnalyzeCount(PartiesEmails.PartyEmailExists(address) ? 1 : 0, address, "PartiesEmails.PartyEmail"); if (!found) { _Messages.Add($"<p class=\"error\">{address} not found</p>"); } }
protected void Button_Delete_Email_Click(object sender, EventArgs e) { try { CheckForDangerousInput(); if (!IsNullOrEmpty(TextboxEmailAddress.Text.Trim())) { PartiesEmails.DeleteByPartyEmail(TextboxEmailAddress.Text.Trim()); Clear_Email_TextBoxes(); PartiesReport(); Emails_Report(); Msg_Email.Text = Ok("The email address has been deleted."); } else { Msg_Email.Text = Fail("No email address was selected for deletion."); } } catch (Exception ex) { Msg_Email.Text = Fail(ex.Message); LogAdminError(ex); } }
public static List <SimpleListItem> GetPreviewPartyEmailItems(string partyKey) { return(new List <SimpleListItem> { new SimpleListItem(Empty, "<none>") }.Union( PartiesEmails.GetDataByPartyKey(partyKey).Rows.Cast <DataRow>() .OrderBy(row => row.PartyContactLName()).Select(row => new SimpleListItem(row.PartyEmail(), $"{row.PartyContactFName()} {row.PartyContactLName()} <{row.PartyEmail()}>"))) .ToList()); }
private static void SetSessionVariables( string usernameEntered, string userSecurityClass, bool superUser) { var session = HttpContext.Current.Session; // Note: we fetch the UserName from the db to normalize casing session["UserSecurity"] = userSecurityClass; session["_UserSecurity"] = session["UserSecurity"]; session["SuperUser"] = superUser ? "Y" : "N"; session["_SuperUser"] = session["SuperUser"]; switch (userSecurityClass) { case PoliticianSecurityClass: session["UserName"] = Politicians.GetPoliticianKey(usernameEntered); session["_UserName"] = session["UserName"]; session["PoliticianKey"] = usernameEntered.ToUpperInvariant(); session["_PoliticianKey"] = session["PoliticianKey"]; break; case PartySecurityClass: session["UserName"] = PartiesEmails.GetPartyEmail(usernameEntered); session["_UserName"] = session["UserName"]; session["UserPartyKey"] = PartiesEmails.GetPartyKey(usernameEntered) .ToUpperInvariant(); session["_UserPartyKey"] = session["UserPartyKey"]; break; default: { var row = Security.GetData(usernameEntered)[0]; session["UserName"] = Security.GetUserName(usernameEntered); session["_UserName"] = session["UserName"]; session["UserStateCode"] = row.UserStateCode.ToUpperInvariant(); session["_UserStateCode"] = session["UserStateCode"]; session["UserCountyCode"] = string.IsNullOrWhiteSpace(row.UserCountyCode) ? string.Empty : row.UserCountyCode.ZeroPad(3); session["_UserCountyCode"] = session["UserCountyCode"]; session["UserLocalCode"] = string.IsNullOrWhiteSpace(row.UserLocalCode) ? string.Empty : row.UserLocalCode.ZeroPad(2); session["_UserLocalCode"] = session["UserLocalCode"]; session["UserDesignCode"] = row.UserDesignCode.ToUpperInvariant(); session["_UserDesignCode"] = session["UserDesignCode"]; session["UserOrganizationCode"] = row.UserOrganizationCode.ToUpperInvariant(); session["_UserOrganizationCode"] = session["UserOrganizationCode"]; session["UserIssuesCode"] = row.UserIssuesCode.ToUpperInvariant(); session["_UserIssuesCode"] = session["UserIssuesCode"]; } break; } }
protected void TextBox_Title_TextChanged(object sender, EventArgs e) { CheckForDangerousInput(); Check_Email_Address_Empty(); var email = TextboxEmailAddress.Text.Trim(); PartiesEmails.UpdatePartyContactTitle(TextBox_Title.Text.Trim(), email); Load_Party_Data(); Load_Email_Data(email); PartiesReport(); Msg_Party.Text = Ok("Title was updated."); }
protected void Button_Add_Email_Click1(object sender, EventArgs e) { try { CheckForDangerousInput(); if (IsNullOrEmpty(_PartyKey)) { Msg_Email.Text = Fail("You need to select a party before you can add an email address."); } else { var emailAddress = TextboxEmailAddress_Add.Text.Trim().RemoveMailTo().ToLower(); if (Validation.IsValidEmailAddress(emailAddress)) { if (PartiesEmails.PartyEmailExists(emailAddress)) { Msg_Email.Text = Fail("The email address already exists."); } else { PartiesEmails.Insert(emailAddress, MakeUniquePassword(), _PartyKey, Empty, Empty, Empty, Empty, false, DateTime.UtcNow, false); LogAdminData.Insert(DateTime.Now, UserSecurityClass, UserName, "PartyEmail", Empty, emailAddress); ViewState["EmailAddress"] = _EmailAddress = emailAddress; TextboxEmailAddress_Add.Text = Empty; Load_Email_Data(_EmailAddress); PartiesReport(); Msg_Email.Text = Ok("The email address has been added."); } } else { Msg_Email.Text = Fail("The email address is not valid."); } } } catch (Exception ex) { Msg_Email.Text = Fail(ex.Message); LogAdminError(ex); } }
protected void ButtonAddVolunteer_OnClick(object sender, EventArgs e) { try { _AddVolunteerTabInfo.ClearValidationErrors(); var success = _AddVolunteerTabInfo.Validate(); if (!success) { return; } // check for existing email var email = ControlAddVolunteerEmail.GetValue(); var isVolunteer = PartiesEmails.GetIsVolunteer(email); if (isVolunteer != null) { // duplicate FeedbackAddVolunteer.PostValidationError(ControlAddVolunteerEmail, isVolunteer.Value ? "The email address is already registered as a volunteer" : "The email address is registered as a party official"); return; } var password = ControlAddVolunteerPassword.GetValue().Trim(); if (string.IsNullOrWhiteSpace(password)) { password = MakeUniquePassword(); } VolunteersView.Insert(email, password, ControlAddVolunteerState.GetValue() + ControlAddVolunteerParty.GetValue(), ControlAddVolunteerFirstName.GetValue(), ControlAddVolunteerLastName.GetValue(), ControlAddVolunteerPhone.GetValue().Trim()); var notes = ControlAddVolunteerNotes.GetValue().StripRedundantWhiteSpace(); if (!string.IsNullOrWhiteSpace(notes)) { VolunteersNotes.Insert(email, DateTime.UtcNow, notes); } _AddVolunteerTabInfo.Reset(); FeedbackAddVolunteer.AddInfo("Volunteer added."); } catch (Exception ex) { FeedbackAddVolunteer.HandleException(ex); } }
private static bool ValidateUniqueEmail(DataItemBase item) { var success = ValidateRequired(item); if (success) { var newValue = item.DataControl.GetValue(); var oldValue = GetCurrentValue(item); if (newValue.IsNeIgnoreCase(oldValue) && PartiesEmails.PartyEmailExists(item.DataControl.GetValue())) { item.Feedback.PostValidationError(item.DataControl, "The new email address already exists."); success = false; } } return(success); }
private void UnsubscribeParty(string email) { var table = PartiesEmails.GetDataByPartyEmail(email); if (table.Count == 0) { Message.InnerText = "The requested email address was not found"; return; } foreach (var row in table) { row.OptOut = true; } PartiesEmails.UpdateTable(table); Message.InnerText = $"Email {email} has been unsubscribed from all future party-related emails."; }
private void Load_Email_Data(string partyEmail) { var tableEmail = PartiesEmails.GetDataByPartyEmail(partyEmail); if (tableEmail.Count != 1) { throw new ApplicationException($"Did not find a unique row for this PartyEmail: {partyEmail}"); } var rowEmail = tableEmail[0]; TextboxEmailAddress.Text = rowEmail.PartyEmail; TextboxPhone.Text = rowEmail.PartyContactPhone; TextBox_First_Name.Text = rowEmail.PartyContactFirstName; TextBox_Last_Name.Text = rowEmail.PartyContactLastName; TextBox_Title.Text = rowEmail.PartyContactTitle; Emails_Report(); }
protected void TextboxPhone_TextChanged(object sender, EventArgs e) { try { CheckForDangerousInput(); Check_Email_Address_Empty(); var email = TextboxEmailAddress.Text.Trim(); PartiesEmails.UpdatePartyContactPhone(TextboxPhone.Text.Trim(), email); Load_Party_Data(); Load_Email_Data(email); PartiesReport(); Msg_Party.Text = Ok("Phone was updated."); } catch (Exception ex) { Msg_Party.Text = Fail(ex.Message); LogAdminError(ex); } }
private void DoDeletions(string address) { var found = false; found |= DeletionCount(States.UpdateEmailByEmail(Empty, address), address, "States.Email"); found |= DeletionCount(States.UpdateAltEmailByAltEmail(Empty, address), address, "States.AltEmail"); found |= DeletionCount(Counties.UpdateEmailByEmail(Empty, address), address, "Counties.Email"); found |= DeletionCount(Counties.UpdateAltEmailByAltEmail(Empty, address), address, "Counties.AltEmail"); found |= DeletionCount(LocalDistricts.UpdateEmailByEmail(Empty, address), address, "LocalDistricts.Email"); found |= DeletionCount(LocalDistricts.UpdateAltEmailByAltEmail(Empty, address), address, "LocalDistricts.AltEmail"); found |= DeletionCount(Politicians.UpdateEmailByEmail(null, address), address, "Politicians.Email"); found |= DeletionCount( Politicians.UpdateCampaignEmailByCampaignEmail(Empty, address), address, "Politicians.CampaignEmail"); found |= DeletionCount( Politicians.UpdateEmailVoteUSAByEmailVoteUSA(Empty, address), address, "Politicians.EmailVoteUSA"); found |= DeletionCount( Politicians.UpdateStateEmailByStateEmail(Empty, address), address, "Politicians.StateEmail"); if (Addresses.EmailExists(address)) { Addresses.DeleteByEmail(address); found |= DeletionCount(1, address, "Addresses"); } found |= DeletionCount(PartiesEmails.DeleteByPartyEmail(address), address, "PartiesEmails.PartyEmail"); found |= DeletionCount( OrganizationContacts.UpdateEmailByEmail(Empty, address), address, "OrganizationContacts.Email"); if (!found) { _Messages.Add($"<p class=\"error\">{address} not found</p>"); } }
protected void TextboxEmailAddress_TextChanged(object sender, EventArgs e) { try { CheckForDangerousInput(); Check_Email_Address_Empty(); var email = TextboxEmailAddress.Text.Trim(); PartiesEmails.UpdatePartyEmail(TextboxEmailAddress.Text.Trim().RemoveMailTo(), email); ViewState["EmailAddress"] = _EmailAddress = TextboxEmailAddress.Text.Trim().RemoveMailTo(); Load_Party_Data(); Load_Email_Data(TextboxEmailAddress.Text.Trim()); PartiesReport(); Msg_Party.Text = Ok("Email address was updated."); } catch (Exception ex) { Msg_Party.Text = Fail(ex.Message); LogAdminError(ex); } }
private void SubmitCallback(Dictionary <string, string> dict) { var email = dict["EmailFormFromEmailAddress"]; var isVolunteer = PartiesEmails.GetIsVolunteer(email); if (isVolunteer != null) // email exists { throw new VoteException(isVolunteer.Value ? "This email address is already registered to a volunteer" : "This email address is registered to a party official"); } var subject = dict["EmailFormSubject"]; var message = dict["EmailFormMessage"]; var firstName = dict["EmailFormFirstName"]; var lastName = dict["EmailFormLastName"]; var partyCode = dict["EmailFormParty"]; var stateCode = dict["EmailFormState"]; var phone = dict["EmailFormPhone"]; var password = dict["EmailFormPassword"]; var dateStamp = DateTime.UtcNow; if (IsNullOrWhiteSpace(password)) { password = MakeUniquePassword(); } // for email display EmailForm.SetOptionalValue("EmailFormParty", Parties.GetNationalPartyDescription(partyCode)); EmailForm.SetOptionalValue("EmailFormPassword", password); VolunteersView.Insert(email, password, stateCode + partyCode, firstName, lastName, phone); VolunteersNotes.Insert(email, dateStamp, subject); if (!IsNullOrWhiteSpace(message)) { VolunteersNotes.Insert(email, dateStamp.AddSeconds(1), message); } }
public void GetData(string partyKey) { DataTable = PartiesEmails.GetPartiesEmailReportData(partyKey); }
private static void HandleSignin(string usernameEntered, string passwordEntered) { // a null passwordEntered signals auto login var generalPassword = Security.GetUserPassword(usernameEntered); var politiciansPassword = Politicians.GetPassword(usernameEntered); var partiesPassword = PartiesEmails.GetPartyPassword(usernameEntered); // Get an array of all valid (non-null) passwords var validPasswords = (new[] { generalPassword, politiciansPassword, partiesPassword }).Where( pw => pw != null) .ToArray(); if (validPasswords.Length > 1) { // the username appeared in more than one security context HandleCredentialingInconsistency(usernameEntered, "Ambiguous usernname"); } var validPassword = passwordEntered == null || validPasswords.Length > 0 && validPasswords[0] == passwordEntered; if (validPasswords.Length == 0 || !validPassword) { throw new VoteException( "Your sign in failed. Please check your username and " + "password. If you believe they are correct and still cannot sign in, please " + "<a href=\"/Contact.aspx\">contact us</a>."); } // We now base the saved security on the user, not the page requested string userSecurityClass; if (politiciansPassword != null) { userSecurityClass = PoliticianSecurityClass; } else if (partiesPassword != null) { userSecurityClass = PartySecurityClass; } else { userSecurityClass = Security.GetUserSecurity(usernameEntered) .ToUpperInvariant(); } var superUser = userSecurityClass == MasterSecurityClass && Security.GetIsSuperUser(usernameEntered, false); InitializeSessionVariables(); SetSessionVariables(usernameEntered, userSecurityClass, superUser); CheckForFatalCredentialingProblems(usernameEntered); CorrectCredentialingInconsistencies(); if (passwordEntered != null) { LogSignIn(); } FormsAuthentication.RedirectFromLoginPage(usernameEntered, false); }
public static string LookupUpEmailSourceCode(string sourceCode) { var sourceType = sourceCode[0]; var subType = sourceCode[1]; var hyphenPos = sourceCode.IndexOf('-'); var stateCode = Empty; if (hyphenPos <= 0 || hyphenPos > 2 || sourceCode.Length < hyphenPos + 2) { return(null); } switch (sourceType) { case 'S': case 'C': case 'L': if (sourceCode.Length < 5) { return(null); } if (subType != 'P' && subType != 'A') { return(null); } stateCode = sourceCode.Substring(hyphenPos + 1, 2); hyphenPos = 4; if (!StateCache.IsValidStateCode(stateCode)) { return(null); } break; case 'P': if (subType != 'M' && subType != 'C' && subType != 'S' && subType != 'V') { return(null); } break; case 'A': case 'Z': case 'O': break; default: return(null); } var idString = sourceCode.Substring(hyphenPos + 1); if (!int.TryParse(idString, out var id) && sourceType != 'S') { return(null); } switch (sourceType) { case 'S': switch (subType) { case 'P': return(States.GetContactEmail(stateCode)); case 'A': return(States.GetAltEmail(stateCode)); } break; case 'C': switch (subType) { case 'P': return(Counties.GetContactEmail(stateCode, idString)); case 'A': return(Counties.GetAltEmail(stateCode, idString)); } break; case 'L': switch (subType) { case 'P': return(LocalDistricts.GetContactEmail(stateCode, idString)); case 'A': return(LocalDistricts.GetAltEmail(stateCode, idString)); } break; case 'P': switch (subType) { case 'M': return(Politicians.GetEmailById(id)); case 'C': return(Politicians.GetCampaignEmailById(id)); case 'S': return(Politicians.GetStateEmailById(id)); case 'V': return(Politicians.GetEmailVoteUSAById(id)); } break; case 'A': return(Addresses.GetEmailById(id)); case 'Z': return(PartiesEmails.GetPartyEmailById(id)); case 'O': return(OrganizationContacts.GetEmailByContactId(id)); } return(null); }