コード例 #1
0
    protected void Page_Load (object sender, EventArgs e)
    {
        bool success = false;
        string expectedHash1 = "";
        string expectedHash2 = "";
        Person person = null;
        string redirectUrl = string.Empty;

        int personId = 0;

        //New or old variant? MemberId indicates old variant with common date for all orgs.
        if (Int32.TryParse(Request.QueryString["MemberId"], out personId))
        {
            // Ok, at least we have  a valid person id.

            person = Person.FromIdentity(personId);

            DateTime currentExpiry = DateTime.MaxValue;
            DateTime newExpiry = DateTime.MinValue;
            Memberships memberships = person.GetRecentMemberships(Membership.GracePeriod);
            string[] mIds = ("" + Request.QueryString["MID"]).Split(',');
            bool membershipExists = false;
            Membership membershipToExtend = null;
            if (mIds.Length > 0)
            {
                memberships = new Memberships();
                foreach (string mId in mIds)
                {
                    try
                    {
                        Membership membership = Membership.FromIdentity(Convert.ToInt32(mId));
                        memberships.Add(membership);
                        //find earliest expiry in expiring orgs
                        if (membership.Expires < currentExpiry)
                        {
                            currentExpiry = membership.Expires;
                            newExpiry = currentExpiry.AddYears(1);
                            membershipExists = true;
                            membershipToExtend = membership;
                        }
                    }
                    catch (Exception)
                    {
                    }
                }
            }

            // Get the new expiry from org 1 Organization.PPSEid

            bool isPpMember = false;
            bool isUPMember = false;

            foreach (Membership membership in person.GetRecentMemberships(Membership.GracePeriod))
            {
                if (membership.OrganizationId == Organization.PPSEid)
                {
                    isPpMember = true;
                }
                else if (membership.Organization.IsOrInherits(Organization.UPSEid))
                {
                    isUPMember = true;
                }
                if (membership.Expires < currentExpiry
                    && (membership.Organization.IsOrInherits(Organization.UPSEid)
                        || membership.OrganizationId == Organization.PPSEid))
                {
                    currentExpiry = membership.Expires;
                    newExpiry = currentExpiry.AddYears(1);
                    membershipExists = true;
                    membershipToExtend = membership;
                }

            }


            if (membershipExists)
            {
                // The default is to renew all existing memberships. However, a person can also
                // request a transfer or to leave one specific organization.

                // This is built into the security token.

                string token1 = person.Name.Replace(" ", "-") + person.PasswordHash + "-" +
                                currentExpiry.Year.ToString();
                string token2 = person.PasswordHash + "-" + currentExpiry.Year.ToString();
                int leaveOrgId = 0;
                int transferOldOrgId = 0;
                int transferNewOrgId = 0;

                string leaveString = Request.QueryString["Leave"];
                string transferString = Request.QueryString["Transfer"];

                if (!string.IsNullOrEmpty(leaveString))
                {
                    leaveOrgId = Int32.Parse(leaveString);
                    token1 += "-Leave" + leaveOrgId.ToString();
                    token2 += "-Leave" + leaveOrgId.ToString();
                }

                if (!string.IsNullOrEmpty(transferString))
                {
                    string[] tokens = transferString.Split(',');
                    transferOldOrgId = Int32.Parse(tokens[0]);
                    transferNewOrgId = Int32.Parse(tokens[1]);

                    token1 += "-Transfer" + transferOldOrgId.ToString() + "/" + transferNewOrgId.ToString();
                    token2 += "-Transfer" + transferOldOrgId.ToString() + "/" + transferNewOrgId.ToString();
                }

                expectedHash1 = SHA1.Hash(token1).Replace(" ", "").Substring(0, 8);
                expectedHash2 = SHA1.Hash(token2).Replace(" ", "").Substring(0, 8);

                if (Request.QueryString["SecHash"] == expectedHash1 || Request.QueryString["SecHash"] == expectedHash2)
                {
                    success = true;

                    this.LabelExpires.Text = newExpiry.ToString("yyyy-MM-dd");

                    if (leaveOrgId > 0)
                    {
                        Membership membership = person.GetRecentMembership(Membership.GracePeriod, leaveOrgId);

                        // Might have been terminated already
                        if (membership != null && membership.Active)
                        {
                            //Terminate logs and creates appropriate events
                            membership.Terminate(EventSource.SignupPage, person,
                                                 "Membership in " + membership.Organization.NameShort +
                                                 " was terminated while renewing.");
                        }
                        this.PanelLeft.Visible = true;
                        this.LiteralLeftOrganizations.Text = "<b>" +
                                                             Server.HtmlEncode(
                                                                 Organization.FromIdentity(leaveOrgId).Name) + "</b>";
                    }

                    if (transferOldOrgId > 0)
                    {
                        Membership oldMembership = person.GetRecentMembership(Membership.GracePeriod, transferOldOrgId);
                        // Might have been terminated already
                        if (oldMembership != null)
                        {
                            Membership newMembership = Membership.Create(person.Identity, transferNewOrgId,
                                                                         oldMembership.Expires);

                            //Terminate logs and creates appropriate events
                            oldMembership.Terminate(EventSource.SignupPage, person,
                                                    "Membership in " + oldMembership.Organization.NameShort +
                                                    " was transferred to " + newMembership.Organization.NameShort +
                                                    " while renewing.");

                        }
                        this.LabelTransferOldOrganization.Text = Organization.FromIdentity(transferOldOrgId).Name;
                        this.LabelTransferNewOrganization.Text = Organization.FromIdentity(transferNewOrgId).Name;
                        this.PanelTransferred.Visible = true;
                    }

                    Activizr.Logic.Support.PWEvents.CreateEvent(EventSource.SignupPage,
                                                                 EventType.ReceivedMembershipPayment,
                                                                 person.Identity, membershipToExtend.OrganizationId,
                                                                 person.Geography.Identity, person.Identity, 0,
                                                                 Request.UserHostAddress);

                    string orgList = string.Empty;

                    foreach (Membership membership in person.GetRecentMemberships(Membership.GracePeriod))
                    {
                        if (membership.OrganizationId != leaveOrgId)
                        {
                            if ((isPpMember && membership.OrganizationId == Organization.PPSEid)
                                || (isUPMember && membership.Organization.IsOrInherits(Organization.UPSEid))
                                || (memberships.Contains(membership)))
                            {
                                PWLog.Write(PWLogItem.Person, person.Identity, PWLogAction.MembershipRenewed,
                                            "Membership in " + membership.Organization.NameShort + " renewed.",
                                            "Membership was renewed from IP " + Request.UserHostAddress + ".");
                                orgList += ", <b>" + Server.HtmlEncode(membership.Organization.Name) + "</b>";
                            }
                        }
                    }

                    orgList = orgList.Substring(2);
                    this.LiteralRenewedOrganizations.Text = orgList;
                }
            }
            else
            {
                // There were no existing memberships. Create new ones. This is the PPSE path, so create a new membership for just PPSE.

                // Verify security token.

                string tokenBase = person.Name.Replace(" ", "-") + person.PasswordHash + "-" +
                                   DateTime.Today.Year.ToString();
                string expectedSecurityHash = SHA1.Hash(tokenBase).Replace(" ", "").Substring(0, 8);

                if (Request.QueryString["SecHash"] == expectedSecurityHash)
                {

                    Membership.Create(person, Organization.PPSE, DateTime.Today.AddYears(1));
                    Activizr.Logic.Support.PWEvents.CreateEvent(EventSource.SignupPage,
                                                                 EventType.ReceivedMembershipPayment,
                                                                 person.Identity, Organization.PPSEid,
                                                                 person.Geography.Identity, person.Identity, 0,
                                                                 Request.UserHostAddress);
                    PWLog.Write(PWLogItem.Person, person.Identity, PWLogAction.MembershipRenewed,
                                "A renewed membership in " + Organization.PPSE.NameShort + " was signed up.",
                                "Membership was created from IP " + Request.UserHostAddress + ".");
                    success = true;
                }
            }
        }

        string errorType = "";
        try
        {
            // This is the new path - we expect all renewals from Dec 14, 2010 and onward to follow this. Delete the old path (with "MemberId") some time February 2011.

            if (Int32.TryParse(Request.QueryString["PersonId"], out personId))
            {
                // Ok, at least we have  a valid person id.

                person = Person.FromIdentity(personId);

                string transferString = Request.QueryString["Transfer"];
                Membership membership = null;
                DateTime newExpiry = DateTime.MinValue; ;
                int transferOldOrgId = 0;
                int transferNewOrgId = 0;
                try
                {
                    if (Request.QueryString["MembershipId"] != null)
                    {
                        membership = Membership.FromIdentity(Int32.Parse(Request.QueryString["MembershipId"]));
                        newExpiry = membership.Expires;

                        //do not mess with lifetime memberships (100 years)
                        if (newExpiry < DateTime.Today.AddYears(10))
                        {
                            newExpiry = newExpiry.AddYears(1);
                            if (newExpiry > DateTime.Now.AddYears(1))
                            {
                                newExpiry = DateTime.Now.AddYears(1).AddDays(1);
                            }
                        }

                        if (membership.OrganizationId == Organization.PPSEid)
                        {
                            redirectUrl = "http://www.piratpartiet.se/fornyelse"; // HACK, have an org parameter for this later
                        }

                        if (membership.PersonId != personId)
                        {
                            throw new ArgumentException("Mismatching membership and person");
                        }
                    }
                    else if (Request.QueryString["Transfer"] != null)
                    {
                        if (!string.IsNullOrEmpty(transferString))
                        {
                            string[] tokens = transferString.Split(',');
                            transferOldOrgId = Int32.Parse(tokens[0]);
                        }
                        membership = person.GetRecentMembership(Membership.GracePeriod, transferOldOrgId);
                        if (membership == null)
                        {
                            throw new ArgumentException("Can't find membership");
                        }
                        //do not mess with lifetime memberships (100 years)
                        if (membership.Expires < DateTime.Today.AddYears(10))
                        {
                            if (membership.Expires > DateTime.Today.AddYears(1))
                                newExpiry = membership.Expires;
                            else
                                newExpiry = DateTime.Today.AddYears(1);
                        }
                    }
                    else
                    {
                        throw new ArgumentException("No MembershipId given");
                    }
                }
                catch (Exception ex)
                {
                    throw new Exception("No Membership found: " + ex.Message, ex);
                }

                if (!membership.Active)
                {
                    if (membership.DateTerminated.AddDays(Membership.GracePeriod) < DateTime.Today)
                    {
                        throw new ArgumentException("Membership has expired beyond recovery");
                    }

                    newExpiry = DateTime.Today.AddYears(1);

                    if (membership.OrganizationId == Organization.PPSEid)
                    {
                        redirectUrl = "http://www.piratpartiet.se/fornyelse"; // HACK, have an org parameter for this later
                    }
                }


                string tokenBase = person.PasswordHash + "-" + membership.Identity.ToString() + "-" +
                                   membership.Expires.Year.ToString();


                if (!string.IsNullOrEmpty(transferString))
                {
                    string[] tokens = transferString.Split(',');
                    transferOldOrgId = Int32.Parse(tokens[0]);
                    transferNewOrgId = Int32.Parse(tokens[1]);

                    tokenBase += "-Transfer" + transferOldOrgId.ToString() + "/" + transferNewOrgId.ToString();
                }

                if (transferOldOrgId != 0 && transferOldOrgId != membership.OrganizationId)
                {
                    throw new ArgumentException("Invalid Transfer Order");
                }

                string expectedHash = SHA1.Hash(tokenBase).Replace(" ", "").Substring(0, 8);

                if (Request.QueryString["SecHash"] == expectedHash)
                {
                    success = true;

                    this.LabelExpires.Text = newExpiry.ToString("yyyy-MM-dd");
                    int orgMembershipToExtend = membership.OrganizationId;


                    if (transferOldOrgId > 0)
                    {
                        Membership oldMembership = person.GetRecentMembership(Membership.GracePeriod, transferOldOrgId);
                        Membership newMembership = membership;
                        // Might have been terminated already
                        if (oldMembership != null)
                        {
                            newMembership = Membership.Create(person.Identity, transferNewOrgId, oldMembership.Expires);

                            //Terminate logs and creates appropriate events
                            oldMembership.Terminate(EventSource.SignupPage, person,
                                                    "Membership in " + oldMembership.Organization.NameShort +
                                                    " was transferred to " + newMembership.Organization.NameShort +
                                                    " while renewing.");

                            membership = newMembership;
                        }
                        this.LabelTransferOldOrganization.Text = Organization.FromIdentity(transferOldOrgId).Name;
                        this.LabelTransferNewOrganization.Text = Organization.FromIdentity(transferNewOrgId).Name;
                        this.PanelTransferred.Visible = true;

                        orgMembershipToExtend = transferNewOrgId;
                    }

                    Activizr.Logic.Support.PWEvents.CreateEvent(EventSource.SignupPage,
                                                                 EventType.ReceivedMembershipPayment,
                                                                 person.Identity, orgMembershipToExtend,
                                                                 person.Geography.Identity, person.Identity, 0,
                                                                 Request.UserHostAddress);

                    PWLog.Write(person.Identity, PWLogItem.Person, person.Identity, PWLogAction.MembershipRenewed,
                                "Membership in " + membership.Organization.NameShort + " renewed.",
                                "Membership was renewed from IP " + Request.UserHostAddress + ".");

                    this.LiteralRenewedOrganizations.Text = Organization.FromIdentity(orgMembershipToExtend).Name;
                }
            }
        }
        catch (ArgumentException e2)
        {
            // Something failed parsing the parameters. Do not renew.
            errorType = e2.Message;
        }


        if (!success)
        {
            // Send a couple mails
            PWLog.Write(person.Identity, PWLogItem.Person, person.Identity, PWLogAction.Failure, "Tech failure on membership renewal: " + Request.RawUrl + " Errormessage:" + errorType, "Renewal attempt from from IP " + Request.UserHostAddress + ".");

            person.SendNotice("Vill du f\xF6rnya?",
                "Alldeles nyss f\xF6rs\xF6kte n\xE5gon, troligtvis du, f\xF6rnya ditt medlemskap i Piratpartiet " +
                "och/eller Ung Pirat. Det misslyckades p\xE5 grund av en felaktig s\xE4kerhetskod.\r\n\r\n" +
                "Det kan bero p\xE5 ett antal anledningar, men f\xF6r att vara s\xE4ker p\xE5 att det inte \xE4r " +
                "on\xF6" + "diga tekniska fel som hindrar dig fr\xE5n att forts\xE4tta vara medlem, s\xE5 kan vi ocks\xE5 f\xF6rnya " +
                "ditt medlemskap manuellt.\r\n\r\nAllt som kr\xE4vs \xE4r att du svarar JA p\xE5 det h\xE4r brevet och " +
                "skickar tillbaka det till Medlemsservice (avs\xE4ndaren).\r\n\r\n" +
                "Vill du f\xF6rnya ditt eller dina befintliga medlemskap i Piratpartiet och/eller Ung Pirat " +
                "f\xF6r ett \xE5r till?\r\n\r\n", Organization.PPSEid);
            Person.FromIdentity(1).SendNotice("Misslyckad f\xF6rnyelse",
                person.Name + " (#" + person.Identity.ToString() + ") f\xF6rs\xF6kte f\xF6rnya medlemskapet. Det misslyckades:" + errorType +
                "Ett mail har skickats ut.\r\n", Organization.PPSEid);
        }
        else
        {
            this.PanelSuccess.Visible = success;
            this.PanelFail.Visible = !success;

            if (!String.IsNullOrEmpty(redirectUrl))
            {
                Response.Redirect(redirectUrl);
            }
        }

    }
