Exemple #1
0
        private string CreateUserTag(EmailQueueTo emailqueueto)
        {
            User user = (from u in db.Users
                         where u.PeopleId == emailqueueto.PeopleId
                         select u).FirstOrDefault();

            if (user != null)
            {
                user.ResetPasswordCode    = Guid.NewGuid();
                user.ResetPasswordExpires = DateTime.Now.AddHours(db.Setting("ResetPasswordExpiresHours", "24").ToInt());
                string link = Util.URLCombine(db.CmsHost, "/Account/SetPassword/" + user.ResetPasswordCode.ToString());
                db.SubmitChanges();
                return(@"<a href=""{0}"">Set password for {1}</a>".Fmt(link, user.Username));
            }
            var ot = new OneTimeLink
            {
                Id          = Guid.NewGuid(),
                Querystring = emailqueueto.PeopleId.ToString()
            };

            db.OneTimeLinks.InsertOnSubmit(ot);
            db.SubmitChanges();
            string url = Util.URLCombine(db.CmsHost, "/Account/CreateAccount/{0}".Fmt(ot.Id.ToCode()));

            return(@"<a href=""{0}"">Create Account</a>".Fmt(url));
        }
Exemple #2
0
        private string VolSubLink(string code, EmailQueueTo emailqueueto)
        {
            var list = new Dictionary <string, OneTimeLink>();

            var doc = new HtmlDocument();

            doc.LoadHtml(code);
            HtmlNode ele    = doc.DocumentNode.Element("a");
            string   inside = ele.InnerHtml;
            Dictionary <string, string> d = ele.Attributes.ToDictionary(aa => aa.Name.ToString(), aa => aa.Value);

            string qs = "{0},{1},{2},{3}"
                        .Fmt(d["aid"], d["pid"], d["ticks"], emailqueueto.PeopleId);
            OneTimeLink ot = null;

            if (list.ContainsKey(qs))
            {
                ot = list[qs];
            }
            else
            {
                ot = new OneTimeLink
                {
                    Id          = Guid.NewGuid(),
                    Querystring = qs
                };
                db.OneTimeLinks.InsertOnSubmit(ot);
                db.SubmitChanges();
                list.Add(qs, ot);
            }

            var url = db.ServerLink("/OnlineReg/ClaimVolSub/{0}/{1}".Fmt(d["ans"], ot.Id.ToCode()));

            return(@"<a href=""{0}"">{1}</a>".Fmt(url, inside));
        }
Exemple #3
0
        private string SupportLink(string code, EmailQueueTo emailqueueto)
        {
            var list = new Dictionary <string, OneTimeLink>();

            var doc = new HtmlDocument();

            doc.LoadHtml(code);
            HtmlNode ele    = doc.DocumentNode.Element("a");
            string   inside = ele.InnerHtml;
            Dictionary <string, string> d = ele.Attributes.ToDictionary(aa => aa.Name.ToString(), aa => aa.Value);

            string qs = "{0},{1},{2},{3},{4}".Fmt(emailqueueto.OrgId, emailqueueto.PeopleId, emailqueueto.Id, "supportlink", emailqueueto.GoerSupportId);

            OneTimeLink ot;

            if (list.ContainsKey(qs))
            {
                ot = list[qs];
            }
            else
            {
                ot = new OneTimeLink
                {
                    Id          = Guid.NewGuid(),
                    Querystring = qs
                };
                db.OneTimeLinks.InsertOnSubmit(ot);
                db.SubmitChanges();
                list.Add(qs, ot);
            }
            string url = Util.URLCombine(db.CmsHost, "/OnlineReg/SendLink/{0}".Fmt(ot.Id.ToCode()));

            return(@"<a href=""{0}"">{1}</a>".Fmt(url, inside));
        }
Exemple #4
0
        private string SupportLinkReplacement(string code, EmailQueueTo emailqueueto)
        {
            var list = new Dictionary <string, OneTimeLink>();

            var doc = new HtmlDocument();

            doc.LoadHtml(code);
            var ele    = doc.DocumentNode.Element("a");
            var inside = ele.InnerHtml.Replace("{last}", person.LastName);
            var d      = ele.Attributes.ToDictionary(aa => aa.Name.ToString(), aa => aa.Value);

            var oid = GetId(d, "SupportLink");
            var qs  = $"{oid},{emailqueueto.PeopleId},{emailqueueto.Id},{"supportlink"}:{emailqueueto.GoerSupportId}";

            OneTimeLink ot;

            if (list.ContainsKey(qs))
            {
                ot = list[qs];
            }
            else
            {
                ot = new OneTimeLink
                {
                    Id          = Guid.NewGuid(),
                    Querystring = qs
                };
                db.OneTimeLinks.InsertOnSubmit(ot);
                db.SubmitChanges();
                list.Add(qs, ot);
            }
            var url = db.ServerLink($"/OnlineReg/SendLink/{ot.Id.ToCode()}");

            return($@"<a href=""{url}"">{inside}</a>");
        }
Exemple #5
0
        private string RsvpLink(string code, EmailQueueTo emailqueueto)
        {
            //<a dir="ltr" href="http://rsvplink" id="798" rel="meetingid" title="This is a message">test</a>
            var list = new Dictionary <string, OneTimeLink>();

            var doc = new HtmlDocument();

            doc.LoadHtml(code);
            HtmlNode ele    = doc.DocumentNode.Element("a");
            string   inside = ele.InnerHtml;
            Dictionary <string, string> d = ele.Attributes.ToDictionary(aa => aa.Name.ToString(), aa => aa.Value);

            string msg = "Thank you for responding.";

            if (d.ContainsKey("title"))
            {
                msg = d["title"];
            }

            string confirm = "false";

            if (d.ContainsKey("dir") && d["dir"] == "ltr")
            {
                confirm = "true";
            }

            string smallgroup = null;

            if (d.ContainsKey("rel"))
            {
                smallgroup = d["rel"];
            }

            var id = GetId(d, "RsvpLink");

            string      qs = "{0},{1},{2},{3}".Fmt(id, emailqueueto.PeopleId, emailqueueto.Id, smallgroup);
            OneTimeLink ot;

            if (list.ContainsKey(qs))
            {
                ot = list[qs];
            }
            else
            {
                ot = new OneTimeLink
                {
                    Id          = Guid.NewGuid(),
                    Querystring = qs
                };
                db.OneTimeLinks.InsertOnSubmit(ot);
                db.SubmitChanges();
                list.Add(qs, ot);
            }
            string url = Util.URLCombine(db.CmsHost, "/OnlineReg/RsvpLinkSg/{0}?confirm={1}&message={2}"
                                         .Fmt(ot.Id.ToCode(), confirm, HttpUtility.UrlEncode(msg)));

            return(@"<a href=""{0}"">{1}</a>".Fmt(url, inside));
        }
 public static string GetOTLoginLink(string url, string user)
 {
     var ot = new OneTimeLink
     {
         Id = Guid.NewGuid(),
         Querystring = user,
         Expires = DateTime.Now.AddHours(24)
     };
     DbUtil.Db.OneTimeLinks.InsertOnSubmit(ot);
     DbUtil.Db.SubmitChanges();
     return $"{Util.CmsHost2}Logon?ReturnUrl={HttpUtility.UrlEncode(url)}&otltoken={ot.Id.ToCode()}";
 }
