예제 #1
0
    protected void ButtonSubmit_Click(object sender, EventArgs e)
    {
        string    responsibilities = string.Empty;
        Geography geography        = Geography.FromIdentity(Int32.Parse(this.DropGeographies.SelectedValue));

        // Find: is this an existing person?

        Person person = null;

        //TODO: Hardcoded countrycode = 1
        People people = People.FromPhoneNumber(1, this.TextPhone.Text);

        if (people.Count == 1)
        {
            if (people[0].Name.ToLower() == this.TextName.Text.ToLower())
            {
                person = people[0];
            }
        }

        // If not, create one for this purpose

        if (person == null)
        {
            person           = Person.Create(this.TextName.Text, string.Empty, string.Empty, this.TextPhone.Text, string.Empty, string.Empty, string.Empty, "SE", DateTime.Now, PersonGender.Unknown);
            person.Geography = geography;
        }
        Person    defaultOwner = Person.FromIdentity(1);
        Volunteer volunteer    = Volunteer.Create(person, defaultOwner); // RF owns new volunteers

        if (this.CheckKL1.Checked)
        {
            responsibilities += " KL1";
            volunteer.AddRole(Organization.PPSEid, geography.Identity, RoleType.LocalLead);
        }

        if (this.CheckKL2.Checked)
        {
            responsibilities += " KL2";
            volunteer.AddRole(Organization.PPSEid, geography.Identity, RoleType.LocalDeputy);
        }


        // Move "geography" up to electoral circuit level
        while ((!geography.AtLevel(GeographyLevel.ElectoralCircuit)) && (geography.Parent != null))
        {
            geography = geography.Parent;
        }

        //Autoassign will try to assign to ElectoralCircuit lead or
        //if not possible, to its parent org lead, or if not possible to defaultOwner
        //TODO:Hardcoded sweden(30)
        volunteer.AutoAssign(geography, Organization.PPSEid, defaultOwner, Geography.SwedenId);

        if (this.CheckVL1.Checked)
        {
            responsibilities += " VL1";
            volunteer.AddRole(Organization.PPSEid, geography.Identity, RoleType.LocalLead);
        }

        if (this.CheckVL2.Checked)
        {
            responsibilities += " VL2";
            volunteer.AddRole(Organization.PPSEid, geography.Identity, RoleType.LocalDeputy);
        }

        responsibilities = responsibilities.Trim();

        string textParameter = this.TextName.Text.Replace("|", "") + "|" + this.TextPhone.Text.Replace("|", "") + "|" + this.DropMember.SelectedValue + "|" + responsibilities;

        Activizr.Logic.Support.PWEvents.CreateEvent(EventSource.SignupPage, EventType.NewVolunteer, 0, Organization.PPSEid, Int32.Parse(this.DropGeographies.SelectedValue), 0, 0, textParameter);

        this.TextName.Enabled        = false;
        this.TextPhone.Enabled       = false;
        this.DropGeographies.Enabled = false;
        this.DropMember.Enabled      = false;
        this.CheckKL1.Enabled        = false;
        this.CheckKL2.Enabled        = false;
        this.CheckVL1.Enabled        = false;
        this.CheckVL2.Enabled        = false;
        this.ButtonSubmit.Enabled    = false;

        this.PanelFinished.Visible = true;
    }
예제 #2
0
    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);
            }
        }
    }