コード例 #2
0
 private static bool CheckIsMemberOf (Memberships displayedMemberOf, Organization organizationOption)
 {
     bool canhave = false;
     foreach (Activizr.Logic.Pirates.Membership m in displayedMemberOf)
     {
         if (organizationOption.IsOrInherits(m.OrganizationId)
         || m.Organization.IsOrInherits(organizationOption.Identity) )
         {
             canhave = true;
             break;
         }
     }
     return canhave;
 }
コード例 #3
0
    public List<ListPerson> GetData (string sortBy)
    {

        List<ListPerson> retval = new List<ListPerson>();
        if (listedPersons != null)
        {
            People ppl = People.FromIdentities(listedPersons);
            Dictionary<int, List<BasicMembership>> membershipTable = Memberships.GetMembershipsForPeople(listedPersons, Membership.GracePeriod);
            Memberships membershipsToLoad = new Memberships();
            foreach (Person p in ppl)
            {
                if (membershipTable.ContainsKey(p.Identity))
                {
                    foreach (BasicMembership bm in membershipTable[p.Identity])
                    {
                        if (bm.OrganizationId == selectedOrgId)
                        {
                            Membership ms = Membership.FromBasic(bm);
                            membershipsToLoad.Add(ms);
                        }
                    }
                }
            }
            Membership.LoadPaymentStatuses(membershipsToLoad);

            Dictionary<int, Membership> memberships = new Dictionary<int, Membership>();
            foreach (Membership ms in membershipsToLoad)
            {
                memberships[ms.Identity] = ms;
            }

            foreach (Person p in ppl)
            {
                ListPerson lp = new ListPerson(p);
                if (membershipTable.ContainsKey(p.Identity))
                {
                    foreach (BasicMembership bm in membershipTable[p.Identity])
                    {
                        if (bm.OrganizationId == selectedOrgId)
                        {
                            Membership ms = memberships[bm.MembershipId];
                            lp.JoinedDate = ms.MemberSince;
                            lp.ExpiresDate = ms.Expires;
                            lp.MembershipId = ms.Identity;
                            retval.Add(lp);
                        }
                    }
                }
            }
        }

        PropertyInfo pi = typeof(ListPerson).GetProperty(sortBy);
        if (pi != null)
        {

            MemberInfo [] miA = pi.PropertyType.GetMember("CompareTo", MemberTypes.Method, BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static);
            if (miA.Length > 0)
            {

                MethodInfo mi =(MethodInfo) miA[0];
                retval.Sort(delegate(ListPerson p1, ListPerson p2)
                {
                    return Convert.ToInt32(mi.Invoke(pi.GetValue(p1, null), new object[] { pi.GetValue(p2, null) }));
                });
            }
        }
        return retval;
    }