Exemple #7
0
        public static string DropFromOrgLinkUrl(CMSDataContext db, int orgid, int pid, int queueid)
        {
            var qs = $"{orgid},{pid},{queueid}";
            var ot = new OneTimeLink
            {
                Id          = Guid.NewGuid(),
                Querystring = qs,
            };

            db.OneTimeLinks.InsertOnSubmit(ot);
            db.SubmitChanges();
            var url = db.ServerLink($"/OnlineReg/DropFromOrgLink/{ot.Id.ToCode()}");

            return(url);
        }
 public ActionResult GetOneTimeRegisterLink(int OrgId, int PeopleId)
 {
     var ret = AuthenticateDeveloper();
     if (ret.StartsWith("!"))
         return Content("/");
     var ot = new OneTimeLink
     {
         Id = Guid.NewGuid(),
         Querystring = $"{OrgId},{PeopleId},0",
         Expires = DateTime.Now.AddMinutes(10)
     };
     DbUtil.Db.OneTimeLinks.InsertOnSubmit(ot);
     DbUtil.Db.SubmitChanges();
     DbUtil.LogActivity($"APIPerson GetOneTimeRegisterLink {OrgId}, {PeopleId}");
     return Content(Util.CmsHost2 + "OnlineReg/RegisterLink/" + ot.Id.ToCode());
 }
Exemple #9
0
 public static string ExternalLink(CMSDataContext db, int?peopleId, string url)
 {
     if (url.Contains("{token}"))
     {
         var expirationWindow = db.Setting("OTLTokenExpirationMinutes", "5").ToInt();
         var otl = new OneTimeLink
         {
             Id          = Guid.NewGuid(),
             Querystring = peopleId.ToString(),
             Expires     = DateTime.Now.AddMinutes(expirationWindow)
         };
         db.OneTimeLinks.InsertOnSubmit(otl);
         db.SubmitChanges();
         url = url.Replace("{token}", otl.Id.ToCode());
     }
     return(url);
 }
        public static string GetOTLoginLink(string url, string user)
        {
            var ot = new OneTimeLink
            {
                Id = Guid.NewGuid(),
                Querystring = user,
                Expires = DateTime.Now.AddHours(24)
            };
            DbUtil.Db.OneTimeLinks.InsertOnSubmit(ot);
            DbUtil.Db.SubmitChanges();

            var b = DbUtil.Db.ServerLink();
            if(url.StartsWith(b))
            	url = url.Substring(b.Length - (b.EndsWith("/") ? 1 : 0));

            return $"{Util.CmsHost2}Logon?ReturnUrl={HttpUtility.UrlEncode(url)}&otltoken={ot.Id.ToCode()}";
        }
Exemple #11
0
        public void SendOneTimeLink(string from, string url, string subject, string body)
        {
            var ot = new OneTimeLink
            {
                Id = Guid.NewGuid(),
                Querystring = "{0},{1}".Fmt(divid ?? orgid ?? masterorgid , PeopleId)
            };
            var Db = DbUtil.Db;
            Db.OneTimeLinks.InsertOnSubmit(ot);
            Db.SubmitChanges();

            var message = body.Replace("{url}", url + ot.Id.ToCode(), ignoreCase:true);
            message = message.Replace("{name}", person.Name, ignoreCase:true);
            message = message.Replace("{first}", person.PreferredName, ignoreCase:true);

            Db.Email(from, person, subject, message);
        }
        private string RegisterLink(string code, EmailQueueTo emailqueueto)
        {
            var list = new Dictionary <string, OneTimeLink>();

            var doc = new HtmlDocument();

            doc.LoadHtml(code);
            var ele    = doc.DocumentNode.Element("a");
            var inside = ele.InnerHtml.Replace("{last}", person.LastName);
            var d      = ele.Attributes.ToDictionary(aa => aa.Name.ToString(), aa => aa.Value);

            var id = GetId(d, "RegisterLink");

            var         showfamily = code.Contains("registerlink2", ignoreCase: true);
            var         qs         = $"{id},{emailqueueto.PeopleId},{emailqueueto.Id}";
            OneTimeLink ot;

            if (list.ContainsKey(qs))
            {
                ot = list[qs];
            }
            else
            {
                ot = new OneTimeLink
                {
                    Id          = Guid.NewGuid(),
                    Querystring = qs
                };
                db.OneTimeLinks.InsertOnSubmit(ot);
                db.SubmitChanges();
                list.Add(qs, ot);
            }
            var url = db.ServerLink($"/OnlineReg/RegisterLink/{ot.Id.ToCode()}");

            if (showfamily)
            {
                url += "?showfamily=true";
            }
            if (d.ContainsKey("style"))
            {
                return($@"<a href=""{url}"" style=""{d["style"]}"">{inside}</a>");
            }
            return($@"<a href=""{url}"">{inside}</a>");
        }
Exemple #13
0
        private string RegisterLink(string code, EmailQueueTo emailqueueto)
        {
            var list = new Dictionary <string, OneTimeLink>();

            var doc = new HtmlDocument();

            doc.LoadHtml(code);
            HtmlNode ele    = doc.DocumentNode.Element("a");
            string   inside = ele.InnerHtml;
            Dictionary <string, string> d = ele.Attributes.ToDictionary(aa => aa.Name.ToString(), aa => aa.Value);

            var id = GetId(d, "RegisterLink");

            var         showfamily = code.Contains("registerlink2", ignoreCase: true);
            string      qs         = "{0},{1},{2}".Fmt(id, emailqueueto.PeopleId, emailqueueto.Id);
            OneTimeLink ot;

            if (list.ContainsKey(qs))
            {
                ot = list[qs];
            }
            else
            {
                ot = new OneTimeLink
                {
                    Id          = Guid.NewGuid(),
                    Querystring = qs
                };
                db.OneTimeLinks.InsertOnSubmit(ot);
                db.SubmitChanges();
                list.Add(qs, ot);
            }
            string url = db.ServerLink("/OnlineReg/RegisterLink/{0}".Fmt(ot.Id.ToCode()));

            if (showfamily)
            {
                url += "?showfamily=true";
            }
            if (d.ContainsKey("style"))
            {
                return(@"<a href=""{0}"" style=""{1}"">{2}</a>".Fmt(url, d["style"], inside));
            }
            return(@"<a href=""{0}"">{1}</a>".Fmt(url, inside));
        }
Exemple #14
0
        public string DoVolReqLink(string text, string CmsHost, EmailQueueTo emailqueueto)
        {
            var          list         = new Dictionary <string, OneTimeLink>();
            const string VolSubLinkRE = "<a[^>]*?href=\"https{0,1}://volreqlink\"[^>]*>.*?</a>";
            var          re           = new Regex(VolSubLinkRE, RegexOptions.Singleline | RegexOptions.Multiline | RegexOptions.IgnoreCase);
            Match        match        = re.Match(text);

            while (match.Success)
            {
                string tag = match.Value;

                var doc = new HtmlDocument();
                doc.LoadHtml(tag);
                HtmlNode ele    = doc.DocumentNode.Element("a");
                string   inside = ele.InnerHtml;
                Dictionary <string, string> d = ele.Attributes.ToDictionary(aa => aa.Name.ToString(), aa => aa.Value);

                string qs = "{0},{1},{2},{3}"
                            .Fmt(d["mid"], d["pid"], d["ticks"], emailqueueto.PeopleId);
                OneTimeLink ot = null;
                if (list.ContainsKey(qs))
                {
                    ot = list[qs];
                }
                else
                {
                    ot = new OneTimeLink
                    {
                        Id          = Guid.NewGuid(),
                        Querystring = qs
                    };
                    OneTimeLinks.InsertOnSubmit(ot);
                    SubmitChanges();
                    list.Add(qs, ot);
                }

                string url = Util.URLCombine(CmsHost,
                                             "/OnlineReg/RequestResponse?ans={0}&guid={1}".Fmt(d["ans"], ot.Id.ToCode()));
                text  = text.Replace(tag, @"<a href=""{0}"">{1}</a>".Fmt(url, inside));
                match = match.NextMatch();
            }
            return(text);
        }