예제 #3
0
    protected void Wizard_NextButtonClick(object sender, WizardNavigationEventArgs e)
    {
        // Validate data for the various steps, or (on page 4) finalize the membership.


        // -------------------------------------
        // VALIDATE PAGE: CHOICE OF ORGANIZATION
        // -------------------------------------

        if (e.CurrentStepIndex == 0)
        {
            // Validate the choice of organization.

            if (this.RadioParty.Checked == false && this.RadioYouthLeague.Checked == false)
            {
                this.LabelOrganizationError.Text = "Du m&aring;ste v&auml;lja en organisation!";
                e.Cancel = true;
            }
            else
            {
                this.LabelOrganizationError.Text = string.Empty; // Clear on success
            }

            // If youth league is selected, make sure that the payment page is skipped.

            if (this.RadioYouthLeague.Checked == true)
            {
                this.LabelSmsMessageText.Text = "PP UNG";
                this.LabelOrganization.Text   = "Ung Pirat (och Piratpartiet, som du blir medlem i samtidigt)";
                Wizard.ActiveStepIndex        = 2; // Remove this on 2007 expiry

                // Set the focus to the name control on the member details page.

                this.TextName.Focus();
            }

            else if (this.RadioParty.Checked == true)
            {
                this.LabelSmsMessageText.Text = "PP MEDLEM";
                this.LabelOrganization.Text   = "Piratpartiet";

                Wizard.ActiveStepIndex = 2; // Zero cost payment

                // Set the focus to the payment code control.

                this.TextPaymentCode.Focus();
            }
        }


        // ---------------------------
        // VALIDATE PAGE: PAYMENT CODE
        // ---------------------------

        if (e.CurrentStepIndex == 1)
        {
            // Validate the payment code page.

            PaymentCode code = null;

            try
            {
                code = PaymentCode.FromCode(this.TextPaymentCode.Text.Trim());
            }
            catch (Exception)
            {
                // If we can't get the payment code, it will remain null, which is fine.
            }

            if (code == null || code.Claimed)
            {
                this.LabelPaymentError.Text = "Hittar inte kvittokoden!";
                e.Cancel = true;
            }
            else
            {
                this.LabelPaymentError.Text = string.Empty; // Clear on success

                if (code.IssuedToPhoneNumber.Length > 0)
                {
                    this.TextPhone.Text = code.IssuedToPhoneNumber;
                }
            }

            // Set the focus to the name control on the member details page.

            this.TextName.Focus();
        }


        // -----------------------------
        // VALIDATE PAGE: MEMBER DETAILS
        // -----------------------------

        if (e.CurrentStepIndex == 2)
        {
            // Validate member details. This is going to be quite a long validation.

            // Check for errors.

            // Name

            if (this.TextName.Text.Length < 3 || !this.TextName.Text.Contains(" "))
            {
                this.LabelNameError.Visible = true;
                e.Cancel = true;
            }

            // Street

            if (this.TextStreet.Text.Length < 4)
            {
                this.LabelStreetError.Visible = true;
                e.Cancel = true;
            }

            // Postal code & city -- also validate postal code length for given country

            if (this.TextPostal.Text.Length < 4)
            {
                this.LabelPostalError.Text    = "Skriv postnummer";
                this.LabelPostalError.Visible = true;
                e.Cancel = true;
            }
            else
            {
                Country country = Country.FromCode(DropCountries.SelectedValue);

                if (country.PostalCodeLength != 0)
                {
                    string postalCode = this.TextPostal.Text;
                    postalCode = postalCode.Replace(" ", "");
                    if (postalCode.Length != country.PostalCodeLength)
                    {
                        this.LabelPostalError.Visible = true;
                        e.Cancel = true;
                    }
                }
            }
            if (this.TextCity.Text.Length < 3 && this.LabelPostalError.Text.Length < 2)
            {
                this.LabelCityError.Visible = true;
                e.Cancel = true;
            }

            // Phone number

            if (this.TextPhone.Text.Length < 7)
            {
                this.LabelPhoneError.Visible = true;
                e.Cancel = true;
            }

            // Email

            this.TextEmail.Text = this.TextEmail.Text.Trim();
            if (this.TextEmail.Text.Length < 5)
            {
                this.LabelEmailError.Visible = true;
                e.Cancel = true;
            }
            else if (!Formatting.ValidateEmailFormat(this.TextEmail.Text))
            {
                this.LabelEmailError.Visible = true;
                e.Cancel = true;
            }


            // Birthdate

            try
            {
                int day   = Convert.ToInt32(this.TextBirthDay.Text);
                int year  = Convert.ToInt32(this.TextBirthYear.Text);
                int month = Convert.ToInt32(this.DropBirthMonths.SelectedValue);

                DateTime test = new DateTime(year, month, day);

                if (test > DateTime.Now)
                {
                    throw new Exception("No, you can't be born on a future date.");
                }

                if (test < DateTime.Now.AddYears(-125))
                {
                    throw new Exception("And you're not over 125 years old, either.");
                }
            }
            catch (Exception)
            {
                this.LabelBirthdateError.Visible = true;
                e.Cancel = true;
            }

            // Gender

            try
            {
                PersonGender gender = (PersonGender)Enum.Parse(typeof(PersonGender), this.DropGenders.SelectedValue);

                if (gender == PersonGender.Unknown)
                {
                    throw new Exception(); // Gender not selected - just throw something to produce the error message.
                }
            }
            catch (Exception)
            {
                this.LabelGenderError.Text = "V&auml;lj k&ouml;n";
                e.Cancel = true;
            }


            if (!e.Cancel)
            {
                this.TextPassword1.Focus();
            }
        }



        // ---------------------------------
        // VALIDATE PAGE: PIRATEWEB PASSWORD
        // ---------------------------------

        if (e.CurrentStepIndex == 3 && DateTime.Now.Subtract(SessionMemberDuplicateStop).TotalSeconds > 2)
        {
            string password1 = this.TextPassword1.Text;
            string password2 = this.TextPassword2.Text;

            if (password1 != password2)
            {
                this.LabelPasswordErrorSame.Visible = true;
                e.Cancel = true;
            }
            else if (password1 == string.Empty)
            {
                this.LabelPasswordError.Visible = true;
                e.Cancel = true;
            }
            else if (password1.Length < 5)
            {
                this.LabelPasswordErrorLength.Visible = true;
                e.Cancel = true;
            }

            if (e.Cancel == true)
            {
                this.TextPassword1.Focus(); // Set focus to first (now empty) text box
            }
            ViewState["pw"] = password1;
        }

        if (e.CurrentStepIndex == 4 && DateTime.Now.Subtract(SessionMemberDuplicateStop).TotalSeconds > 2)
        {
            // This is the final page. When we get here, all data is good. This code
            // creates and commits the member.

            // If youthOrg is true, then the person opted for youth league membership.

            bool youthOrgSelected = this.RadioYouthLeague.Checked;

            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);

            // Tis 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)
            {
                youthOrg = Organizations.GetMostLocalOrganization(person.GeographyId, Organization.UPSEid);
                person.AddMembership(youthOrg.Identity, DateTime.Now.AddYears(1));
                this.LabelMemberOfOrganizations.Text = "<b>" + Server.HtmlEncode(youthOrg.Name) + "</b> och<br/>";
            }

            person.AddMembership(Organization.PPSEid, DateTime.Now.AddYears(1));
            this.LabelMemberOfOrganizations.Text += "<b>Piratpartiet</b>";

            // Create events.

            if (youthOrgSelected)
            {
                Activizr.Logic.Support.PWEvents.CreateEvent(EventSource.SignupPage, EventType.AddedMember,
                                                            person.Identity, youthOrg.Identity, person.GeographyId, person.Identity, 0, youthOrg.Identity.ToString() + " " + Organization.PPSEid.ToString() + "," + Request.UserHostAddress + "," + this.LabelReferrer.Text);
                PWLog.Write(PWLogItem.Person, person.Identity, PWLogAction.MemberAdd, "New member joined organizations " + youthOrg.NameShort + " and Piratpartiet SE.", "The self-signup came from IP address " + Request.UserHostAddress + ".");
            }
            else
            {
                Activizr.Logic.Support.PWEvents.CreateEvent(EventSource.SignupPage, EventType.AddedMember,
                                                            person.Identity, Organization.PPSEid, person.GeographyId, person.Identity, 0, Organization.PPSEid.ToString() + "," + Request.UserHostAddress + "," + this.LabelReferrer.Text);
                PWLog.Write(PWLogItem.Person, person.Identity, PWLogAction.MemberAdd, "New member joined Piratpartiet SE.", "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.PPSEid, 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)
            {
                Person    defaultOwner = Person.FromIdentity(1);
                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.PPSEid, defaultOwner, Geography.SwedenId);

                volunteer.AddRole(Organization.PPSEid, person.GeographyId, RoleType.LocalLead);
                volunteer.AddRole(Organization.PPSEid, person.GeographyId, RoleType.LocalDeputy);
                volunteer.AddRole(Organization.PPSEid, 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.PPSEid, person.GeographyId, 0, 0, textParameter);
                PWLog.Write(PWLogItem.Person, person.Identity, PWLogAction.MemberAdd, "Volunteered for local officership.", string.Empty);
            }
            Wizard.ActiveStepIndex = 6;
        }
        if (e.CurrentStepIndex == 5)
        {
            Wizard.ActiveStepIndex = 0;
        }
    }