コード例 #4
0
    protected void ButtonChange_Click (object sender, EventArgs e)
    {

        MembershipPaymentStatus newStatus = (MembershipPaymentStatus)Convert.ToInt32(DropDownListStatusChange.SelectedValue);
        DateTime nowvalue = DateTime.Now;
        string checkedIds = "" + Request.Form["CheckboxSelect"];
        string[] checkedIdArr = checkedIds.Split(',');
        List<int> ids = new List<int>();
        Memberships membershipsToLoad = new Memberships();

        foreach (string id in checkedIdArr)
        {
            Membership ms = Membership.FromIdentity(Convert.ToInt32(id));
            membershipsToLoad.Add(ms);
        }
        Membership.LoadPaymentStatuses(membershipsToLoad);
        foreach (Membership ms in membershipsToLoad)
        {
            ms.SetPaymentStatus(newStatus, nowvalue);
        }

        RebuildGrid();

    }
コード例 #5
0
ファイル: TestForum4.aspx.cs プロジェクト: SwarmCorp/Swarmops
    private void SetMembers (int startRecord, IForumDatabase forumDatabase, Dictionary<int, bool> memberAccountLookup, Memberships memberships)
    {
        Person currentMember = null;
        int recCnt = -1;
        int recCnt2 = 0;
        foreach (Membership membership in memberships)
        {
            recCnt++;
            if (recCnt < startRecord) continue;

            if (!membership.Active)
            {
                continue;
            }
            recCnt2++;
            currentMember = membership.Person;
            SetOneMember(forumDatabase, memberAccountLookup, ref currentMember);
            if (recCnt2 > batchsize)
            {
                Label2.Text = "" + (recCnt + 1);
                return;
            }
        }
        Label2.Text = "0";
        Label1.Text = "2";

    }