Exemple #15
0
        public static string RegisterLinkUrl(CMSDataContext db, int orgid, int pid, int queueid, string linktype)
        {
            var    showfamily = linktype == "registerlink2";
            string qs         = "{0},{1},{2},{3}".Fmt(orgid, pid, queueid, linktype);
            var    ot         = new OneTimeLink
            {
                Id          = Guid.NewGuid(),
                Querystring = qs
            };

            db.OneTimeLinks.InsertOnSubmit(ot);
            db.SubmitChanges();
            string url = db.ServerLink("/OnlineReg/RegisterLink/{0}".Fmt(ot.Id.ToCode()));

            if (showfamily)
            {
                url += "?showfamily=true";
            }
            return(url);
        }
Exemple #16
0
        public string RegisterLinkUrl(int orgid, int pid, int queueid, string linktype)
        {
            var    showfamily = linktype == "registerlink2";
            string qs         = "{0},{1},{2},{3}".Fmt(orgid, pid, queueid, linktype);
            var    ot         = new OneTimeLink
            {
                Id          = Guid.NewGuid(),
                Querystring = qs
            };

            OneTimeLinks.InsertOnSubmit(ot);
            SubmitChanges();
            string url = Util.URLCombine(CmsHost, "/OnlineReg/RegisterLink/{0}".Fmt(ot.Id.ToCode()));

            if (showfamily)
            {
                url += "?showfamily=true";
            }
            return(url);
        }
Exemple #17
0
        private OneTimeLink CreateOrFetchOneTimeLink(string qs, Dictionary <string, OneTimeLink> list)
        {
            OneTimeLink ot;

            if (list.ContainsKey(qs))
            {
                ot = list[qs];
            }
            else
            {
                ot = new OneTimeLink
                {
                    Id          = Guid.NewGuid(),
                    Querystring = qs
                };
                CurrentDatabase.OneTimeLinks.InsertOnSubmit(ot);
                CurrentDatabase.SubmitChanges();
                list.Add(qs, ot);
            }
            return(ot);
        }
Exemple #18
0
        private string RegisterLinkHrefReplacement(string code, EmailQueueTo emailqueueto)
        {
            var list = new Dictionary <string, OneTimeLink>();

            var match = RegisterLinkHrefRe.Match(code);

            if (!match.Success)
            {
                return(code);
            }
            var id = match.Groups["id"].Value.ToInt();

            var         showfamily = code.Contains("registerlink2", ignoreCase: true);
            string      qs         = $"{id},{emailqueueto.PeopleId},{emailqueueto.Id}";
            OneTimeLink ot;

            if (list.ContainsKey(qs))
            {
                ot = list[qs];
            }
            else
            {
                ot = new OneTimeLink
                {
                    Id          = Guid.NewGuid(),
                    Querystring = qs
                };
                db.OneTimeLinks.InsertOnSubmit(ot);
                db.SubmitChanges();
                list.Add(qs, ot);
            }
            string url = db.ServerLink($"/OnlineReg/RegisterLink/{ot.Id.ToCode()}");

            if (showfamily)
            {
                url += "?showfamily=true";
            }
            return($"href=\"{url}\"");
        }
Exemple #19
0
        private string CreateUrlForLink(string type, OneTimeLink ot, string confirm, string message, bool showfamily)
        {
            string url = "";

            switch (type)
            {
            case "rsvplink":
            case "regretslink":
                url = CurrentDatabase.ServerLink(
                    $"/OnlineReg/RsvpLinkSg/{ot.Id.ToCode()}?confirm={confirm}&message={HttpUtility.UrlEncode(message)}");
                if (type == "regretslink")
                {
                    url += "&regrets=true";
                }
                break;

            case "registerlink":
            case "registerlink2":
                url = CurrentDatabase.ServerLink($"/OnlineReg/RegisterLink/{ot.Id.ToCode()}");
                if (showfamily)
                {
                    url += "?showfamily=true";
                }
                break;

            case "sendlink":
            case "sendlink2":
                url = CurrentDatabase.ServerLink($"/OnlineReg/SendLink/{ot.Id.ToCode()}");
                break;

            case "votelink":
                url = CurrentDatabase.ServerLink(
                    $"/OnlineReg/VoteLinkSg/{ot.Id.ToCode()}?confirm={confirm}&message={HttpUtility.UrlEncode(message)}");
                break;
            }
            return(url);
        }
        public static string RegisterLinkUrl(CMSDataContext db, int orgid, int pid, int queueid, string linktype, DateTime?expires = null)
        {
            var showfamily = linktype == "registerlink2";
            var qs         = $"{orgid},{pid},{queueid},{linktype}";
            var ot         = new OneTimeLink
            {
                Id          = Guid.NewGuid(),
                Querystring = qs,
            };

            if (expires.HasValue)
            {
                ot.Expires = expires.Value;
            }
            db.OneTimeLinks.InsertOnSubmit(ot);
            db.SubmitChanges();
            var url = db.ServerLink($"/OnlineReg/RegisterLink/{ot.Id.ToCode()}");

            if (showfamily)
            {
                url += "?showfamily=true";
            }
            return(url);
        }
Exemple #21
0
        private string RsvpLink(string code, EmailQueueTo emailqueueto)
        {
            //<a dir="ltr" href="http://rsvplink" id="798" rel="meetingid" title="This is a message">test</a>
            var list = new Dictionary<string, OneTimeLink>();

            var doc = new HtmlDocument();
            doc.LoadHtml(code);
            var ele = doc.DocumentNode.Element("a");
            var inside = ele.InnerHtml.Replace("{last}", person.LastName);
            var d = ele.Attributes.ToDictionary(aa => aa.Name.ToString(), aa => aa.Value);

            var msg = "Thank you for responding.";
            if (d.ContainsKey("title"))
                msg = d["title"];

            string confirm = "false";
            if (d.ContainsKey("dir") && d["dir"] == "ltr")
                confirm = "true";

            string smallgroup = null;
            if (d.ContainsKey("rel"))
                smallgroup = d["rel"];

            var id = GetId(d, "RsvpLink");

            string qs = $"{id},{emailqueueto.PeopleId},{emailqueueto.Id},{smallgroup}";
            OneTimeLink ot;
            if (list.ContainsKey(qs))
                ot = list[qs];
            else
            {
                ot = new OneTimeLink
                {
                    Id = Guid.NewGuid(),
                    Querystring = qs
                };
                db.OneTimeLinks.InsertOnSubmit(ot);
                db.SubmitChanges();
                list.Add(qs, ot);
            }
            var url = db.ServerLink(
                $"/OnlineReg/RsvpLinkSg/{ot.Id.ToCode()}?confirm={confirm}&message={HttpUtility.UrlEncode(msg)}");

            var href = d["href"];
            if (href.Contains("regretslink", ignoreCase: true))
                url = url + "&regrets=true";

            return $@"<a href=""{url}"">{inside}</a>";
        }
