示例#1
0
        // This should run daily, suggested right after midnight.

        public static void ChurnExpiredMembers()
        {
            Organizations organizations = Organizations.GetAll();

            foreach (Organization organization in organizations)
            {
                Memberships memberships = Memberships.GetExpired(organization);
                // Mail each expiring member

                foreach (Membership membership in memberships)
                {
                    //only remove expired memberships
                    if (membership.Expires > DateTime.Now.Date)
                    {
                        continue;
                    }

                    Person person = membership.Person;

                    // Remove all roles and responsibilities for this person in the org

                    Authority authority = person.GetAuthority();

                    foreach (BasicPersonRole basicRole in authority.LocalPersonRoles)
                    {
                        PersonRole personRole = PersonRole.FromBasic(basicRole);
                        if (personRole.OrganizationId == membership.OrganizationId)
                        {
                            PWEvents.CreateEvent(EventSource.PirateBot, EventType.DeletedRole, person.Identity,
                                                 personRole.OrganizationId, personRole.GeographyId, person.Identity,
                                                 (int)personRole.Type,
                                                 string.Empty);
                            personRole.Delete();
                        }
                    }

                    // Mail

                    Memberships personMemberships   = person.GetMemberships();
                    Memberships membershipsToDelete = new Memberships();
                    foreach (Membership personMembership in personMemberships)
                    {
                        if (personMembership.Expires <= DateTime.Now.Date)
                        {
                            membershipsToDelete.Add(personMembership);
                        }
                    }


                    ExpiredMail expiredmail    = new ExpiredMail();
                    string      membershipsIds = "";

                    if (membershipsToDelete.Count > 1)
                    {
                        foreach (Membership personMembership in membershipsToDelete)
                        {
                            membershipsIds += "," + personMembership.MembershipId;
                        }
                        membershipsIds = membershipsIds.Substring(1);
                        string expiredMemberships = "";
                        foreach (Membership personMembership in membershipsToDelete)
                        {
                            if (personMembership.OrganizationId != organization.Identity)
                            {
                                expiredMemberships += ", " + personMembership.Organization.Name;
                            }
                        }
                        expiredMemberships      += ".  ";
                        expiredmail.pMemberships = expiredMemberships.Substring(2).Trim();
                    }

                    //TODO: URL for renewal, recieving end of this is NOT yet implemented...
                    // intended to recreate the memberships in MID
                    string tokenBase = person.PasswordHash + "-" + membership.Expires.Year;
                    string stdLink   = "https://pirateweb.net/Pages/Public/SE/People/MemberRenew.aspx?MemberId=" +
                                       person.Identity +
                                       "&SecHash=" + SHA1.Hash(tokenBase).Replace(" ", "").Substring(0, 8) +
                                       "&MID=" + membershipsIds;

                    expiredmail.pStdRenewLink = stdLink;
                    expiredmail.pOrgName      = organization.MailPrefixInherited;

                    person.SendNotice(expiredmail, organization.Identity);

                    person.DeleteSubscriptionData();

                    string orgIdString = string.Empty;

                    foreach (Membership personMembership in membershipsToDelete)
                    {
                        if (personMembership.Active)
                        {
                            orgIdString += " " + personMembership.OrganizationId;

                            personMembership.Terminate(EventSource.PirateBot, null, "Member churned in housekeeping.");
                        }
                    }
                }
            }
        }
示例#2
0
        // This should run daily, suggested right after midnight.

        public static void ChurnExpiredMembers()
        {
            Organizations organizations = Organizations.GetAll();

            foreach (Organization organization in organizations)
            {
                Participations participations = Participations.GetExpired(organization);
                // Mail each expiring member

                foreach (Participation membership in participations)
                {
                    //only remove expired memberships
                    if (membership.Expires > DateTime.Now.Date)
                    {
                        continue;
                    }

                    Person person = membership.Person;

                    // TODO: Check for positions that expire with membership


                    // Mail

                    Participations personParticipations   = person.GetParticipations();
                    Participations participationsToDelete = new Participations();
                    foreach (Participation personMembership in personParticipations)
                    {
                        if (personMembership.Expires <= DateTime.Now.Date)
                        {
                            participationsToDelete.Add(personMembership);
                        }
                    }


                    ExpiredMail expiredmail    = new ExpiredMail();
                    string      membershipsIds = "";

                    if (participationsToDelete.Count > 1)
                    {
                        foreach (Participation personMembership in participationsToDelete)
                        {
                            membershipsIds += "," + personMembership.MembershipId;
                        }
                        membershipsIds = membershipsIds.Substring(1);
                        string expiredMemberships = "";
                        foreach (Participation personMembership in participationsToDelete)
                        {
                            if (personMembership.OrganizationId != organization.Identity)
                            {
                                expiredMemberships += ", " + personMembership.Organization.Name;
                            }
                        }
                        expiredMemberships      += ".  ";
                        expiredmail.pMemberships = expiredMemberships.Substring(2).Trim();
                    }

                    //TODO: URL for renewal, recieving end of this is NOT yet implemented...
                    // intended to recreate the memberships in MID
                    string tokenBase = person.PasswordHash + "-" + membership.Expires.Year;
                    string stdLink   = "https://pirateweb.net/Pages/Public/SE/People/MemberRenew.aspx?MemberId=" +
                                       person.Identity +
                                       "&SecHash=" + SHA1.Hash(tokenBase).Replace(" ", "").Substring(0, 8) +
                                       "&MID=" + membershipsIds;

                    expiredmail.pStdRenewLink = stdLink;
                    expiredmail.pOrgName      = organization.MailPrefixInherited;

                    person.SendNotice(expiredmail, organization.Identity);

                    person.DeleteSubscriptionData();

                    string orgIdString = string.Empty;

                    foreach (Participation personMembership in participationsToDelete)
                    {
                        if (personMembership.Active)
                        {
                            orgIdString += " " + personMembership.OrganizationId;

                            personMembership.Terminate(EventSource.PirateBot, null, "Member churned in housekeeping.");
                        }
                    }
                }
            }
        }