private void CreateMember() { // If youthOrg is true, then the person opted for youth league membership. bool youthOrgSelected = this.RadioYouthLeague.Checked || this.RadioYouthLeagueOnly.Checked == true; PaymentCode paymentCode = null; /* * // Payments disabled * * if (!youthOrgSelected) * { * paymentCode = PaymentCode.FromCode(this.TextPaymentCode.Text); * }*/ string name = this.TextName.Text; string password = ViewState["pw"] as string; string email = this.TextEmail.Text.Replace(",", "."); // for some reason 1 in 500 mistypes this string phone = this.TextPhone.Text; string street = this.TextStreet.Text; string postal = this.TextPostal.Text; string city = this.TextCity.Text; string countryCode = this.DropCountries.SelectedValue; int birthDay = Convert.ToInt32(this.TextBirthDay.Text); int birthMonth = Convert.ToInt32(this.DropBirthMonths.SelectedValue); int birthYear = Convert.ToInt32(this.TextBirthYear.Text); DateTime birthdate = new DateTime(birthYear, birthMonth, birthDay); PersonGender gender = (PersonGender)Enum.Parse(typeof(PersonGender), this.DropGenders.SelectedValue); // This will stop the Create to be called twice even if doubleclick SessionMemberDuplicateStop = DateTime.Now;; // We are ready to create the new person. Person person = Person.Create(name, email, password, phone, street, postal, city, countryCode, birthdate, gender); // The creation resolves the appropriate geography, so we can determine the correct // organization to join the person to. // In some cases PostalCode does not indicate the geography uniquely if (DropDownKommun.SelectedIndex >= 0) { person.Geography = Geography.FromIdentity(int.Parse(DropDownKommun.SelectedValue)); } // Add memberships, as appropriate. Organization youthOrg = null; this.LabelMemberOfOrganizations.Text = string.Empty; if (youthOrgSelected) { try { youthOrg = Organizations.GetMostLocalOrganization(person.GeographyId, Organization.UPDKid); } catch (ArgumentException ex) { //didnt find any, Does the org itself accept members? youthOrg = Organization.FromIdentity(Organization.UPDKid); if (!youthOrg.AcceptsMembers) { throw ex; //rethrow } } Activizr.Logic.Pirates.Membership newMembership = person.AddMembership(youthOrg.Identity, DateTime.Now.AddYears(1)); newMembership.SetPaymentStatus(MembershipPaymentStatus.NewlyRegistered, DateTime.Now); this.LabelMemberOfOrganizations.Text = "<br><b>" + Server.HtmlEncode(youthOrg.Name) + "</b> og <br/>"; } if (!this.RadioYouthLeagueOnly.Checked) { person.AddMembership(Organization.PPDKid, DateTime.Now.AddYears(1)); this.LabelMemberOfOrganizations.Text += "<b>Piratpartiet</b>"; } // Create events. if (RadioYouthLeague.Checked) { Activizr.Logic.Support.PWEvents.CreateEvent(EventSource.SignupPage, EventType.AddedMember, person.Identity, youthOrg.Identity, person.GeographyId, person.Identity, 0, youthOrg.Identity.ToString() + " " + Organization.PPDKid.ToString() + "," + Request.UserHostAddress + "," + this.LabelReferrer.Text); PWLog.Write(PWLogItem.Person, person.Identity, PWLogAction.MemberAdd, "New member joined organization " + youthOrg.NameShort + " and Piratpartiet DK.", "The self-signup came from IP address " + Request.UserHostAddress + "."); } else if (RadioYouthLeagueOnly.Checked) { Activizr.Logic.Support.PWEvents.CreateEvent(EventSource.SignupPage, EventType.AddedMember, person.Identity, youthOrg.Identity, person.GeographyId, person.Identity, 0, youthOrg.Identity.ToString() + "," + Request.UserHostAddress + "," + this.LabelReferrer.Text); PWLog.Write(PWLogItem.Person, person.Identity, PWLogAction.MemberAdd, "New member joined organizations " + youthOrg.NameShort, "The self-signup came from IP address " + Request.UserHostAddress + "."); } else { Activizr.Logic.Support.PWEvents.CreateEvent(EventSource.SignupPage, EventType.AddedMember, person.Identity, Organization.PPDKid, person.GeographyId, person.Identity, 0, Organization.PPDKid.ToString() + "," + Request.UserHostAddress + "," + this.LabelReferrer.Text); PWLog.Write(PWLogItem.Person, person.Identity, PWLogAction.MemberAdd, "New member joined Piratpartiet DK.", "The self-signup came from IP address " + Request.UserHostAddress + "."); } // Claim the payment. if (paymentCode != null) { paymentCode.Claim(person); } // If activity level was not passive (activist or officer), then register as activist. if (!this.RadioActivityPassive.Checked) { person.CreateActivist(false, false); Activizr.Logic.Support.PWEvents.CreateEvent(EventSource.SignupPage, EventType.NewActivist, person.Identity, Organization.PPDKid, person.GeographyId, person.Identity, 0, string.Empty); PWLog.Write(PWLogItem.Person, person.Identity, PWLogAction.MemberAdd, "Joined as activist.", string.Empty); } // If activity level was officer, register as officer volunteer. if (this.RadioActivityOfficer.Checked) { int[] chairman = Authorization.PersonsWithRoleInOrg(RoleType.OrganizationChairman, Organization.PPFIid, false); if (chairman.Length > 0) { Person defaultOwner = Person.FromIdentity(chairman[0]); Volunteer volunteer = Volunteer.Create(person, defaultOwner); // RF owns new volunteers //Autoassign will try to assign to ElectoralCircuit lead or //if not possible, to its parent org lead, or if not possible to defaultOwner //TODO:Ugly hack sweden hardcoded (30) volunteer.AutoAssign(person.Geography, Organization.PPDKid, defaultOwner, Geography.SwedenId); volunteer.AddRole(Organization.PPDKid, person.GeographyId, RoleType.LocalLead); volunteer.AddRole(Organization.PPDKid, person.GeographyId, RoleType.LocalDeputy); volunteer.AddRole(Organization.PPDKid, person.GeographyId, RoleType.LocalAdmin); string textParameter = person.Name.Replace("|", "") + "|" + person.Phone.Replace("|", "") + "|Yes|KL1 KL2 KLA"; Activizr.Logic.Support.PWEvents.CreateEvent(EventSource.SignupPage, EventType.NewVolunteer, 0, Organization.PPDKid, person.GeographyId, 0, 0, textParameter); PWLog.Write(PWLogItem.Person, person.Identity, PWLogAction.MemberAdd, "Volunteered for local officership.", string.Empty); } } }
private void CreateMember() { bool youthOrgSelected = this.cbYouthOnly.Checked; bool partyOrgSelected = this.cbParty.Checked; bool localOrgSelected = this.cbPartyAndLocal.Checked && partyOrgSelected; int partyOrgID = Organization.PPFIid; int youthOrgID = Organization.UPFIid;//Not yet defined PaymentCode paymentCode = null; /* * // Payments disabled * * if (!youthOrgSelected) * { * paymentCode = PaymentCode.FromCode(this.TextPaymentCode.Text); * }*/ string name = this.TextName.Text; string password = ViewState["pw"] as string; string email = this.TextEmail.Text.Replace(",", "."); // for some reason 1 in 500 mistypes this string phone = this.TextPhone.Text; string street = this.TextStreet.Text; string postal = this.TextPostal.Text; string city = this.TextCity.Text; string countryCode = this.DropCountries.SelectedValue; int birthDay = Convert.ToInt32(this.TextBirthDay.Text); int birthMonth = Convert.ToInt32(this.DropBirthMonths.SelectedValue); int birthYear = Convert.ToInt32(this.TextBirthYear.Text); DateTime birthdate = new DateTime(birthYear, birthMonth, birthDay); PersonGender gender = (PersonGender)Enum.Parse(typeof(PersonGender), this.DropGenders.SelectedValue); // This will stop the Create to be called twice even if doubleclick SessionMemberDuplicateStop = DateTime.Now;; // We are ready to create the new person. People people = People.FromEmail(email); // already in db? Person person = null; foreach (Person p in people) { if (p.Birthdate == birthdate) { person = p; } } if (person != null) { person.TempPasswordHash = person.PasswordHash;//save it, but dont trash the existing one Authentication.RequestMembershipConfirmation(person, "https://pirateweb.net/Pages/Public/FI/People/ConfirmMembership.aspx?member={0}&ticket={1}"); } else { person = Person.Create(name, email, Formatting.GeneratePassword(9), phone, street, postal, city, countryCode, birthdate, gender); person.SetPassword(password); //set the given password person.TempPasswordHash = person.PasswordHash; //save it. person.SetPassword(Formatting.GeneratePassword(9)); //Generate a random one. Authentication.RequestMembershipConfirmation(person, "https://pirateweb.net/Pages/Public/FI/People/ConfirmMembership.aspx?member={0}&ticket={1}"); } // The creation resolves the appropriate geography, so we can determine the correct // organization to join the person to. // In some cases PostalCode does not indicate the geography uniquely if (DropDownKommun.SelectedIndex >= 0) { person.Geography = Geography.FromIdentity(int.Parse(DropDownKommun.SelectedValue)); } if (person.GeographyId == 0) { person.Geography = Geography.FromIdentity(Geography.FinlandId); } // Add memberships, as appropriate. Organization youthOrg = null; Organization localPartyOrg = null; Organization partyOrg = null; this.LabelMemberOfOrganizations.Text = string.Empty; if (youthOrgSelected) { try { youthOrg = Organizations.GetMostLocalOrganization(person.GeographyId, youthOrgID); } catch (ArgumentException ex) { //didnt find any, Does the org itself accept members? youthOrg = Organization.FromIdentity(youthOrgID); if (!youthOrg.AcceptsMembers) { throw ex; //rethrow } } this.LabelMemberOfOrganizations.Text += "<br><b>" + Server.HtmlEncode(youthOrg.Name) + "</b>, <br/>"; if (!person.MemberOf(youthOrg.Identity)) { Activizr.Logic.Pirates.Membership newMembership = person.AddMembership(youthOrg.Identity, DateTime.Now.AddYears(100)); newMembership.SetPaymentStatus(MembershipPaymentStatus.NewlyRegistered, DateTime.Now); } else { youthOrg = null; } } bool wasPartyMember = false; if (localOrgSelected) { try { // localPartyOrg = Organizations.GetMostLocalOrganization(person.GeographyId, partyOrgID); localPartyOrg = Organization.FromIdentity(Convert.ToInt32(DropDownListSubOrg.SelectedValue)); this.LabelMemberOfOrganizations.Text += "<br><b>" + Server.HtmlEncode(localPartyOrg.Name) + "</b>, <br/>"; if (!person.MemberOf(localPartyOrg.Identity)) { Activizr.Logic.Pirates.Membership newMembership = person.AddMembership(localPartyOrg.Identity, DateTime.Now.AddYears(100)); newMembership.SetPaymentStatus(MembershipPaymentStatus.NewlyRegistered, DateTime.Now); } else { localPartyOrg = null; } } catch { //Asked for local org but didnt give enoght data } } if (partyOrgSelected && (wasPartyMember == false)) { if (!person.MemberOf(partyOrgID)) { Activizr.Logic.Pirates.Membership newMembership = person.AddMembership(partyOrgID, DateTime.Now.AddYears(100)); newMembership.SetPaymentStatus(MembershipPaymentStatus.NewlyRegistered, DateTime.Now); partyOrg = Organization.FromIdentity(partyOrgID); this.LabelMemberOfOrganizations.Text += "<br><b>" + Server.HtmlEncode(partyOrg.Name) + "</b>, <br/>"; } else { partyOrg = Organization.FromIdentity(partyOrgID); this.LabelMemberOfOrganizations.Text += "<br><b>" + Server.HtmlEncode(partyOrg.Name) + "</b>, <br/>"; partyOrg = null; } } // Create events. if (localPartyOrg != null || youthOrg != null || partyOrg != null) { if (localPartyOrg != null) { Activizr.Logic.Support.PWEvents.CreateEvent(EventSource.SignupPage, EventType.AddedMember, person.Identity, localPartyOrg.Identity, person.GeographyId, person.Identity, 0, localPartyOrg.Identity.ToString() + "," + Request.UserHostAddress + "," + this.LabelReferrer.Text); } if (youthOrg != null) { Activizr.Logic.Support.PWEvents.CreateEvent(EventSource.SignupPage, EventType.AddedMember, person.Identity, youthOrg.Identity, person.GeographyId, person.Identity, 0, youthOrg.Identity.ToString() + "," + Request.UserHostAddress + "," + this.LabelReferrer.Text); } if (partyOrg != null) { Activizr.Logic.Support.PWEvents.CreateEvent(EventSource.SignupPage, EventType.AddedMember, person.Identity, partyOrg.Identity, person.GeographyId, person.Identity, 0, partyOrg.Identity.ToString() + "," + Request.UserHostAddress + "," + this.LabelReferrer.Text); } PWLog.Write(PWLogItem.Person, person.Identity, PWLogAction.MemberAdd, "New member joined organization " + (youthOrg != null ? youthOrg.NameShort + " " : "") + (localPartyOrg != null ? localPartyOrg.NameShort + " " : "") + (partyOrg != null ? partyOrg.NameShort : ""), "The self-signup came from IP address " + Request.UserHostAddress + "."); } // Claim the payment. if (paymentCode != null) { paymentCode.Claim(person); } // If activity level was not passive (activist or officer), then register as activist. if (!this.RadioActivityPassive.Checked) { person.CreateActivist(false, false); Activizr.Logic.Support.PWEvents.CreateEvent(EventSource.SignupPage, EventType.NewActivist, person.Identity, partyOrgID, person.GeographyId, person.Identity, 0, string.Empty); PWLog.Write(PWLogItem.Person, person.Identity, PWLogAction.MemberAdd, "Joined as activist.", string.Empty); } // If activity level was officer, register as officer volunteer. if (this.RadioActivityOfficer.Checked) { int[] chairman = Authorization.PersonsWithRoleInOrg(RoleType.OrganizationChairman, Organization.PPFIid, false); if (chairman.Length > 0) { Person defaultOwner = Person.FromIdentity(chairman[0]); Volunteer volunteer = Volunteer.Create(person, defaultOwner); // RF owns new volunteers //Autoassign will try to assign to ElectoralCircuit lead or //if not possible, to its parent org lead, or if not possible to defaultOwner volunteer.AutoAssign(person.Geography, Organization.PPFIid, defaultOwner, Geography.FinlandId); volunteer.AddRole(Organization.PPFIid, person.GeographyId, RoleType.LocalLead); volunteer.AddRole(Organization.PPFIid, person.GeographyId, RoleType.LocalDeputy); volunteer.AddRole(Organization.PPFIid, person.GeographyId, RoleType.LocalAdmin); string textParameter = person.Name.Replace("|", "") + "|" + person.Phone.Replace("|", "") + "|Yes|KL1 KL2 KLA"; Activizr.Logic.Support.PWEvents.CreateEvent(EventSource.SignupPage, EventType.NewVolunteer, 0, Organization.PPFIid, person.GeographyId, 0, 0, textParameter); PWLog.Write(PWLogItem.Person, person.Identity, PWLogAction.MemberAdd, "Volunteered for local officership.", string.Empty); } } }