Exemple #22
0
        private string RsvpLinkReplacement(string code, EmailQueueTo emailqueueto)
        {
            //<a dir="ltr" href="http://rsvplink" id="798" rel="meetingid" title="This is a message">test</a>
            var list = new Dictionary <string, OneTimeLink>();

            var doc = new HtmlDocument();

            doc.LoadHtml(code);
            var ele    = doc.DocumentNode.Element("a");
            var inside = ele.InnerHtml.Replace("{last}", person.LastName);
            var d      = ele.Attributes.ToDictionary(aa => aa.Name.ToString(), aa => aa.Value);

            var msg = "Thank you for responding.";

            if (d.ContainsKey("title"))
            {
                msg = d["title"];
            }

            string confirm = "false";

            if (d.ContainsKey("dir") && d["dir"] == "ltr")
            {
                confirm = "true";
            }

            string smallgroup = null;

            if (d.ContainsKey("rel"))
            {
                smallgroup = d["rel"];
            }

            var id = GetId(d, "RsvpLink");

            string      qs = $"{id},{emailqueueto.PeopleId},{emailqueueto.Id},{smallgroup}";
            OneTimeLink ot;

            if (list.ContainsKey(qs))
            {
                ot = list[qs];
            }
            else
            {
                ot = new OneTimeLink
                {
                    Id          = Guid.NewGuid(),
                    Querystring = qs
                };
                db.OneTimeLinks.InsertOnSubmit(ot);
                db.SubmitChanges();
                list.Add(qs, ot);
            }
            var url = db.ServerLink(
                $"/OnlineReg/RsvpLinkSg/{ot.Id.ToCode()}?confirm={confirm}&message={HttpUtility.UrlEncode(msg)}");

            var href = d["href"];

            if (href.Contains("regretslink", ignoreCase: true))
            {
                url = url + "&regrets=true";
            }

            return($@"<a href=""{url}"">{inside}</a>");
        }
Exemple #23
0
 private string VoteLinkUrl(string text,
                            EmailQueueTo emailqueueto,
                            Dictionary<string, OneTimeLink> list,
                            string votelink,
                            string id,
                            string msg,
                            string confirm,
                            string smallgroup,
                            string pre)
 {
     string qs = "{0},{1},{2},{3},{4}".Fmt(id, emailqueueto.PeopleId, emailqueueto.Id, pre, smallgroup);
     OneTimeLink ot;
     if (list.ContainsKey(qs))
         ot = list[qs];
     else
     {
         ot = new OneTimeLink
             {
                 Id = Guid.NewGuid(),
                 Querystring = qs
             };
         OneTimeLinks.InsertOnSubmit(ot);
         SubmitChanges();
         list.Add(qs, ot);
     }
     string url = Util.URLCombine(CmsHost, "/OnlineReg/VoteLinkSg/{0}?confirm={1}&message={2}"
                                               .Fmt(ot.Id.ToCode(), confirm, HttpUtility.UrlEncode(msg)));
     return url;
 }
Exemple #24
0
 private string DoCreateUserTag(EmailQueueTo emailqueueto)
 {
     User user = (from u in Users
                  where u.PeopleId == emailqueueto.PeopleId
                  select u).FirstOrDefault();
     if (user != null)
     {
         user.ResetPasswordCode = Guid.NewGuid();
         user.ResetPasswordExpires = DateTime.Now.AddHours(Setting("ResetPasswordExpiresHours", "24").ToInt());
         string link = Util.URLCombine(CmsHost, "/Account/SetPassword/" + user.ResetPasswordCode.ToString());
         SubmitChanges();
         return @"<a href=""{0}"">Set password for {1}</a>".Fmt(link, user.Username);
     }
     var ot = new OneTimeLink
         {
             Id = Guid.NewGuid(),
             Querystring = emailqueueto.PeopleId.ToString()
         };
     OneTimeLinks.InsertOnSubmit(ot);
     SubmitChanges();
     string url = Util.URLCombine(CmsHost, "/Account/CreateAccount/{0}".Fmt(ot.Id.ToCode()));
     return @"<a href=""{0}"">Create Account</a>".Fmt(url);
 }
Exemple #25
0
        private string VoteLink(string code, EmailQueueTo emailqueueto)
        {
            //<a dir="ltr" href="http://votelink" id="798" rel="smallgroup" title="This is a message">test</a>
            var list = new Dictionary<string, OneTimeLink>();

            var doc = new HtmlDocument();
            doc.LoadHtml(code);
            HtmlNode ele = doc.DocumentNode.Element("a");
            string inside = ele.InnerHtml;
            Dictionary<string, string> d = ele.Attributes.ToDictionary(aa => aa.Name.ToString(), aa => aa.Value);

            string msg = "Thank you for responding.";
            if (d.ContainsKey("title"))
                msg = d["title"];

            string confirm = "false";
            if (d.ContainsKey("dir") && d["dir"] == "ltr")
                confirm = "true";

            if (!d.ContainsKey("rel"))
                throw new Exception("Votelink: no smallgroup attribute");
            string smallgroup = d["rel"];
            string pre = "";
            string[] a = smallgroup.SplitStr(":");
            if (a.Length > 1)
                pre = a[0];

            var id = GetId(d, "VoteLink");

            string qs = "{0},{1},{2},{3},{4}".Fmt(id, emailqueueto.PeopleId, emailqueueto.Id, pre, smallgroup);
            OneTimeLink ot;
            if (list.ContainsKey(qs))
                ot = list[qs];
            else
            {
                ot = new OneTimeLink
                    {
                        Id = Guid.NewGuid(),
                        Querystring = qs
                    };
                db.OneTimeLinks.InsertOnSubmit(ot);
                db.SubmitChanges();
                list.Add(qs, ot);
            }
            string url = Util.URLCombine(db.CmsHost, "/OnlineReg/VoteLinkSg/{0}?confirm={1}&message={2}"
                                                      .Fmt(ot.Id.ToCode(), confirm, HttpUtility.UrlEncode(msg)));
            return @"<a href=""{0}"">{1}</a>".Fmt(url, inside);
        }
Exemple #26
0
            public LinkInfo(string link, string from, string id, bool hasorg = true)
            {
                this.link = link;
                this.from = from;
                try
                {
                    if (!id.HasValue())
                        throw LinkException("missing id");
                    var guid = id.ToGuid();
                    if (guid == null)
                        throw LinkException("invalid id");
                    ot = DbUtil.Db.OneTimeLinks.SingleOrDefault(oo => oo.Id == guid.Value);
                    if (ot == null)
                        throw LinkException("missing link");

                    a = ot.Querystring.SplitStr(",", 5);
                    if (hasorg)
                        oid = a[0].ToInt();
                    pid = a[1].ToInt();
                    if (ot.Used)
                        throw LinkException("link used");
                    if (ot.Expires.HasValue && ot.Expires < DateTime.Now)
                        throw LinkException("link expired");
                }
                catch (Exception ex)
                {
                    error = ex.Message;
                }
            }
Exemple #27
0
        private string VoteLink(string code, EmailQueueTo emailqueueto)
        {
            //<a dir="ltr" href="http://votelink" id="798" rel="smallgroup" title="This is a message">test</a>
            var list = new Dictionary <string, OneTimeLink>();

            var doc = new HtmlDocument();

            doc.LoadHtml(code);
            HtmlNode ele    = doc.DocumentNode.Element("a");
            string   inside = ele.InnerHtml;
            Dictionary <string, string> d = ele.Attributes.ToDictionary(aa => aa.Name.ToString(), aa => aa.Value);

            string msg = "Thank you for responding.";

            if (d.ContainsKey("title"))
            {
                msg = d["title"];
            }

            string confirm = "false";

            if (d.ContainsKey("dir") && d["dir"] == "ltr")
            {
                confirm = "true";
            }

            if (!d.ContainsKey("rel"))
            {
                throw new Exception("Votelink: no smallgroup attribute");
            }
            string smallgroup = d["rel"];
            string pre        = "";

            string[] a = smallgroup.SplitStr(":");
            if (a.Length > 1)
            {
                pre = a[0];
            }

            var id = GetId(d, "VoteLink");

            string      qs = "{0},{1},{2},{3},{4}".Fmt(id, emailqueueto.PeopleId, emailqueueto.Id, pre, smallgroup);
            OneTimeLink ot;

            if (list.ContainsKey(qs))
            {
                ot = list[qs];
            }
            else
            {
                ot = new OneTimeLink
                {
                    Id          = Guid.NewGuid(),
                    Querystring = qs
                };
                db.OneTimeLinks.InsertOnSubmit(ot);
                db.SubmitChanges();
                list.Add(qs, ot);
            }
            string url = db.ServerLink("/OnlineReg/VoteLinkSg/{0}?confirm={1}&message={2}"
                                       .Fmt(ot.Id.ToCode(), confirm, HttpUtility.UrlEncode(msg)));

            return(@"<a href=""{0}"">{1}</a>".Fmt(url, inside));
        }
