OriginalUsername() 공개 정적인 메소드

public static OriginalUsername ( string userName ) : string
userName string
리턴 string
예제 #1
0
        // a method to send a private message to a user, invoked by other methods
        public static bool SendPrivateMessage(string sender, string recipientList, string subject, string body)
        {
            if (Voat.Utilities.UserHelper.IsUserGloballyBanned(System.Web.HttpContext.Current.User.Identity.Name))
            {
                return(false);
            }

            if (Voat.Utilities.Karma.CommentKarma(System.Web.HttpContext.Current.User.Identity.Name) < 10)
            {
                return(false);
            }

            List <PrivateMessage> messages = new List <PrivateMessage>();
            MatchCollection       col      = Regex.Matches(recipientList, @"((?'prefix'@|u/|/u/|v/|/v/)?(?'recipient'[\w-.]+))", RegexOptions.IgnoreCase);

            foreach (Match m in col)
            {
                var recipient = m.Groups["recipient"].Value;
                var prefix    = m.Groups["prefix"].Value;

                if (!String.IsNullOrEmpty(prefix) && prefix.ToLower().Contains("v"))
                {
                    //don't allow banned users to send to subverses
                    if (!UserHelper.IsUserBannedFromSubverse(System.Web.HttpContext.Current.User.Identity.Name, recipient))
                    {
                        //send to subverse mods
                        using (var db = new voatEntities())
                        {
                            //designed to limit abuse by taking the level 1 mod and the next four oldest
                            var mods = (from mod in db.SubverseModerators
                                        where mod.Subverse.Equals(recipient, StringComparison.OrdinalIgnoreCase) && mod.UserName != "system" && mod.UserName != "youcanclaimthissub"
                                        orderby mod.Power ascending, mod.CreationDate descending
                                        select mod).Take(5);

                            foreach (var moderator in mods)
                            {
                                messages.Add(new PrivateMessage
                                {
                                    Sender         = sender,
                                    Recipient      = moderator.UserName,
                                    CreationDate   = DateTime.Now,
                                    Subject        = String.Format("[v/{0}] {1}", recipient, subject),
                                    Body           = body,
                                    IsUnread       = true,
                                    MarkedAsUnread = false
                                });
                            }
                        }
                    }
                }
                else
                {
                    //ensure proper cased
                    recipient = UserHelper.OriginalUsername(recipient);

                    if (Voat.Utilities.UserHelper.UserExists(recipient))
                    {
                        messages.Add(new PrivateMessage
                        {
                            Sender         = sender,
                            Recipient      = recipient,
                            CreationDate   = DateTime.Now,
                            Subject        = subject,
                            Body           = body,
                            IsUnread       = true,
                            MarkedAsUnread = false
                        });
                    }
                }
            }

            if (messages.Count > 0)
            {
                using (var db = new voatEntities())
                {
                    try
                    {
                        db.PrivateMessages.AddRange(messages);
                        db.SaveChanges();
                    }
                    catch (Exception)
                    {
                        return(false);
                    }
                }
            }
            return(true);
        }
예제 #2
0
        // a method to send a private message to a user, invoked by other methods
        public static bool SendPrivateMessage(string sender, string recipientList, string subject, string body)
        {
            if (Voat.Utilities.UserHelper.IsUserGloballyBanned(System.Web.HttpContext.Current.User.Identity.Name))
            {
                return(false);
            }

            if (Voat.Utilities.Karma.CommentKarma(System.Web.HttpContext.Current.User.Identity.Name) < 10)
            {
                return(false);
            }

            List <PrivateMessage> messages = new List <PrivateMessage>();
            MatchCollection       col      = Regex.Matches(recipientList, @"((?'prefix'@|u/|/u/|v/|/v/)?(?'recipient'[\w-.]+))", RegexOptions.IgnoreCase);

            if (col.Count <= 0)
            {
                return(false);
            }

            //Have to filter distinct because of spamming. If you copy a user name
            //1,000 times into the recipient list the previous
            //logic would send that user 1,000 messages. These guys find everything.
            var filtered = (from x in col.Cast <Match>()
                            select new
            {
                recipient = x.Groups["recipient"].Value,
                prefix = (x.Groups["prefix"].Value.ToLower().Contains("v") ? "v" : "")                 //stop users from sending multiple messages using diff prefixes @user, /u/user, and u/user
            }).Distinct();

            foreach (var m in filtered)
            {
                var recipient = m.recipient;
                var prefix    = m.prefix;

                if (!String.IsNullOrEmpty(prefix) && prefix.ToLower().Contains("v"))
                {
                    //don't allow banned users to send to subverses
                    if (!UserHelper.IsUserBannedFromSubverse(System.Web.HttpContext.Current.User.Identity.Name, recipient))
                    {
                        //send to subverse mods
                        using (var db = new voatEntities())
                        {
                            //designed to limit abuse by taking the level 1 mod and the next four oldest
                            var mods = (from mod in db.SubverseModerators
                                        where mod.Subverse.Equals(recipient, StringComparison.OrdinalIgnoreCase) && mod.UserName != "system" && mod.UserName != "youcanclaimthissub"
                                        orderby mod.Power ascending, mod.CreationDate descending
                                        select mod).Take(5);

                            foreach (var moderator in mods)
                            {
                                messages.Add(new PrivateMessage
                                {
                                    Sender         = sender,
                                    Recipient      = moderator.UserName,
                                    CreationDate   = DateTime.Now,
                                    Subject        = String.Format("[v/{0}] {1}", recipient, subject),
                                    Body           = body,
                                    IsUnread       = true,
                                    MarkedAsUnread = false
                                });
                            }
                        }
                    }
                }
                else
                {
                    //ensure proper cased
                    recipient = UserHelper.OriginalUsername(recipient);

                    if (Voat.Utilities.UserHelper.UserExists(recipient))
                    {
                        messages.Add(new PrivateMessage
                        {
                            Sender         = sender,
                            Recipient      = recipient,
                            CreationDate   = DateTime.Now,
                            Subject        = subject,
                            Body           = body,
                            IsUnread       = true,
                            MarkedAsUnread = false
                        });
                    }
                }
            }

            if (messages.Count > 0)
            {
                using (var db = new voatEntities())
                {
                    try
                    {
                        db.PrivateMessages.AddRange(messages);
                        db.SaveChanges();
                    }
                    catch (Exception)
                    {
                        return(false);
                    }
                }
            }
            return(true);
        }