コード例 #6
0
 public static Membership[] SelectStatic (Memberships memberships)
 {
     return memberships.ToArray();
 }
コード例 #7
0
ファイル: Authorization.cs プロジェクト: SwarmCorp/Swarmops
        public static Memberships FilterMembershipsToMatchAuthority (Memberships memberships, Geography personGeography,
                                                                     Authority authority)
        {
            // First: If sysadmin, return the whole list uncensored.

            if (IsSystemAdministrator(authority))
            {
                return memberships;
            }

            var clearedMemberships = new Dictionary<int, Membership>();

            //
            foreach (BasicPersonRole role in authority.OrganizationPersonRoles)
            {
                Dictionary<int, BasicOrganization> clearedOrganizations =
                    OrganizationCache.GetOrganizationHashtable(role.OrganizationId);

                foreach (Membership membership in memberships)
                {
                    bool organizationClear = clearedOrganizations.ContainsKey(membership.OrganizationId);

                    if (organizationClear
                        && authority.HasPermission(Permission.CanViewMemberships, membership.OrganizationId, membership.Person.GeographyId, Flag.Default))
                    {
                        clearedMemberships[membership.Identity] = membership;
                    }
                }
            }


            foreach (BasicPersonRole role in authority.LocalPersonRoles)
            {
                Dictionary<int, BasicGeography> clearedGeographies = GeographyCache.GetGeographyHashtable(role.GeographyId);
                Dictionary<int, BasicOrganization> clearedOrganizations =
                    OrganizationCache.GetOrganizationHashtable(role.OrganizationId);

                bool geographyClear = clearedGeographies.ContainsKey(personGeography.Identity);
                geographyClear = geographyClear && authority.HasPermission(Permission.CanViewMemberships, role.OrganizationId, personGeography.Identity, Flag.Default);

                if (geographyClear)
                {
                    foreach (Membership membership in memberships)
                    {
                        bool organizationClear = clearedOrganizations.ContainsKey(membership.OrganizationId);

                        if (organizationClear)
                        {
                            clearedMemberships[membership.Identity] = membership;
                        }
                    }
                }
            }


            // Assemble the array

            var result = new Memberships();

            foreach (Membership membership in clearedMemberships.Values)
            {
                result.Add(membership);
            }

            return result;
        }