Exemple #28
0
        private string VolSubLink(string code, EmailQueueTo emailqueueto)
        {
            var list = new Dictionary<string, OneTimeLink>();

            var doc = new HtmlDocument();
            doc.LoadHtml(code);
            HtmlNode ele = doc.DocumentNode.Element("a");
            string inside = ele.InnerHtml;
            Dictionary<string, string> d = ele.Attributes.ToDictionary(aa => aa.Name.ToString(), aa => aa.Value);

            string qs = "{0},{1},{2},{3}"
                .Fmt(d["aid"], d["pid"], d["ticks"], emailqueueto.PeopleId);
            OneTimeLink ot = null;
            if (list.ContainsKey(qs))
                ot = list[qs];
            else
            {
                ot = new OneTimeLink
                {
                    Id = Guid.NewGuid(),
                    Querystring = qs
                };
                db.OneTimeLinks.InsertOnSubmit(ot);
                db.SubmitChanges();
                list.Add(qs, ot);
            }

            var url = Util.URLCombine(db.CmsHost, "/OnlineReg/ClaimVolSub/{0}/{1}".Fmt(d["ans"], ot.Id.ToCode()));
            return @"<a href=""{0}"">{1}</a>".Fmt(url, inside);
        }
Exemple #29
0
        private static string GetOneTimeLoginLink(string url, string user)
        {
            var ot = new OneTimeLink
            {
                Id = Guid.NewGuid(),
                Querystring = user,
                Expires = DateTime.Now.AddMinutes(15)
            };

            DbUtil.Db.OneTimeLinks.InsertOnSubmit(ot);
            DbUtil.Db.SubmitChanges();

            return $"{DbUtil.Db.ServerLink($"Logon?ReturnUrl={HttpUtility.UrlEncode(url)}&otltoken={ot.Id.ToCode()}")}";
        }
Exemple #30
0
 private string SendLinkUrl(EmailQueueTo emailqueueto,
                            Dictionary<string, OneTimeLink> list,
                            string id,
                            bool showfamily = false)
 {
     string qs = "{0},{1},{2},{3}".Fmt(id, emailqueueto.PeopleId, emailqueueto.Id,
         showfamily ? "registerlink2" : "registerlink");
     OneTimeLink ot;
     if (list.ContainsKey(qs))
         ot = list[qs];
     else
     {
         ot = new OneTimeLink
             {
                 Id = Guid.NewGuid(),
                 Querystring = qs
             };
         OneTimeLinks.InsertOnSubmit(ot);
         SubmitChanges();
         list.Add(qs, ot);
     }
     string url = Util.URLCombine(CmsHost, "/OnlineReg/SendLink/{0}".Fmt(ot.Id.ToCode()));
     return url;
 }
Exemple #31
0
 public string RegisterLinkUrl(int orgid, int pid, int queueid, bool showfamily = false)
 {
     string qs = "{0},{1},{2}".Fmt(orgid, pid, queueid);
     var ot = new OneTimeLink
         {
             Id = Guid.NewGuid(),
             Querystring = qs
         };
     OneTimeLinks.InsertOnSubmit(ot);
     SubmitChanges();
     string url = Util.URLCombine(CmsHost, "/OnlineReg/RegisterLink/{0}".Fmt(ot.Id.ToCode()));
     if (showfamily)
         url += "?showfamily=true";
     return url;
 }
Exemple #32
0
        private string SendLink(string code, EmailQueueTo emailqueueto)
        {
            var list = new Dictionary<string, OneTimeLink>();

            var doc = new HtmlDocument();
            doc.LoadHtml(code);
            var ele = doc.DocumentNode.Element("a");
            var inside = ele.InnerHtml.Replace("{last}", person.LastName);
            var d = ele.Attributes.ToDictionary(aa => aa.Name.ToString(), aa => aa.Value);

            var id = GetId(d, "SendLink");

            var showfamily = code.Contains("sendlink2", ignoreCase: true);
            var qs = $"{id},{emailqueueto.PeopleId},{emailqueueto.Id},{(showfamily ? "registerlink2" : "registerlink")}";

            OneTimeLink ot;
            if (list.ContainsKey(qs))
                ot = list[qs];
            else
            {
                ot = new OneTimeLink
                {
                    Id = Guid.NewGuid(),
                    Querystring = qs
                };
                db.OneTimeLinks.InsertOnSubmit(ot);
                db.SubmitChanges();
                list.Add(qs, ot);
            }
            var url = db.ServerLink($"/OnlineReg/SendLink/{ot.Id.ToCode()}");
            return $@"<a href=""{url}"">{inside}</a>";
        }
Exemple #33
0
        private string SendSupportLinkUrl(EmailQueueTo emailqueueto, Dictionary<string, OneTimeLink> list)
        {
            string qs = "{0},{1},{2},{3},{4}".Fmt(emailqueueto.OrgId, emailqueueto.PeopleId, emailqueueto.Id, "supportlink", emailqueueto.GoerSupportId);

            OneTimeLink ot;
            if (list.ContainsKey(qs))
                ot = list[qs];
            else
            {
                ot = new OneTimeLink
                    {
                        Id = Guid.NewGuid(),
                        Querystring = qs
                    };
                OneTimeLinks.InsertOnSubmit(ot);
                SubmitChanges();
                list.Add(qs, ot);
            }
            string url = Util.URLCombine(CmsHost, "/OnlineReg/SendLink/{0}".Fmt(ot.Id.ToCode()));
            return url;
        }
Exemple #34
0
        private string VolSubLink(string code, EmailQueueTo emailqueueto)
        {
            var list = new Dictionary<string, OneTimeLink>();

            var doc = new HtmlDocument();
            doc.LoadHtml(code);
            var ele = doc.DocumentNode.Element("a");
            var inside = ele.InnerHtml.Replace("{last}", person.LastName);
            var d = ele.Attributes.ToDictionary(aa => aa.Name.ToString(), aa => aa.Value);

            var qs = $"{d["aid"]},{d["pid"]},{d["ticks"]},{emailqueueto.PeopleId}";
            OneTimeLink ot = null;
            if (list.ContainsKey(qs))
                ot = list[qs];
            else
            {
                ot = new OneTimeLink
                {
                    Id = Guid.NewGuid(),
                    Querystring = qs
                };
                db.OneTimeLinks.InsertOnSubmit(ot);
                db.SubmitChanges();
                list.Add(qs, ot);
            }

            var url = db.ServerLink($"/OnlineReg/ClaimVolSub/{d["ans"]}/{ot.Id.ToCode()}");
            return $@"<a href=""{url}"">{inside}</a>";
        }
