public ActionResult SendLink(string id, FormCollection formCollection) { var li = new LinkInfo(sendlinkSTR, landingSTR, id); if (li.error.HasValue()) { return(Message(li.error)); } try { if (!li.pid.HasValue) { throw new Exception("missing peopleid"); } if (!li.oid.HasValue) { throw new Exception("missing orgid"); } var queueid = li.a[2].ToInt(); var linktype = li.a[3]; // for supportlink, this will also have the goerid var q = (from pp in DbUtil.Db.People where pp.PeopleId == li.pid let org = DbUtil.Db.LoadOrganizationById(li.oid) select new { p = pp, org }).Single(); if (q.org == null && DbUtil.Db.Host == "trialdb") { var oid = li.oid + Util.TrialDbOffset; q = (from pp in DbUtil.Db.People where pp.PeopleId == li.pid let org = DbUtil.Db.LoadOrganizationById(oid) select new { p = pp, org }).Single(); } if (q.org.RegistrationClosed == true || q.org.OrganizationStatusId == OrgStatusCode.Inactive) { throw new Exception("sorry, registration has been closed"); } if (q.org.RegistrationTypeId == RegistrationTypeCode.None) { throw new Exception("sorry, registration is no longer available"); } DbUtil.LogActivity($"{sendlinkSTR}{confirmSTR}", li.oid, li.pid); var expires = DateTime.Now.AddMinutes(DbUtil.Db.Setting("SendlinkExpireMintues", "30").ToInt()); var c = DbUtil.Content("SendLinkMessage"); if (c == null) { c = new Content { Name = "SendLinkMessage", Title = "Your Link for {org}", Body = @" <p>Here is your temporary <a href='{url}'>LINK</a> to register for {org}.</p> <p>This link will expire at {time} (30 minutes). You may request another link by clicking the link in the original email you received.</p> <p>Note: If you did not request this link, please ignore this email, or contact the church if you need help.</p> " }; DbUtil.Db.Contents.InsertOnSubmit(c); DbUtil.Db.SubmitChanges(); } var url = EmailReplacements.RegisterLinkUrl(DbUtil.Db, li.oid.Value, li.pid.Value, queueid, linktype, expires); var subject = c.Title.Replace("{org}", q.org.OrganizationName); var msg = c.Body.Replace("{org}", q.org.OrganizationName) .Replace("{time}", expires.ToString("f")) .Replace("{url}", url) .Replace("%7Burl%7D", url); var NotifyIds = DbUtil.Db.StaffPeopleForOrg(q.org.OrganizationId); DbUtil.Db.Email(NotifyIds[0].FromEmail, q.p, subject, msg); // send confirmation return(Message($"Thank you, {q.p.PreferredName}, we just sent an email to {Util.ObscureEmail(q.p.EmailAddress)} with your link...")); } catch (Exception ex) { DbUtil.LogActivity($"{sendlinkSTR}{confirmSTR}Error: {ex.Message}", li.oid, li.pid); return(Message(ex.Message)); } }
public ActionResult SendLink(string id) { if (!id.HasValue()) { return(Content("bad link")); } var guid = id.ToGuid(); if (guid == null) { return(Content("invalid link")); } var ot = DbUtil.Db.OneTimeLinks.SingleOrDefault(oo => oo.Id == guid.Value); if (ot == null) { return(Content("invalid link")); } if (ot.Used) { return(Content("link used")); } if (ot.Expires.HasValue && ot.Expires < DateTime.Now) { return(Content("link expired")); } var a = ot.Querystring.SplitStr(",", 4); var orgid = a[0].ToInt(); var pid = a[1].ToInt(); var queueid = a[2].ToInt(); var linktype = a[3]; // for supportlink, this will also have the goerid var q = (from pp in DbUtil.Db.People where pp.PeopleId == pid let org = DbUtil.Db.LoadOrganizationById(orgid) select new { p = pp, org }).Single(); if (q.org.RegistrationClosed == true || q.org.OrganizationStatusId == OrgStatusCode.Inactive) { return(Content("sorry, registration has been closed")); } if (q.org.RegistrationTypeId == RegistrationTypeCode.None) { return(Content("sorry, registration is no longer available")); } ot.Used = true; DbUtil.Db.SubmitChanges(); DbUtil.LogActivity("Sendlink: {0}".Fmt(q.org.OrganizationName)); var subject = "Your link for " + q.org.OrganizationName; var msg = @"<p>Here is your <a href=""{0}"">LINK</a></p> <p>Note: If you did not request this link, please ignore this email, or contact the church if you need help.</p>" .Fmt(EmailReplacements.RegisterLinkUrl(DbUtil.Db, orgid, pid, queueid, linktype)); var NotifyIds = DbUtil.Db.StaffPeopleForOrg(q.org.OrganizationId); DbUtil.Db.Email(NotifyIds[0].FromEmail, q.p, subject, msg); // send confirmation return(Content("Thank you, {0}, we just sent an email to {1} with your link...".Fmt(q.p.PreferredName, Util.ObscureEmail(q.p.EmailAddress)))); }
public ActionResult SendLink(string id, FormCollection formCollection) { var li = new LinkInfo(CurrentDatabase, sendlinkSTR, landingSTR, id); if (li.error.HasValue()) { return(Message(li.error)); } try { if (!li.pid.HasValue) { throw new Exception("missing peopleid"); } if (!li.oid.HasValue) { throw new Exception("missing orgid"); } var queueid = li.a[2].ToInt(); var linktype = li.a[3]; // for supportlink, this will also have the goerid int?gsid = null; if (linktype.Contains("supportlink:")) { gsid = linktype.Split(':')[1].ToInt(); } Organization oorg = null; Person person = null; string personPreferredName; string personEmailAddress; GoerSupporter gs = null; if (li.pid == 0) { oorg = CurrentDatabase.Organizations.SingleOrDefault(o => o.OrganizationId == li.oid); gs = CurrentDatabase.GoerSupporters.SingleOrDefault(s => s.Id == gsid); personPreferredName = string.Empty; personEmailAddress = gs.NoDbEmail; } else { var q = (from pp in CurrentDatabase.People where pp.PeopleId == li.pid let org = CurrentDatabase.LoadOrganizationById(li.oid) select new { p = pp, org }).Single(); oorg = q.org; person = q.p; personPreferredName = $"{person.PreferredName}, "; personEmailAddress = person.EmailAddress; } if (oorg == null && CurrentDatabase.Host == "trialdb") { var oid = li.oid + Util.TrialDbOffset; var q = (from pp in CurrentDatabase.People where pp.PeopleId == li.pid let org = CurrentDatabase.LoadOrganizationById(oid) select new { p = pp, org }).Single(); oorg = q.org; person = q.p; personPreferredName = $"{person.PreferredName}, "; personEmailAddress = person.EmailAddress; } if (oorg.RegistrationClosed == true || oorg.OrganizationStatusId == OrgStatusCode.Inactive) { throw new Exception("sorry, registration has been closed"); } if (oorg.RegistrationTypeId == RegistrationTypeCode.None) { throw new Exception("sorry, registration is no longer available"); } DbUtil.LogActivity($"{sendlinkSTR}{confirmSTR}", li.oid, li.pid); var expires = DateTime.Now.AddMinutes(CurrentDatabase.Setting("SendlinkExpireMinutes", "30").ToInt()); string action = (linktype.Contains("supportlink") ? "support" : "register for"); string minutes = CurrentDatabase.Setting("SendLinkExpireMinutes", "30"); var c = DbUtil.Content(CurrentDatabase, "SendLinkMessage"); if (c == null) { c = new Content { Name = "SendLinkMessage", Title = "Your Link for {org}", Body = @" <p>Here is your temporary <a href='{url}'>LINK</a> to {action} {org}.</p> <p>This link will expire at {time} ({minutes} minutes). You may request another link by clicking the link in the original email you received.</p> <p>Note: If you did not request this link, please ignore this email, or contact the church if you need help.</p> " }; CurrentDatabase.Contents.InsertOnSubmit(c); CurrentDatabase.SubmitChanges(); } var url = EmailReplacements.RegisterLinkUrl(CurrentDatabase, li.oid.Value, li.pid.Value, queueid, linktype, expires); var subject = c.Title.Replace("{org}", oorg.OrganizationName); var msg = c.Body.Replace("{org}", oorg.OrganizationName) .Replace("{time}", expires.ToString("f")) .Replace("{url}", url) .Replace("{action}", action) .Replace("{minutes}", minutes) .Replace("%7Burl%7D", url); var NotifyIds = CurrentDatabase.StaffPeopleForOrg(oorg.OrganizationId); if (person != null) { CurrentDatabase.Email(NotifyIds[0].FromEmail, person, subject, msg); // send confirmation } else //send email to no db person { var from = new MailAddress(NotifyIds[0].EmailAddress ?? NotifyIds[0].EmailAddress2, NotifyIds[0].Name); CurrentDatabase.SendEmail(from, subject, msg, Util.ToMailAddressList(gs.NoDbEmail), gs.Id); } return(Message($"Thank you, {personPreferredName}we just sent an email to {Util.ObscureEmail(personEmailAddress)} with your link...")); } catch (Exception ex) { DbUtil.LogActivity($"{sendlinkSTR}{confirmSTR}Error: {ex.Message}", li.oid, li.pid); return(Message(ex.Message)); } }