コード例 #8
0
 public virtual int Update(Memberships dataSet) {
     return this.Adapter.Update(dataSet, "Roles");
 }
コード例 #9
0
ファイル: Person.cs プロジェクト: SwarmCorp/Swarmops
        /// <summary>
        /// Returns most recent membership for each org wich is active or terminated within the grace period
        /// </summary>
        /// <param name="orgs">List of ids. If empty, all orgs</param>
        /// <param name="gracePeriod">For exired, number of days to add to allow it to be returned</param>
        /// <returns></returns>
        public Memberships GetRecentMemberships (List<int> orgs, int gracePeriod)
        {
            Memberships memberships = this.GetMemberships(true);
            Dictionary<int, Membership> collectMembers = new Dictionary<int, Membership>();

            memberships.Sort(delegate(Membership ms1, Membership ms2)
            {
                return ms2.DateTerminated.CompareTo(ms1.DateTerminated);
            });

            //Keep one for each org, the active one or the one with the highest Terminationdate
            foreach (Membership membership in memberships)
            {
                if (orgs.Count == 0 || orgs.Contains(membership.OrganizationId))
                {
                    if (membership.Active)
                    {
                        collectMembers[membership.OrganizationId] = membership;
                    }
                    else if (membership.DateTerminated.AddDays(gracePeriod) > DateTime.Today)
                    {
                        if (!collectMembers.ContainsKey(membership.OrganizationId)
                            || collectMembers[membership.OrganizationId].Active == false)
                        {
                            collectMembers[membership.OrganizationId] = membership;
                        }
                    }
                }
            }

            Memberships collectedMS = new Memberships();
            collectedMS.AddRange(collectMembers.Values);

            if (collectedMS.Count > 0)
            { //sort to get most recent first
                collectedMS.Sort(delegate(Membership ms1, Membership ms2)
                {
                    if (ms1.Active && ms1.Active != ms2.Active)
                        return -1; // active before terminated
                    else if (ms1.Active != ms2.Active)
                        return 1;// active before terminated
                    else if (ms1.Active)
                        return ms1.Expires.CompareTo(ms2.Expires); // active with lowest expiry
                    else
                        return ms2.DateTerminated.CompareTo(ms1.DateTerminated); // terminated with latest terminationdate
                });
            }

            return collectedMS;
        }