Exemple #35
0
        private string VoteLinkReplacement(string code, EmailQueueTo emailqueueto)
        {
            //<a dir="ltr" href="http://votelink" id="798" rel="smallgroup" title="This is a message">test</a>
            var list = new Dictionary <string, OneTimeLink>();

            var doc = new HtmlDocument();

            doc.LoadHtml(code);
            var ele    = doc.DocumentNode.Element("a");
            var inside = ele.InnerHtml.Replace("{last}", person.LastName);
            var d      = ele.Attributes.ToDictionary(aa => aa.Name.ToString(), aa => aa.Value);

            var msg = "Thank you for responding.";

            if (d.ContainsKey("title"))
            {
                msg = d["title"];
            }

            var confirm = "false";

            if (d.ContainsKey("dir") && d["dir"] == "ltr")
            {
                confirm = "true";
            }

            if (!d.ContainsKey("rel"))
            {
                throw new Exception("Votelink: no smallgroup attribute");
            }
            var smallgroup = d["rel"];
            var pre        = "";
            var a          = smallgroup.SplitStr(":");

            if (a.Length > 1)
            {
                pre = a[0];
            }

            var id = GetId(d, "VoteLink");

            var         qs = $"{id},{emailqueueto.PeopleId},{emailqueueto.Id},{pre},{smallgroup}";
            OneTimeLink ot;

            if (list.ContainsKey(qs))
            {
                ot = list[qs];
            }
            else
            {
                ot = new OneTimeLink
                {
                    Id          = Guid.NewGuid(),
                    Querystring = qs
                };
                db.OneTimeLinks.InsertOnSubmit(ot);
                db.SubmitChanges();
                list.Add(qs, ot);
            }
            var url = db.ServerLink(
                $"/OnlineReg/VoteLinkSg/{ot.Id.ToCode()}?confirm={confirm}&message={HttpUtility.UrlEncode(msg)}");

            return($@"<a href=""{url}"">{inside}</a>");
        }
        public ActionResult AuthenticatedLink(string data)
        {
            var result = AuthenticateUser();
            if (!result.IsValid) return AuthorizationError(result);

            // Link in data string is path only include leading slash
            var dataIn = BaseMessage.createFromString(data);

            var ot = new OneTimeLink
            {
                Id = Guid.NewGuid(),
                Querystring = Util.UserName,
                Expires = DateTime.Now.AddMinutes(15)
            };

            DbUtil.Db.OneTimeLinks.InsertOnSubmit(ot);
            DbUtil.Db.SubmitChanges();

            var br = new BaseMessage();
            br.setNoError();
            br.data = $"{DbUtil.Db.ServerLink($"Logon?ReturnUrl={HttpUtility.UrlEncode(dataIn.argString)}&otltoken={ot.Id.ToCode()}")}";

            return br;
        }
Exemple #37
0
        private string VoteLink(string code, EmailQueueTo emailqueueto)
        {
            //<a dir="ltr" href="http://votelink" id="798" rel="smallgroup" title="This is a message">test</a>
            var list = new Dictionary<string, OneTimeLink>();

            var doc = new HtmlDocument();
            doc.LoadHtml(code);
            var ele = doc.DocumentNode.Element("a");
            var inside = ele.InnerHtml.Replace("{last}", person.LastName);
            var d = ele.Attributes.ToDictionary(aa => aa.Name.ToString(), aa => aa.Value);

            var msg = "Thank you for responding.";
            if (d.ContainsKey("title"))
                msg = d["title"];

            var confirm = "false";
            if (d.ContainsKey("dir") && d["dir"] == "ltr")
                confirm = "true";

            if (!d.ContainsKey("rel"))
                throw new Exception("Votelink: no smallgroup attribute");
            var smallgroup = d["rel"];
            var pre = "";
            var a = smallgroup.SplitStr(":");
            if (a.Length > 1)
                pre = a[0];

            var id = GetId(d, "VoteLink");

            var qs = $"{id},{emailqueueto.PeopleId},{emailqueueto.Id},{pre},{smallgroup}";
            OneTimeLink ot;
            if (list.ContainsKey(qs))
                ot = list[qs];
            else
            {
                ot = new OneTimeLink
                {
                    Id = Guid.NewGuid(),
                    Querystring = qs
                };
                db.OneTimeLinks.InsertOnSubmit(ot);
                db.SubmitChanges();
                list.Add(qs, ot);
            }
            var url = db.ServerLink(
                $"/OnlineReg/VoteLinkSg/{ot.Id.ToCode()}?confirm={confirm}&message={HttpUtility.UrlEncode(msg)}");
            return $@"<a href=""{url}"">{inside}</a>";
        }
Exemple #38
0
        private string UnlayerLinkReplacement(string code, EmailQueueTo emailqueueto)
        {
            var list = new Dictionary <string, OneTimeLink>();

            // remove the non url parts and reformat
            code = code.Replace("\"", string.Empty);
            code = code.Replace("&amp;", "&");
            code = HttpUtility.UrlDecode(code);

            // parse the special link url to get the component parts
            Uri    SpecialLink = new Uri(code);
            string type        = SpecialLink.Host;
            string orgId       = HttpUtility.ParseQueryString(SpecialLink.Query).Get("org");
            string meetingId   = HttpUtility.ParseQueryString(SpecialLink.Query).Get("meeting");
            string groupId     = HttpUtility.ParseQueryString(SpecialLink.Query).Get("group");
            string confirm     = HttpUtility.ParseQueryString(SpecialLink.Query).Get("confirm");
            string message     = HttpUtility.ParseQueryString(SpecialLink.Query).Get("msg");

            // result variables
            string qs;      // the unique link combination for the db
            string url = "";

            // set some defaults for any missing properties
            bool showfamily = false;

            if (!message.HasValue())
            {
                message = "Thank you for responding.";
            }
            if (!confirm.HasValue())
            {
                confirm = "false";
            }

            // generate the one time link code and update any vars based on the link type
            switch (type)
            {
            case "rsvplink":
            case "regretslink":
                qs = $"{meetingId},{emailqueueto.PeopleId},{emailqueueto.Id},{groupId}";
                break;

            case "registerlink":
            case "registerlink2":
                showfamily = (type == "registerlink2");
                qs         = $"{orgId},{emailqueueto.PeopleId},{emailqueueto.Id}";
                break;

            case "sendlink":
            case "sendlink2":
                showfamily = (type == "sendlink2");
                qs         = $"{orgId},{emailqueueto.PeopleId},{emailqueueto.Id},{(showfamily ? "registerlink2" : "registerlink")}";
                break;

            case "supportlink":
                qs = $"{orgId},{emailqueueto.PeopleId},{emailqueueto.Id},{"supportlink"}:{emailqueueto.GoerSupportId}";
                break;

            case "votelink":
                string pre = "";
                var    a   = groupId.SplitStr(":");
                if (a.Length > 1)
                {
                    pre = a[0];
                }
                qs = $"{orgId},{emailqueueto.PeopleId},{emailqueueto.Id},{pre},{groupId}";
                break;

            default:
                return(code);
            }

            OneTimeLink ot;

            if (list.ContainsKey(qs))
            {
                ot = list[qs];
            }
            else
            {
                ot = new OneTimeLink
                {
                    Id          = Guid.NewGuid(),
                    Querystring = qs
                };
                db.OneTimeLinks.InsertOnSubmit(ot);
                db.SubmitChanges();
                list.Add(qs, ot);
            }

            // generate the one time link url based on the one time link id
            switch (type)
            {
            case "rsvplink":
            case "regretslink":
                url = db.ServerLink($"/OnlineReg/RsvpLinkSg/{ot.Id.ToCode()}?confirm={confirm}&message={HttpUtility.UrlEncode(message)}");
                if (type == "regretslink")
                {
                    url += "&regrets=true";
                }
                break;

            case "registerlink":
            case "registerlink2":
                url = db.ServerLink($"/OnlineReg/RegisterLink/{ot.Id.ToCode()}");
                if (showfamily)
                {
                    url += "?showfamily=true";
                }
                break;

            case "sendlink":
            case "sendlink2":
            case "supportlink":
                url = db.ServerLink($"/OnlineReg/SendLink/{ot.Id.ToCode()}");
                break;

            case "votelink":
                url = db.ServerLink($"/OnlineReg/VoteLinkSg/{ot.Id.ToCode()}?confirm={confirm}&message={HttpUtility.UrlEncode(message)}");
                break;
            }
            return(url);
        }