예제 #4
0
    private void CompleteSignup()
    {
        string name        = this.TextFirstName.Text + "|" + this.TextLastName.Text;
        string password    = ViewState["pwpass"] as string;
        string email       = this.TextEmail.Text.Replace(",", "."); // for some reason 1 in 500 mistypes this, even with repeats
        string phone       = this.TextPhone.Text;
        string street      = this.TextStreet.Text;
        string postal      = this.TextPostalCode.Text;
        string city        = this.TextCity.Text;
        string countryCode = this.DropCountries.SelectedValue;

        int birthDay   = Convert.ToInt32(this.DropBirthDay.SelectedValue);
        int birthMonth = Convert.ToInt32(this.DropBirthMonth.SelectedValue);
        int birthYear  = Convert.ToInt32(this.DropBirthYear.SelectedValue);

        DateTime     birthdate = new DateTime(birthYear, birthMonth, birthDay);
        PersonGender gender    = (PersonGender)Enum.Parse(typeof(PersonGender), this.DropGenders.SelectedValue);

        // 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 (DropGeographies.SelectedIndex >= 0)
        {
            person.Geography = Geography.FromIdentity(int.Parse(DropGeographies.SelectedValue));
        }
        else
        {
            person.Geography = Country.FromCode(countryCode).Geography;
        }

        person.AddMembership(Organization.PPSEid, DateTime.Now.AddYears(1));
        Activizr.Logic.Support.PWEvents.CreateEvent(EventSource.SignupPage, EventType.AddedMember,
                                                    person.Identity, Organization.PPSEid, person.GeographyId, person.Identity, 0, Organization.PPSEid.ToString() + "," + Request.UserHostAddress + "," + ViewState["Referrer"] as string);
        PWLog.Write(PWLogItem.Person, person.Identity, PWLogAction.MemberAdd, "New member joined Piratpartiet SE.", "The self-signup came from IP address " + Request.UserHostAddress + ".");

        // 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.PPSEid, 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)
        {
            Person    defaultOwner = Person.FromIdentity(1);
            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.PPSEid, defaultOwner, Geography.SwedenId);

            volunteer.AddRole(Organization.PPSEid, person.GeographyId, RoleType.LocalLead);
            volunteer.AddRole(Organization.PPSEid, person.GeographyId, RoleType.LocalDeputy);
            volunteer.AddRole(Organization.PPSEid, person.GeographyId, RoleType.LocalAdmin);

            // TODO: Add more specifics about how the volunteer would like to work.

            string textParameter = person.Name.Replace("|", "") + "|" +
                                   person.Phone.Replace("|", "") +
                                   "|Yes|KL1 KL2 KLA";

            Activizr.Logic.Support.PWEvents.CreateEvent(EventSource.SignupPage, EventType.NewVolunteer, 0, Organization.PPSEid, person.GeographyId, 0, 0, textParameter);
            PWLog.Write(PWLogItem.Person, person.Identity, PWLogAction.MemberAdd, "Volunteered for local officership.", string.Empty);
        }

        // If Ung Pirat was checked, process.

        if (this.CheckUngPirat.Checked)
        {
            Organization youthOrg = Organizations.GetMostLocalOrganization(person.GeographyId, Organization.UPSEid);
            person.AddMembership(youthOrg.Identity, DateTime.Now.AddYears(1));
            Activizr.Logic.Support.PWEvents.CreateEvent(EventSource.SignupPage, EventType.AddedMember,
                                                        person.Identity, youthOrg.Identity, person.GeographyId,
                                                        person.Identity, 0,
                                                        youthOrg.Identity.ToString() + " " +
                                                        Organization.PPSEid.ToString() + "," +
                                                        Request.UserHostAddress + "," + ViewState["Referrer"] as string);
            PWLog.Write(PWLogItem.Person, person.Identity, PWLogAction.MemberAdd,
                        "New member joined organization " + youthOrg.NameShort + ".",
                        "The self-signup came from IP address " + Request.UserHostAddress + ".");
        }
    }
예제 #5
0
    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);
            }
        }
    }