コード例 #10
0
 public virtual int Update(Memberships.RolesDataTable dataTable) {
     return this.Adapter.Update(dataTable);
 }
コード例 #11
0
    protected void Button1_Click (object sender, EventArgs e)
    {

        if (!Formatting.ValidateEmailFormat(TextBoxMail.Text))
        {
            LabelReply.Text = "Fel format på e-Mail adress";
            LabelReply.Font.Bold = true;
            LabelReply.ForeColor = Color.Red;
            LabelReply.Font.Size = FontUnit.Medium;
            return;
        }

        if (CheckBoxRenew.Checked == false)
        {
            LabelReply.Text = "Kryssa för att du vill vara medlem!";
            LabelReply.Font.Bold = true;
            LabelReply.ForeColor = Color.Red;
            LabelReply.Font.Size = FontUnit.Medium;
            return;
        }

        if (TextBoxName.Text.Trim() == "")
        {
            LabelReply.Text = "Ange namn!";
            LabelReply.Font.Bold = true;
            LabelReply.ForeColor = Color.Red;
            LabelReply.Font.Size = FontUnit.Medium;
            return;
        }





        People members = People.FromEmail(TextBoxMail.Text);
        Person person = null;
        DateTime newExpiry = DateTime.MinValue;
        bool sentMail = true;

        try
        {
            Memberships membershipsToRenew = new Memberships();
            string foundMemberIds = "";
            try
            {
                DateTime currentExpiry = DateTime.MinValue;
                if (members.Count > 0)
                {
                    person = members[0];
                    DateTime latest = DateTime.MinValue;

                    Memberships personMS = person.GetRecentMemberships(Membership.GracePeriod);
                    if (personMS != null && personMS.Count > 0)
                    {
                        membershipsToRenew = personMS;
                        latest = personMS[0].Expires;
                    }

                    foreach (Person p in members)
                    {
                        foundMemberIds += "," + p.Identity;
                        personMS = p.GetRecentMemberships(Membership.GracePeriod);

                        if (personMS != null
                            && personMS.Count > 0
                            && personMS[0].Expires > latest)
                        {
                            membershipsToRenew = personMS;
                            person = p;
                            latest = personMS[0].Expires;
                        }
                    }
                }
            }
            finally
            {
                PWLog.Write(PWLogItem.None, 0, PWLogAction.MembershipRenewalRequest, "MembershipRenewalRequest recieved |" + TextBoxMail.Text + "|" + TextBoxName.Text, "Found " + members.Count + "Persons" + foundMemberIds);
            }
            if (membershipsToRenew.Count > 0)
            {
                //Don't need to extend these, it will be handled in the renewalpage

                //newExpiry = DateTime.Today.AddDays(6); //6 days to avoid renewal mail (just in case)
                //foreach (Membership ms in membershipsToRenew)
                //{
                //    if (ms.Expires < DateTime.Now)
                //    {
                //        PWLog.Write(PWLogItem.Person, person.Identity, PWLogAction.MembershipRenewed, "Membership in " + ms.Organization.NameShort + " extended temporarily on delayed renewal", "Membership was renewed from IP " + Request.UserHostAddress + ".");
                //        ms.Expires = newExpiry;
                //    }
                //}
                SendReminderMail(person, membershipsToRenew);

            }
            else
            {
                //No memberships

                sentMail = SendMail(
                    FunctionalMail.Address[MailAuthorType.MemberService].Name,
                    FunctionalMail.Address[MailAuthorType.MemberService].Email,
                    TextBoxName.Text,
                    TextBoxMail.Text,
                    "Vill du förnya?",
                    @"
Alldeles nyss försökte någon (troligtvis du) förnya ditt medlemskap i Piratpartiet och/eller Ung Pirat.

Tyvärr kunde vi inte hitta din mailadress i vårt medlemsregister, så antingen var det fel adress, eller så
har vi redan hunnit rensa bort dina medlemsuppgifter.

Om du misstänker att det kan ha varit fel mailadress, att den adress vi har registrerad är en annan, 
pröva gärna med en annan på https://pirateweb.net/Pages/Public/SE/RequestRenewal.aspx

Annars, om det har gått en tid sedan ditt medlemskap löpte ut, registrera dig på nytt
på http://blipirat.nu/

Du är välkommen, du behövs!

mvh

Piratpartiet");
            }
        }
        catch
        {
            sentMail = false;
        }
        if (sentMail)
        {
            Panel1.Visible = false;
            LabelReply.Text = "Vi har skickat ett mail med en förnyelselänk.<br><br>Kolla din mailbox.";
        }
        else
            LabelReply.Text = "PROGRAMFEL: Lyckades inte skicka mail. Kontakta [email protected] istället och be att de hjälper dig att förnya ditt medlemskap.";

    }
コード例 #12
0
    public static void SendReminderMail (Person person, Memberships memberships)
    {
        // First, determine the organization template to use. Prioritize a long ancestry.

        // This is a hack for the Swedish structure.

        ReminderMail remindermail = new ReminderMail();


        int longestAncestry = 0; // "ancestry" as a length means distance to organization tree root
        int shortestAncestry = 999;
        Organization topOrg = null;
        Organization lowOrg = null;
        DateTime currentExpiry = DateTime.MinValue;

        foreach (Membership membership in memberships)
        {
            if (membership.Organization.AutoAssignNewMembers)
            {
                Organizations ancestry = membership.Organization.GetLine();

                if (ancestry.Count > longestAncestry)
                {
                    longestAncestry = ancestry.Count;
                    lowOrg = membership.Organization;
                    remindermail.pOrgName = lowOrg.MailPrefixInherited;
                }

                if (ancestry.Count < shortestAncestry)
                {
                    shortestAncestry = ancestry.Count;
                    topOrg = membership.Organization;
                }
            }
            if (membership.OrganizationId == Organization.PPSEid)
            {
                topOrg = membership.Organization;
                remindermail.pOrgName = membership.Organization.MailPrefixInherited;
                currentExpiry = membership.Expires;
            }
        }

        DateTime newExpiry = currentExpiry;
        if (newExpiry < DateTime.Today.AddYears(10))
        {
            //do not mess with lifetime memberships
            newExpiry = newExpiry.AddYears(1);
            if (newExpiry > DateTime.Today.AddYears(1))
                newExpiry = DateTime.Today.AddYears(1).AddDays(1);
        }


        //Person sender = Person.FromIdentity(1); //Rick

        remindermail.pExpirationDate = currentExpiry;
        remindermail.pNextDate = newExpiry;
        remindermail.pPreamble = "<p> Vi är glada att du vill <strong>förnya ditt medlemskap</strong> i Piratpartiet och/eller Ung Pirat.<br /><br />Använd en av länkarna nedan så genomförs förnyelsen.<br />";

        string tokenBase = person.PasswordHash + "-" + currentExpiry.Year.ToString();

        Organization expectedLowOrg = Organizations.GetMostLocalOrganization(person.GeographyId, Organization.UPSEid);

        int ageThisYear = DateTime.Now.Year - person.Birthdate.Year;

        //Hardcoded: age = 26
        if (ageThisYear >= 26 && lowOrg.Inherits(Organization.UPSEid))
        {
            // If this person is older than 26, suggest that they leave UP.

            remindermail.pCurrentAge = ageThisYear.ToString();
            remindermail.pCurrentOrg = lowOrg.Name;
            remindermail.pOtherOrg = topOrg.Name;
            string link = "https://pirateweb.net/Pages/Public/SE/People/MemberRenew.aspx?MemberId=" +
                          person.Identity.ToString() + "&Leave=" + lowOrg.Identity.ToString() +
                          "&SecHash=" + SHA1.Hash(tokenBase + "-Leave" + lowOrg.Identity.ToString()).
                                            Replace(" ", "").Substring(0, 8);
            remindermail.pOtherRenewLink = link;
            remindermail.pWrongOrgSpan = " "; //clear the other span
        }

        else if (lowOrg.Inherits(Organization.UPSEid) && lowOrg.Identity != expectedLowOrg.Identity)
        {
            // Is this person in the wrong locale?

            remindermail.pCurrentOrg = lowOrg.Name;
            remindermail.pOtherOrg = expectedLowOrg.Name;
            remindermail.pGeographyName = person.Geography.Name;
            //mailBody += "Du är medlem i " + lowOrg.Name + ", men när du bor i [b]" + person.Geography.Name +
            //             "[/b] så rekommenderar " +
            //             "vi att du byter till din lokala organisation, [b]" + expectedLowOrg.Name +
            //             "[/b]. Klicka här för att göra det:\r\n\r\n";

            string link = "https://pirateweb.net/Pages/Public/SE/People/MemberRenew.aspx?MemberId=" +
                          person.Identity.ToString() + "&Transfer=" + lowOrg.Identity.ToString() + "," +
                          expectedLowOrg.Identity.ToString() +
                          "&SecHash=" + SHA1.Hash(tokenBase + "-Transfer" + lowOrg.Identity.ToString() + "/" +
                                                  expectedLowOrg.Identity.ToString()).Replace(" ", "").Substring(0, 8);
            remindermail.pOtherRenewLink = link;
            remindermail.pTooOldForYouthOrgSpan = " "; //clear the other span

            //mailBody += "[a href=\"" + link + "\"]" + link + "[/a]\r\n\r\n" +
            //            "Det är naturligtvis inget krav, utan du kan fortsätta precis som förut om du vill. " +
            //            "För att fortsätta i dina befintliga föreningar, klicka här:\r\n\r\n";
        }

        else
        {
            remindermail.pTooOldForYouthOrgSpan = " "; //clear the other span
            remindermail.pWrongOrgSpan = " "; //clear the other span
        }

        string stdLink = "https://pirateweb.net/Pages/Public/SE/People/MemberRenew.aspx?MemberId=" +
                         person.Identity.ToString() +
                         "&SecHash=" + SHA1.Hash(tokenBase).Replace(" ", "").Substring(0, 8);

        remindermail.pStdRenewLink = stdLink;

        OutboundMail mail = remindermail.CreateFunctionalOutboundMail(MailAuthorType.MemberService, OutboundMail.PriorityNormal, topOrg, Geography.Root);
        if (mail.Body.Trim() == "")
        {
            throw new Exception("Failed to create a mailBody");
        }
        else
        {
            mail.AddRecipient(person.Identity, false);
            mail.SetRecipientCount(1);
            mail.SetResolved();
            mail.SetReadyForPickup();

            PWLog.Write(PWLogItem.Person, person.Identity, PWLogAction.MembershipRenewReminder, "Mail was sent to " + person.Email + " on request to renew membership.", string.Empty);

        }
    }
コード例 #13
0
ファイル: Membership.cs プロジェクト: SwarmCorp/Swarmops
 //Optimization metod, loadMultiple in one call
 public static void LoadPaymentStatuses (Memberships mss)
 {
     Dictionary<int, BasicMembershipPaymentStatus> statuses =
         SwarmDb.GetDatabaseForReading().GetMembershipPaymentStatuses(mss.Identities);
     foreach (Membership ms in mss)
     {
         if (ms.paymentStatus == null && statuses.ContainsKey(ms.Identity))
         {
             ms.paymentStatus = statuses[ms.Identity];
         }
     }
 }
コード例 #14
0
        // This should run daily, suggested right after midnight.

        public static void ChurnExpiredMembers ()
        {
            // For the time being, use org 1 as master.

            int[] organizationIds = new int[] { Organization.PPSEid };

            foreach (int organizationId in organizationIds)
            {
                Memberships memberships = Memberships.GetExpired(Organization.FromIdentity(organizationId));
                // 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.ToString();
                        }
                        membershipsIds = membershipsIds.Substring(1);
                        string expiredMemberships = "";
                        foreach (Membership personMembership in membershipsToDelete)
                        {
                            if (personMembership.OrganizationId != organizationId)
                            {
                                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.ToString();
                    string stdLink = "https://pirateweb.net/Pages/Public/SE/People/MemberRenew.aspx?MemberId=" +
                                     person.Identity.ToString() +
                                     "&SecHash=" + SHA1.Hash(tokenBase).Replace(" ", "").Substring(0, 8) +
                                     "&MID=" + membershipsIds;

                    expiredmail.pStdRenewLink = stdLink;
                    expiredmail.pOrgName = Organization.FromIdentity(organizationId).MailPrefixInherited;

                    person.SendNotice(expiredmail, organizationId);

                    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.");
                        }
                    }
                }
            }
        }