コード例 #1
0
        public static void SendChangeOrgMail (Person person, Membership membership, Organization newOrg)
        {
            // HACK for UPSE
            // This is a hack for the Swedish structure.

            ChangeOrgMail changeorgmail = new ChangeOrgMail();

            Organization topOrg = Organization.FromIdentity(Organization.UPSEid);
            Organization lowOrg = membership.Organization;
            DateTime currentExpiry = membership.Expires;


            DateTime newExpiry = DateTime.Today.AddYears(1);


            changeorgmail.pCurrentOrg = lowOrg.Name;
            changeorgmail.pCurrentGeo = person.Geography.Name;
            changeorgmail.pNextDate = newExpiry;

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

            if (newOrg.AnchorGeographyId == Geography.RootIdentity && newOrg.AutoAssignNewMembers)
            {//Fallback org
                changeorgmail.pNoLocalOrg = newOrg.Name;
                changeorgmail.pChangeOrg = "";
            }
            else
            {
                changeorgmail.pNoLocalOrg = "";
                changeorgmail.pChangeOrg = newOrg.Name;
            }

            if (lowOrg.AcceptsMembers)
            {
                changeorgmail.pInactiveOrg = "";
                changeorgmail.pInactiveEnding = " ";
            }
            else
            {
                changeorgmail.pInactiveOrg = newOrg.Name;
            }



            changeorgmail.pStdRenewLink = "https://pirateweb.net/Pages/Public/SE/People/MemberRenew.aspx?PersonId=" +
                              person.Identity.ToString() + "&Transfer=" + lowOrg.Identity.ToString() + "," +
                              newOrg.Identity.ToString() +
                              "&MembershipId=" + membership.Identity.ToString() +
                              "&SecHash=" + SHA1.Hash(tokenBase + "-Transfer" + lowOrg.Identity.ToString() + "/" +
                                                      newOrg.Identity.ToString()).Replace(" ", "").Substring(0, 8);

            OutboundMail mail = changeorgmail.CreateFunctionalOutboundMail(MailAuthorType.MemberService, OutboundMail.PriorityNormal, topOrg, Geography.Root);
            string test = mail.RenderHtml(person, person.PreferredCulture);
            test = mail.RenderText(person, person.PreferredCulture);

            if (mail.Body.Trim() == "")
            {
                throw new InvalidOperationException("Failed to create a mailBody");
            }
            else
            {
                //mail.AddRecipient(7838, true);
                mail.AddRecipient(person.Identity, false);
                mail.SetRecipientCount(1);
                mail.SetResolved();
                mail.SetReadyForPickup();
            }
        }
コード例 #2
0
ファイル: Person.cs プロジェクト: JeffreyQ1/Swarmops
 public Membership AddMembership(int organizationId, DateTime expires)
 {
     return(Membership.Create(Identity, organizationId, expires));
 }
コード例 #3
0
        public static void SendReminderMail (Membership membership)
        {
            // First, determine the organization template to use. Prioritize a long ancestry.

            // This is a hack for the Swedish structure.

            ReminderMail remindermail = new ReminderMail();

            // NEW December 2010: Organizations are separated as per common agreement, there are no common reminder mails. Every membership renews on its own.

            int longestAncestry = 0; // "ancestry" as a length means distance to organization tree root
            int shortestAncestry = 999;
            Organization lowOrg = membership.Organization;
            DateTime currentExpiry = membership.Expires;
            Person person = membership.Person;


            DateTime newExpiry = currentExpiry;

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

            remindermail.pPreamble = "<p> Nu är det dags att <strong>förnya ditt medlemskap</strong> i " + membership.Organization.Name + ".";

            remindermail.pExpirationDate = currentExpiry;
            remindermail.pNextDate = newExpiry;
            remindermail.pOrgName = membership.Organization.MailPrefixInherited;


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

            // REMOVED DEC2010: suggestion that people older than 25 may leave UP, as renewal mails are separated

            // HACK for UPSE:

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

            if (expectedLowOrg != null && 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?PersonId=" +
                                person.Identity.ToString() + "&Transfer=" + lowOrg.Identity.ToString() + "," +
                                expectedLowOrg.Identity.ToString() +
                                "&MembershipId=" + membership.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
                //mailBody += "Klicka på den här länken för att förnya för ett år till:\r\n\r\n";
            }

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

            remindermail.pStdRenewLink = stdLink;
            tokenBase = person.PasswordHash + "-" + membership.Identity.ToString();
            string terminateLink = "https://pirateweb.net/Pages/Public/SE/People/MemberTerminate.aspx?MemberId=" +
                             person.Identity.ToString() +
                             "&SecHash=" + SHA1.Hash(tokenBase).Replace(" ", "").Substring(0, 8) +
                             "&MID=" + membership.Identity.ToString();

            remindermail.pTerminateLink = terminateLink;

            //mailBody += "[a href=\"" + stdLink + "\"]" + stdLink + "[/a]\r\n\r\n" +
            //            "[br]Välkommen att vara med oss i [b]ett år till![/b]\r\n\r\n" +
            //            "Hälsningar,[br]Medlemsservice\r\n\r\n"; // +
            /*"PS: [b]Du fick ett likadant mail alldeles nyss. Om du har å, ä eller ö i ditt namn fungerade " +
                "inte länken i det mailet. Tack till alla som hörde av sig om det; felet är fixat nu och länken ovan ska fungera.[/b]\r\n\r\n";*/

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