Exemple #39
0
 public static string RegisterLinkUrl(CMSDataContext db, int orgid, int pid, int queueid, string linktype, DateTime? expires = null)
 {
     var showfamily = linktype == "registerlink2";
     var qs = $"{orgid},{pid},{queueid},{linktype}";
     var ot = new OneTimeLink
     {
         Id = Guid.NewGuid(),
         Querystring = qs,
     };
     if (expires.HasValue)
         ot.Expires = expires.Value;
     db.OneTimeLinks.InsertOnSubmit(ot);
     db.SubmitChanges();
     var url = db.ServerLink($"/OnlineReg/RegisterLink/{ot.Id.ToCode()}");
     if (showfamily)
         url += "?showfamily=true";
     return url;
 }
Exemple #40
0
        public string DoVolSubLink(string text, EmailQueueTo emailqueueto)
        {
            var list = new Dictionary<string, OneTimeLink>();
            const string VolSubLinkRE = "<a[^>]*?href=\"https{0,1}://volsublink\"[^>]*>.*?</a>";
            var re = new Regex(VolSubLinkRE, RegexOptions.Singleline | RegexOptions.Multiline | RegexOptions.IgnoreCase);
            Match match = re.Match(text);
            while (match.Success)
            {
                string tag = match.Value;

                var doc = new HtmlDocument();
                doc.LoadHtml(tag);
                HtmlNode ele = doc.DocumentNode.Element("a");
                string inside = ele.InnerHtml;
                Dictionary<string, string> d = ele.Attributes.ToDictionary(aa => aa.Name.ToString(), aa => aa.Value);

                string qs = "{0},{1},{2},{3}"
                    .Fmt(d["aid"], d["pid"], d["ticks"], emailqueueto.PeopleId);
                OneTimeLink ot = null;
                if (list.ContainsKey(qs))
                    ot = list[qs];
                else
                {
                    ot = new OneTimeLink
                        {
                            Id = Guid.NewGuid(),
                            Querystring = qs
                        };
                    OneTimeLinks.InsertOnSubmit(ot);
                    SubmitChanges();
                    list.Add(qs, ot);
                }

                string url = Util.URLCombine(CmsHost, "/OnlineReg/ClaimVolSub/{0}/{1}".Fmt(d["ans"], ot.Id.ToCode()));
                text = text.Replace(tag, @"<a href=""{0}"">{1}</a>".Fmt(url, inside));
                match = match.NextMatch();
            }
            return text;
        }
Exemple #41
0
 private string CreateUserTag(EmailQueueTo emailqueueto)
 {
     User user = (from u in db.Users
                  where u.PeopleId == emailqueueto.PeopleId
                  select u).FirstOrDefault();
     if (user != null)
     {
         user.ResetPasswordCode = Guid.NewGuid();
         user.ResetPasswordExpires = DateTime.Now.AddHours(db.Setting("ResetPasswordExpiresHours", "24").ToInt());
         string link = db.ServerLink("/Account/SetPassword/" + user.ResetPasswordCode.ToString());
         db.SubmitChanges();
         return $@"<a href=""{link}"">Set password for {user.Username}</a>";
     }
     var ot = new OneTimeLink
     {
         Id = Guid.NewGuid(),
         Querystring = emailqueueto.PeopleId.ToString()
     };
     db.OneTimeLinks.InsertOnSubmit(ot);
     db.SubmitChanges();
     var url = db.ServerLink($"/Account/CreateAccount/{ot.Id.ToCode()}");
     return $@"<a href=""{url}"">Create Account</a>";
 }
Exemple #42
0
 private string RegisterTagUrl(string text,
                               EmailQueueTo emailqueueto,
                               Dictionary<string, OneTimeLink> list,
                               string votelink,
                               string id,
                               bool showfamily = false)
 {
     string qs = "{0},{1},{2}".Fmt(id, emailqueueto.PeopleId, emailqueueto.Id);
     OneTimeLink ot;
     if (list.ContainsKey(qs))
         ot = list[qs];
     else
     {
         ot = new OneTimeLink
             {
                 Id = Guid.NewGuid(),
                 Querystring = qs
             };
         OneTimeLinks.InsertOnSubmit(ot);
         SubmitChanges();
         list.Add(qs, ot);
     }
     string url = Util.URLCombine(CmsHost, "/OnlineReg/RegisterLink/{0}".Fmt(ot.Id.ToCode()));
     if (showfamily)
         url += "?showfamily=true";
     return url;
 }
Exemple #43
0
        private string RegisterLinkHref(string code, EmailQueueTo emailqueueto)
        {
            var list = new Dictionary<string, OneTimeLink>();

            var match = RegisterHrefReId.Match(code);
            if (!match.Success)
                return code;
            var id = match.Groups["id"].Value.ToInt();

            var showfamily = code.Contains("registerlink2", ignoreCase: true);
            string qs = $"{id},{emailqueueto.PeopleId},{emailqueueto.Id}";
            OneTimeLink ot;
            if (list.ContainsKey(qs))
                ot = list[qs];
            else
            {
                ot = new OneTimeLink
                {
                    Id = Guid.NewGuid(),
                    Querystring = qs
                };
                db.OneTimeLinks.InsertOnSubmit(ot);
                db.SubmitChanges();
                list.Add(qs, ot);
            }
            string url = db.ServerLink($"/OnlineReg/RegisterLink/{ot.Id.ToCode()}");
            if (showfamily)
                url += "?showfamily=true";
            return $"href=\"{url}\"";
        }
Exemple #44
0
 public static string RegisterLinkUrl(CMSDataContext db, int orgid, int pid, int queueid, string linktype)
 {
     var showfamily = linktype == "registerlink2";
     string qs = "{0},{1},{2},{3}".Fmt(orgid, pid, queueid, linktype);
     var ot = new OneTimeLink
         {
             Id = Guid.NewGuid(),
             Querystring = qs
         };
     db.OneTimeLinks.InsertOnSubmit(ot);
     db.SubmitChanges();
     string url = Util.URLCombine(db.CmsHost, "/OnlineReg/RegisterLink/{0}".Fmt(ot.Id.ToCode()));
     if (showfamily)
         url += "?showfamily=true";
     return url;
 }
Exemple #45
0
        public static void ForgotPassword(string username)
        {
            // first find a user with the email address or username
            string msg = null;
            var path = new StringBuilder();

            username = username.Trim();
            var q = DbUtil.Db.Users.Where(uu =>
                 uu.Username == username ||
                 uu.Person.EmailAddress == username ||
                 uu.Person.EmailAddress2 == username
                 );
            if (!q.Any())
            {
                path.Append("u0");
                // could not find a user to match
                // so we look for a person without an account, to match the email address

                var minage = DbUtil.Db.Setting("MinimumUserAge", "16").ToInt();
                var q2 = from uu in DbUtil.Db.People
                            where uu.EmailAddress == username || uu.EmailAddress2 == username
                            where uu.Age == null || uu.Age >= minage
                            select uu;
                if (q2.Any())
                {
                    path.Append("p+");
                    // we found person(s), not a user
                    // we will compose an email for each of them to create an account
                    foreach (var p in q2)
                    {
                        var ot = new OneTimeLink
                        {
                            Id = Guid.NewGuid(),
                            Querystring = p.PeopleId.ToString()
                        };
                        DbUtil.Db.OneTimeLinks.InsertOnSubmit(ot);
                        DbUtil.Db.SubmitChanges();
                        var url = DbUtil.Db.ServerLink($"/Account/CreateAccount/{ot.Id.ToCode()}");
                        msg = DbUtil.Db.ContentHtml("ForgotPasswordReset", Resource1.AccountModel_ForgotPasswordReset);
                        msg = msg.Replace("{name}", p.Name);
                        msg = msg.Replace("{first}", p.PreferredName);
                        msg = msg.Replace("{email}", username);
                        msg = msg.Replace("{resetlink}", url);
                        Util.SendMsg(ConfigurationManager.AppSettings["sysfromemail"],
                             DbUtil.Db.CmsHost, Util.FirstAddress(DbUtil.AdminMail),
                             "touchpointsoftware new password link", msg, Util.ToMailAddressList(p.EmailAddress ?? p.EmailAddress2), 0, null);
                    }
                    DbUtil.LogActivity($"ForgotPassword ('{username}', {path})");
                    return;
                }
                path.Append("p0");
                if (!Util.ValidEmail(username))
                {
                    DbUtil.LogActivity($"ForgotPassword ('{username}', {path})");
                    return;
                }
                path.Append("n0");

                msg = DbUtil.Db.ContentHtml("ForgotPasswordBadEmail", Resource1.AccountModel_ForgotPasswordBadEmail);
                msg = msg.Replace("{email}", username);
                Util.SendMsg(ConfigurationManager.AppSettings["sysfromemail"],
                     DbUtil.Db.CmsHost, Util.FirstAddress(DbUtil.AdminMail),
                     "Forgot password request for " + DbUtil.Db.Setting("NameOfChurch", "bvcms"),
                     msg, Util.ToMailAddressList(username), 0, null);
                DbUtil.LogActivity($"ForgotPassword ('{username}', {path})");
                return;
            }
            path.Append("u+");

            // we found users who match,
            // so now we send the users who match the username or email a set of links to all their usernames

            var sb = new StringBuilder();
            var addrlist = new List<MailAddress>();
            foreach (var user in q)
            {
                Util.AddGoodAddress(addrlist, user.EmailAddress);
                user.ResetPasswordCode = Guid.NewGuid();
                user.ResetPasswordExpires = DateTime.Now.AddHours(DbUtil.Db.Setting("ResetPasswordExpiresHours", "24").ToInt());
                var link = DbUtil.Db.ServerLink($"/Account/SetPassword/{user.ResetPasswordCode}");
                sb.Append($@"{user.Name}, <a href=""{link}"">{user.Username}</a><br>");
                DbUtil.Db.SubmitChanges();
            }
            msg = DbUtil.Db.ContentHtml("ForgotPasswordReset2", Resource1.AccountModel_ForgotPasswordReset2);
            msg = msg.Replace("{email}", username);
            msg = msg.Replace("{resetlink}", sb.ToString());
            Util.SendMsg(ConfigurationManager.AppSettings["sysfromemail"],
                 DbUtil.Db.CmsHost, Util.FirstAddress(DbUtil.AdminMail),
                 "TouchPoint password reset link", msg, addrlist, 0, null);
            DbUtil.LogActivity($"ForgotPassword ('{username}', {path})");
        }
Exemple #46
0
        public static string ForgotPassword(string username)
        {
            username = username.Trim();
            var q = DbUtil.Db.Users.Where(uu =>
                uu.Username == username ||
                uu.Person.EmailAddress == username ||
                uu.Person.EmailAddress2 == username
                );
            var list = q.ToList();
            if (list.Count == 0)
            {
                var minage = DbUtil.Db.Setting("MinimumUserAge", "16").ToInt();
                var q2 = from uu in DbUtil.Db.People
                         where uu.EmailAddress == username || uu.EmailAddress2 == username
                         where uu.Age == null || uu.Age >= minage
                         select uu;
                if (q2.Count() == 1)
                {
                    var p = q2.Single();

                    var ot = new OneTimeLink
                    {
                        Id = Guid.NewGuid(),
                        Querystring = p.PeopleId.ToString()
                    };
                    DbUtil.Db.OneTimeLinks.InsertOnSubmit(ot);
                    DbUtil.Db.SubmitChanges();
                    var url = Util.ServerLink("/Account/CreateAccount/{0}".Fmt(ot.Id.ToCode()));
                    var message = DbUtil.Db.ContentHtml("ForgotPasswordReset", Resource1.AccountModel_ForgotPasswordReset);
                    message = message.Replace("{email}", username);
                    message = message.Replace("{resetlink}", url);
                    Util.SendMsg(ConfigurationManager.AppSettings["sysfromemail"],
                        DbUtil.Db.CmsHost, Util.FirstAddress(DbUtil.AdminMail),
                        "bvcms new password link", message, Util.ToMailAddressList(p.EmailAddress ?? p.EmailAddress2), 0, null);
                    return Util.ObscureEmail(p.EmailAddress ?? p.EmailAddress2);
                }
                if (Util.ValidEmail(username)) // did not find their email address, let them know this
                {
                    var message = DbUtil.Db.ContentHtml("ForgotPasswordBadEmail", Resource1.AccountModel_ForgotPasswordBadEmail);
                    message = message.Replace("{email}", username);
                    Util.SendMsg(ConfigurationManager.AppSettings["sysfromemail"],
                        DbUtil.Db.CmsHost, Util.FirstAddress(DbUtil.AdminMail),
                        "Forgot password request for " + DbUtil.Db.Setting("NameOfChurch", "bvcms"),
                        message, Util.ToMailAddressList(username), 0, null);
                    return Util.ObscureEmail(username);
                }
                return null;
            }
            else
            {
                var sb = new StringBuilder();
                var addrlist = new List<MailAddress>();
                foreach (var user in list)
                {
                    Util.AddGoodAddress(addrlist, user.EmailAddress);
                    user.ResetPasswordCode = Guid.NewGuid();
                    user.ResetPasswordExpires = DateTime.Now.AddHours(DbUtil.Db.Setting("ResetPasswordExpiresHours", "24").ToInt());
                    var link = Util.ServerLink("/Account/SetPassword/" + user.ResetPasswordCode.ToString());
                    sb.AppendFormat(@"{0}, <a href=""{1}"">{2}</a><br>", user.Name, link, user.Username);
                    DbUtil.Db.SubmitChanges();
                }
                var message = DbUtil.Db.ContentHtml("ForgotPasswordReset2", Resource1.AccountModel_ForgotPasswordReset2);
                message = message.Replace("{email}", username);
                message = message.Replace("{resetlink}", sb.ToString());
                Util.SendMsg(ConfigurationManager.AppSettings["sysfromemail"],
                    DbUtil.Db.CmsHost, Util.FirstAddress(DbUtil.AdminMail),
                    "bvcms password reset link", message, addrlist, 0, null);
                if(addrlist.Count > 0)
                    return Util.ObscureEmail(addrlist[0].Address);
                return "no email address";
            }
        }
Exemple #47
0
        private string SendLink(string code, EmailQueueTo emailqueueto)
        {
            var list = new Dictionary<string, OneTimeLink>();

            var doc = new HtmlDocument();
            doc.LoadHtml(code);
            HtmlNode ele = doc.DocumentNode.Element("a");
            string inside = ele.InnerHtml;
            Dictionary<string, string> d = ele.Attributes.ToDictionary(aa => aa.Name.ToString(), aa => aa.Value);

            var id = GetId(d, "SendLink");

            var showfamily = code.Contains("sendlink2", ignoreCase: true);
            string qs = "{0},{1},{2},{3}".Fmt(id, emailqueueto.PeopleId, emailqueueto.Id,
                showfamily ? "registerlink2" : "registerlink");

            OneTimeLink ot;
            if (list.ContainsKey(qs))
                ot = list[qs];
            else
            {
                ot = new OneTimeLink
                    {
                        Id = Guid.NewGuid(),
                        Querystring = qs
                    };
                db.OneTimeLinks.InsertOnSubmit(ot);
                db.SubmitChanges();
                list.Add(qs, ot);
            }
            string url = Util.URLCombine(db.CmsHost, "/OnlineReg/SendLink/{0}".Fmt(ot.Id.ToCode()));
            return @"<a href=""{0}"">{1}</a>".Fmt(url, inside);
        }