Example #1
0
        public async Task ToggleContainBadWord(string word)
        {
            BadWords badWords = new BadWords(Context.Guild);

            foreach (BadWord badWord in badWords.all)
            {
                if (badWord.word.ToLower() == word.ToLower())
                {
                    if (badWord.partOfWord)
                    {
                        badWord.partOfWord = false;
                        await ReplyAsync("Set badword to not be filtered if it's inside of another word");
                    }
                    else
                    {
                        badWord.partOfWord = true;
                        await ReplyAsync("Set badword to be filtered even if it's inside of another word");
                    }
                    BadWordList badWordList = new BadWordList {
                        badWords = badWords.all
                    };
                    badWordList.SaveToFile(Context.Guild);
                    return;
                }
            }
            await ReplyAsync("Badword not found");
        }
Example #2
0
        public IActionResult AddBadWord(BadWords w)
        {
            _assignContext.BadWords.Add(w);
            _assignContext.SaveChanges();

            return(RedirectToAction("ViewBadWords"));
        }
Example #3
0
    void OnMessage(Socket socket, Packet packet, params object[] args)
    {
        // token, username, message
        var json = (string)args[0];
        var data = JsonUtility.FromJson <MessageJSON>(json);
        //Debug.Log(json);

        var source = "[Global] ";
        var author = "<b>" + data.username + "</b>: ";
        var text   = new BadWords().FilterProfanity(data.message);

        if (data.username == "")
        {
            ticker = text;
        }
        else
        {
            if (messageList.Count >= maxMessages)
            {
                Destroy(messageList[0].obj.gameObject);
                messageList.Remove(messageList[0]);
            }

            var res = Resources.Load("Message", typeof(GameObject));
            var obj = Instantiate(res, content.transform) as GameObject;
            var tmp = obj.GetComponentInChildren <TextMeshProUGUI>();
            var str = source + author + text;

            var messageObject = new MessageObject(str, obj);
            tmp.text = str;
            messageList.Add(messageObject);
        }
    }
Example #4
0
        public IActionResult AddBadWordToDatabase()
        {
            BadWords badWordToAdd = new BadWords();

            badWordToAdd.Word = HttpContext.Request.Form["badword"];

            _context.BadWords.Add(badWordToAdd);

            _context.SaveChanges();

            return(RedirectToAction("ViewBadWords"));
        }
Example #5
0
        // Küfür ve kötü söz engelleme
        private IResult IfTheseArticlesContain(string articleWriting)
        {
            BadWords badWords = new BadWords();

            foreach (var item in badWords._word)
            {
                var result = articleWriting.Contains(item);
                if (result)
                {
                    return(new ErrorResult(Messages.YouCannotUseThesePosts));
                }
            }
            return(new SuccessResult());
        }
Example #6
0
        public IActionResult AddBadWords(BadWords item)
        {
            item.Word = Request.Form["BadWords.Word"];
            var existingWord = (from w in _Assignment2DataContext.BadWords where w.Word.ToLower() == item.Word.ToLower() select w).FirstOrDefault();

            if (existingWord == null)
            {
                _Assignment2DataContext.BadWords.Add(item);
                _Assignment2DataContext.SaveChanges();
                return(RedirectToAction("ViewBadWords"));
            }
            TempData["Exist"] = "BadWords";
            return(RedirectToAction("ViewBadWords"));
        }
Example #7
0
    private bool IsProfanity(string username)
    {
        var input = new BadWords().FilterProfanity(username);

        if (input == username)
        {
            return(true);
        }
        else
        {
            network.Status = "bad";
            return(false);
        }
    }
        public void TestBadWordDetection()
        {
            string teststring1 = "f u c k";
            string teststring2 = "quick f u c k fox";
            string teststring3 = "quick brown f u c k";
            string teststring4 = "fuckasshole";
            string teststring5 = "swank";
            string teststring6 = "wank";

            Assert.IsTrue(BadWords.ContainsBadWord(teststring1));
            Assert.IsTrue(BadWords.ContainsBadWord(teststring2));
            Assert.IsTrue(BadWords.ContainsBadWord(teststring3));
            Assert.IsTrue(BadWords.ContainsBadWord(teststring4));
            Assert.IsTrue(BadWords.ContainsBadWord(teststring5));
            Assert.IsTrue(BadWords.ContainsBadWord(teststring6));
        }
Example #9
0
        public ActionResult Add(StoreTable storeTable)
        {
            ModelContainer context = new ModelContainer();
            List <Link>    link    = new List <Link> {
                new Link
                {
                    addDate   = DateTime.Now,
                    lastVisit = DateTime.Now.AddDays(-20),
                    status    = true,
                    link      = "http://" + storeTable.baseURL,
                }
            };

            List <BadWords> badwords = new List <BadWords>();
            List <string>   bwords   = storeTable.badwords[0].Split(',').ToList();

            foreach (string badword in bwords)
            {
                BadWords bw = new BadWords
                {
                    badWord = badword.Trim()
                };
                badwords.Add(bw);
            }

            Store store = new Store
            {
                name                  = storeTable.storeName,
                baseUrl               = storeTable.baseURL,
                currency              = storeTable.currency,
                titleSelector         = storeTable.titleSelector,
                originalPriceSelector = storeTable.originalPriceSelector,
                salePriceSelector     = storeTable.salePriceSelector,
                Link                  = link,
                BadWords              = badwords
            };

            context.Stores.Add(store);
            context.SaveChanges();

            return(RedirectToAction("Index"));
        }
Example #10
0
        /// <summary>
        /// Constructs a new world.
        ///
        ///     <para>With the given world id, it will find the configurations
        ///     set in the database, and configure this world using them. This
        ///     allows you to create multiple worlds, yet connect to the same
        ///     world, with the same players etc.</para>
        /// </summary>
        /// <param name="worldId">The id of this world.</param>
        public GameWorld(uint worldId)
        {
            // World initializations
            this.Id = worldId;

            DataRow vars;

            // Grab the rest of the world-specific variables from the database.
            using (SqlDatabaseClient client = GameServer.Database.GetClient())
            {
                client.AddParameter("id", worldId);
                vars = client.ReadDataRow(
                    "SELECT * FROM worlds WHERE world_id = @id LIMIT 1;" +
                    "UPDATE characters SET online = '0' WHERE online = '1';" +
                    "UPDATE worlds SET startup_time = NOW() WHERE world_id = @id;");
            }

            if (vars != null)
            {
                this.Name           = (string)vars["world_name"];
                this.WelcomeMessage = (string)vars["welcome_message"];
                string[] coords = vars["spawn_point"].ToString().Split(',');
                this.SpawnPoint = Location.Create(
                    short.Parse(coords[0]),
                    short.Parse(coords[1]),
                    byte.Parse(coords[2]));
                this.Motw                   = (string)vars["motw"];
                this.ExperienceRate         = (int)vars["exp_rate"];
                this.AccountCreationEnabled = true;
                this.IdlingEnabled          = (bool)vars["enable_idling"];
            }
            else
            {
                throw new ArgumentException("No existing world with id '" + worldId + "'.");
            }

            // Load bad words.
            BadWords.Load();
        }
Example #11
0
        public async Task ListAutoMod(string extension = "", [Remainder] string whoCaresWhatGoesHere = null)
        {
            try {
                ModerationSettings settings = Context.Guild.LoadFromFile <ModerationSettings>();
                BadWords           badWords = new BadWords(Context.Guild);

                var embed = new EmbedBuilder();
                embed.Author = new EmbedAuthorBuilder().WithName("Automod information for " + Context.Guild.Name + " discord");
                string message = "";

                bool useExplicit = false;
                if (extension != null && extension.ToLower() == "explicit" || extension.ToLower() == "e")
                {
                    if ((Context.Message.Author as SocketGuildUser).CanWarn())
                    {
                        useExplicit = true;
                    }
                    else
                    {
                        await ReplyAsync("You lack the permissions for viewing explicit bad words");

                        return;
                    }
                }

                if (settings == null)
                {
                    embed.AddField("Moderation settings", "Are null", true);
                }
                else
                {
                    embed.AddField("Warn for posting invite", !settings.invitesAllowed, true);
                    if (settings.allowedLinks == null || settings.allowedLinks.Count == 0)
                    {
                        embed.AddField("Allowed links", "Links aren't moderated  ", true);
                    }
                    else
                    {
                        message = settings.allowedLinks.ListItems("\n");
                        if (message.NotEmpty())
                        {
                            embed.AddField("Allowed links", message, true);
                        }
                        if (settings.allowedToLink != null && settings.allowedToLink.Count > 0)
                        {
                            message = Context.Guild.Roles.Where(
                                role => (role.Permissions.Administrator && !role.IsManaged) || settings.allowedToLink.Contains(role.Id)).Select(role => role.Name).ToArray().ListItems("\n");
                            if (message.NotEmpty())
                            {
                                embed.AddField("Roles that can post links", message, true);
                            }
                        }
                    }
                    if (settings.allowedCaps > 0)
                    {
                        embed.AddField("Allowed caps", $"{settings.allowedCaps}% in msgs more than 5 long");
                    }
                    else
                    {
                        embed.AddField("Allowed caps", "Capitalization is not filtered");
                    }
                    string badUniEmojis = settings.badUEmojis?.ListItems("");
                    if (!badUniEmojis.IsNullOrEmpty())
                    {
                        embed.AddField("Banned Emojis", badUniEmojis, true);
                    }
                }
                if (badWords != null && badWords.all != null && badWords.all.Count > 0)
                {
                    List <string> words = new List <string>();
                    foreach (List <BadWord> group in badWords.grouped)
                    {
                        BadWord first = group.FirstOrDefault();
                        if (first != null)
                        {
                            string word = "";
                            if (useExplicit)
                            {
                                if (group.Count == 1 || group.All(badWord => badWord.size == first.size))
                                {
                                    word = $"[{first.size}x] ";
                                }
                                else
                                {
                                    var sizes = group.Select(badword => badword.size);
                                    word = $"[{sizes.Min()}-{sizes.Max()}x] ";
                                }
                                if (first.euphemism.NotEmpty())
                                {
                                    word += $"{first.euphemism} ";
                                }
                                word += $"({group.Select(badWord => badWord.word).ToArray().ListItems(", ")})";
                            }
                            else if (!first.euphemism.IsNullOrEmpty())
                            {
                                word = first.euphemism;
                            }
                            if (first.partOfWord && (!first.euphemism.IsNullOrEmpty() || useExplicit))
                            {
                                word += "⌝";
                            }
                            words.Add(word);
                        }
                        else
                        {
                            _ = new LogMessage(LogSeverity.Error, "Filter", "Empty badword list in badwords").Log();
                        }
                    }

                    /*foreach (BadWord badWord in badWords.all) { Old code
                     *  string word = "";
                     *  if (useExplicit) {
                     *      word = $"[{badWord.size}x] " ;
                     *      if (badWord.euphemism.NotEmpty()) word += $"{badWord.euphemism} ";
                     *      word += $"({badWord.word})";
                     *  }
                     *  else if (!badWord.euphemism.IsNullOrEmpty()) word = badWord.euphemism;
                     *  if (badWord.partOfWord && (useExplicit || !badWord.euphemism.IsNullOrEmpty())) {
                     *      word += "⌝";
                     *  }
                     *  words.Add(word);
                     * }*/
                    message = words.ListItems("\n");
                    embed.AddField("Badword euphemisms (not an exhaustive list)", message, false);
                }
                IDMChannel channel = Context.Message.Author.GetOrCreateDMChannelAsync().Result;
                if (channel != null)
                {
                    _ = channel.SendMessageAsync("The symbol '⌝' next to a word means that you can be warned for a word that contains the bad word", embed: embed.Build());
                }
                else
                {
                    _ = ReplyAsync(Context.Message.Author.Mention + " we can't send a message to your DMs");
                }
            } catch (Exception e) {
                _ = new LogMessage(LogSeverity.Error, "Settings", "Error", e).Log();
            }
        }
Example #12
0
        public static System.Web.Security.MembershipCreateStatus TryCreateIdentity(CSSDataContext db, string username, string password, string email, out Identity createdIdentity)
        {
            createdIdentity = null;

            if (BadWords.ContainsBadWord(username) == true)
            {
                return(System.Web.Security.MembershipCreateStatus.UserRejected);
            }

            foreach (char letter in username.ToArray())
            {
                if (Char.IsLetterOrDigit(letter) == false && letter != '_')
                {
                    return(System.Web.Security.MembershipCreateStatus.UserRejected);
                }
            }

            if (username.Length < 3 || username.Length > 17)
            {
                return(System.Web.Security.MembershipCreateStatus.UserRejected);
            }

            Identity newIdentity = new Identity();

            newIdentity.DateLastLogin             = DateTime.Now;
            newIdentity.LastGlobalMessageDelivery = DateTime.Now;

            // See if the login belongs to this user.
            var login = Login.FindLoginByUsernameOrCallsign(db, username, password);

            if (login == null)
            {
                // See if the login belongs to any user.
                if (db.Logins.FirstOrDefault(p => p.Username == username) != null)
                {
                    return(System.Web.Security.MembershipCreateStatus.DuplicateUserName);
                }

                if (db.Alias.FirstOrDefault(p => p.Callsign == username) != null)
                {
                    return(System.Web.Security.MembershipCreateStatus.DuplicateUserName);
                }

                // login is available, create a new one.
                login = new Login()
                {
                    Username    = username,
                    Password    = PasswordHash.CreateHash(password),
                    Email       = email,
                    DateCreated = DateTime.Now
                };
            }

            string callsignWithTags    = username;
            Alias  existingAlias       = null;
            var    aliasValidateResult = Alias.ValidateUsage(db, login, false, password, ref callsignWithTags, out existingAlias);

            if (aliasValidateResult == CheckAliasResult.InvalidLegacyPassword)
            {
                return(System.Web.Security.MembershipCreateStatus.InvalidPassword);
            }

            else if (Alias.ValidateUsage(db, login, false, password, ref callsignWithTags, out existingAlias) != CheckAliasResult.Available)
            {
                return(System.Web.Security.MembershipCreateStatus.InvalidUserName);
            }

            List <Alias> aliases = Alias.ListAliases(db, username);

            // Make sure no one else has this username as an alias.
            if (aliases.Count > 0)
            {
                return(System.Web.Security.MembershipCreateStatus.DuplicateUserName);
            }

            var alias = new Alias()
            {
                Callsign    = username,
                DateCreated = DateTime.Now,
                IsDefault   = true,
                IsActive    = true
            };

            login.Aliases.Add(alias);
            newIdentity.Logins.Add(login);
            login.Lobby_Logins.Add(new Lobby_Login()
            {
                Lobby = db.Lobbies.First(p => p.Name == "Production")
            });

            db.Identities.InsertOnSubmit(newIdentity);

            // Must be done by the caller.
            //db.SubmitChanges();

            createdIdentity = newIdentity;

            return(System.Web.Security.MembershipCreateStatus.Success);
        }
Example #13
0
        /// <summary>
        /// Check if the selected alias is available for this Login Account,
        /// if the alias is not previously associated with this Login, and it
        /// is available, create it.
        /// </summary>
        public static CheckAliasResult ValidateUsage(CSSDataContext db,
                                                     Login login, bool allowCreate, string legacyPassword, ref string callsignWithTags, out Alias alias)
        {
            alias = null;

            //Parse Callsign
            var match = Regex.Match(callsignWithTags,
                                    string.Concat(@"^(?<token>\W)?(?<callsign>[a-z]\w+)(@(?<tag>\w+))?$"),
                                    RegexOptions.Compiled | RegexOptions.IgnoreCase);

            var token    = match.Groups["token"].Value;
            var callsign = match.Groups["callsign"].Value;
            var tag      = match.Groups["tag"].Value;

            if (callsign.Length < MinAliasLength || callsign.Length > MaxAliasLength)
            {
                return(CheckAliasResult.Unavailable);
            }

            if (BadWords.ContainsBadWord(callsign) == true)
            {
                return(CheckAliasResult.ContainedBadWord);
            }

            alias = db.Alias.FirstOrDefault(p => p.Callsign == callsign);

            IEnumerable <Group_Alias_GroupRole> group_roles = null;

            //Check if this callsign is not empty
            if (string.IsNullOrEmpty(callsign))
            {
                return(CheckAliasResult.Unavailable);
            }

            //Validate that alias is a member of group associated with this tag
            if (!string.IsNullOrEmpty(tag))
            {
                if (alias == null)
                {
                    return(CheckAliasResult.Unavailable);
                }

                group_roles = alias.Group_Alias_GroupRoles
                              .Where(p => p.Group.Tag == tag);

                if (group_roles.Count() == 0)
                {
                    return(CheckAliasResult.Unavailable);
                }

                //Override input tag
                tag = group_roles.Select(p => p.Group.Tag).FirstOrDefault();
            }

            //Validate that the alias has the role which allows him to use this tag with this group
            if (!string.IsNullOrEmpty(token))
            {
                if (alias == null)
                {
                    return(CheckAliasResult.Unavailable);
                }

                var tokenChar = token[0];

                //User has selected a @Tag
                if (!string.IsNullOrEmpty(tag))
                {
                    if (group_roles.Any(p => p.GroupRole.Token == tokenChar) == false)
                    {
                        return(CheckAliasResult.Unavailable);
                    }
                }

                //User has not selected a @Tag
                else
                {
                    group_roles = alias.Group_Alias_GroupRoles
                                  .Where(p => p.GroupRole.Token == tokenChar && !p.Group.IsSquad);

                    if (group_roles.Count() == 0)
                    {
                        return(CheckAliasResult.Unavailable);
                    }
                }
            }

            //Check if we can create this alias
            if (alias == null)
            {
                if (login != null)
                {
                    // Check that the user has not used up all their aliases.
                    if (GetAliasCount(db, login) <= 0)
                    {
                        return(CheckAliasResult.AliasLimit);
                    }
                }

                CheckAliasResult result = CheckAliasResult.Available;
                if (Settings.Default.UseAsgsForLegacyCallsignCheck == true)
                {
                    result = ValidateLegacyCallsignUsage(callsign, legacyPassword);
                }

                if (result != CheckAliasResult.Available)
                {
                    return(result);
                }

                if (allowCreate && login != null)
                {
                    alias = new Alias()
                    {
                        Callsign    = callsign,
                        DateCreated = DateTime.Now,
                        IsDefault   = false,
                        IsActive    = true
                    };
                    login.Aliases.Add(alias);
                    db.SubmitChanges();
                }
                else                 //Alias does not exist, and we cannot create it.
                {
                    return(CheckAliasResult.Available);
                }
            }

            //Check if the user has this alias
            else if (login != null)
            {
                int aliasID = alias.Id;

                if (!login.Identity.Logins.SelectMany(p => p.Aliases).Any(p => p.Id == aliasID))
                {
                    return(CheckAliasResult.Unavailable);
                }
            }

            //Override input callsign
            callsignWithTags = string.Format("{0}{1}{2}", token, alias.Callsign,
                                             (!string.IsNullOrEmpty(tag)) ? "@" + tag : string.Empty);

            return(CheckAliasResult.Registered);
        }
Example #14
0
        public async Task ListAutoMod(string extension = "")
        {
            var mutualGuilds = (Context.Message.Author as SocketUser).MutualGuilds.ToArray();

            var guildsEmbed = new EmbedBuilder();

            guildsEmbed.WithTitle("Reply with the number corresponding to the guild you want to check the filter info from");

            for (int i = 0; i < mutualGuilds.Length; i++)
            {
                guildsEmbed.AddField($"[{i + 1}] {mutualGuilds[i].Name}", $"ID: {mutualGuilds[i].Id}");
            }
            await ReplyAsync(embed : guildsEmbed.Build());

            SocketGuild guild;
            Predicate <SocketMessage> filter = message => message.Channel == Context.Channel;

            while (true)
            {
                var result = await Interactivity.NextMessageAsync(filter, timeout : TimeSpan.FromMinutes(1));

                if (result.Value?.Content is null or "cancel")
                {
                    await ReplyAsync("You have timed out or canceled");

                    return;
                }
                try
                {
                    guild = mutualGuilds[ushort.Parse(result.Value.Content) - 1];
                    break;
                }
                catch
                {
                    await ReplyAsync("Invalid number, please reply again with a valid number or `cancel`");
                }
            }

            var      settings = guild.LoadFromFile <FilterSettings>(false);
            BadWords badWords = new BadWords(guild);

            var embed = new EmbedBuilder()
                        .WithGuildAsAuthor(guild);
            string message = "";

            bool useExplicit = false;

            extension = extension?.ToLowerInvariant();
            if (extension == "explicit" || extension == "e")
            {
                if (guild.GetUser(Context.Message.Author.Id).CanWarn())
                {
                    useExplicit = true;
                }
                else
                {
                    await ReplyAsync("Are you sure you want to view the explicit filter? Reply with !confirm if you are sure.");

                    var result = await Interactivity.NextMessageAsync(filter, timeout : TimeSpan.FromMinutes(1));

                    if (result.Value?.Content.Equals("!confirm", StringComparison.InvariantCultureIgnoreCase) ?? false)
                    {
                        useExplicit = true;
                    }
                    else
                    {
                        useExplicit = false;
                    }
                }
            }

            if (settings == null)
            {
                embed.AddField("Filter settings", "Are null", true);
            }
            else
            {
                embed.AddField("Warn for posting invite", !settings.invitesAllowed, true);
                if (settings.allowedLinks == null || settings.allowedLinks.Count == 0)
                {
                    embed.AddField("Allowed links", "Links aren't moderated  ", true);
                }
                else
                {
                    message = settings.allowedLinks.ListItems("\n");
                    if (message?.Length is not null or 0)
                    {
                        embed.AddField("Allowed links", message, true);
                    }
                    if (settings.allowedToLink != null && settings.allowedToLink.Count > 0)
                    {
                        message = guild.Roles.Where(
                            role => (role.Permissions.Administrator && !role.IsManaged) || settings.allowedToLink.Contains(role.Id)).Select(role => role.Name).ToArray().ListItems("\n");
                        if (message?.Length is not null or 0)
                        {
                            embed.AddField("Roles that can post links", message, true);
                        }
                    }
                }
                if (settings.allowedCaps > 0)
                {
                    embed.AddField("Allowed caps", $"{settings.allowedCaps}% in msgs more than 5 long", true);
                }
                else
                {
                    embed.AddField("Allowed caps", "Capitalization is not filtered", true);
                }
                string badUniEmojis = settings.badUEmojis?.ListItems("");
                if (!badUniEmojis.IsNullOrEmpty())
                {
                    embed.AddField("Banned Emojis", badUniEmojis, true);
                }
                if (settings.moderateNames)
                {
                    embed.AddField("Name moderation", "True", true);
                }
                if (settings.maxNewLines != null)
                {
                    embed.AddField("Maximum new lines", $"{settings.maxNewLines.Value} new lines", true);
                }
            }
            if (badWords?.all != null && badWords.all.Count > 0 && (useExplicit || badWords.all.Any(word => !string.IsNullOrWhiteSpace(word.Euphemism))))
            {
                List <string> words = new List <string>();
                foreach (List <BadWord> group in badWords.grouped)
                {
                    BadWord first = group.FirstOrDefault();
                    if (first != null)
                    {
                        string word = "";
                        if (useExplicit)
                        {
                            if (group.Count == 1 || group.All(badWord => badWord.Size == first.Size))
                            {
                                word = $"[{first.Size}x] ";
                            }
                            else
                            {
                                var sizes = group.Select(badword => badword.Size);
                                word = $"[{sizes.Min()}-{sizes.Max()}x] ";
                            }
                            if (first.Euphemism?.Length is not null or 0)
                            {
                                word += $"{first.Euphemism} ";
                            }
                            word += $"({group.Select(badWord => $"{badWord.Word}{(badWord.PartOfWord ? "¤" : "")}").ToArray().ListItems(", ")})";
                        }
                        else if (!first.Euphemism.IsNullOrEmpty())
                        {
                            word = first.Euphemism;
                        }
                        if (first.PartOfWord && (!first.Euphemism.IsNullOrEmpty() && !useExplicit))
                        {
                            word += "¤";
                        }
                        words.Add(word);
                    }
                    else
                    {
                        _ = new LogMessage(LogSeverity.Error, "Filter", "Empty badword list in badwords").Log();
                    }
                }
                message = words.ListItems("\n");
                string listName;
                if (useExplicit)
                {
                    listName = "Bad words with euphemisms";
                }
                else
                {
                    listName = "Bad word euphemisms (not an exhaustive list)";
                }
                embed.AddField(listName, message, false);
            }

            await ReplyAsync("The symbol '¤' next to a word means that you can be warned for a word that contains the bad word", embed : embed.Build());
        }
        protected override void Seed(ApplicationDbContext db)
        {
            var WordFilter = new WordFilter();

            var Event = new EventModel
            {
                EventId     = 1,
                Title       = "Exempelmöte",
                Description = "Vi ska ses och prata.",
                Start       = new DateTime(2019, 1, 10, 14, 0, 0),
                End         = new DateTime(2019, 1, 10, 16, 0, 0),
                Location    = "N2063"
            };

            db.EventModels.Add(Event);

            var store       = new RoleStore <IdentityRole>(db);
            var roleManager = new RoleManager <IdentityRole>(store);
            var adminRole   = new IdentityRole {
                Name = "admin"
            };
            var userRole = new IdentityRole {
                Name = "user"
            };
            var pendingRole = new IdentityRole {
                Name = "pending"
            };

            roleManager.Create(adminRole);
            roleManager.Create(userRole);
            roleManager.Create(pendingRole);

            var hasher      = new PasswordHasher();
            var userStore   = new UserStore <ApplicationUser>(db);
            var userManager = new UserManager <ApplicationUser>(userStore);
            var user        = new ApplicationUser {
                Email = "*****@*****.**", UserName = "******", Firstname = "Admin", Lastname = "Adminsson", Title = "Hövding", PasswordHash = hasher.HashPassword("password")
            };

            userManager.Create(user);
            var user2 = new ApplicationUser {
                Email        = "*****@*****.**",
                UserName     = "******",
                PasswordHash = hasher.HashPassword("password"),
                Title        = "Rektor",
                Firstname    = "Darth",
                Lastname     = "Vader"
            };
            var user3 = new ApplicationUser
            {
                Email        = "*****@*****.**",
                UserName     = "******",
                PasswordHash = hasher.HashPassword("password"),
                Title        = "Lektor",
                Firstname    = "James",
                Lastname     = "RavenLord"
            };

            userManager.Create(user2);
            userManager.Create(user3);
            userManager.AddToRole(user.Id, "admin");
            userManager.AddToRole(user2.Id, "user");
            userManager.AddToRole(user3.Id, "user");
            List <string> words = WordFilter.Words();

            foreach (var i in words)
            {
                if (i == "")
                {
                    continue;
                }

                var badWord = new BadWords
                {
                    Word = i
                };
                db.BadWords.Add(badWord);
            }
            ;

            var research = new PlacardTypeModel
            {
                Type = "Forskning"
            };
            var education = new PlacardTypeModel
            {
                Type = "Utbildning"
            };
            var category = new CategoryModel
            {
                Type = "Övrigt"
            };

            db.Categories.Add(category);
            db.PlacardTypes.Add(research);
            db.PlacardTypes.Add(education);

            db.SaveChanges();
            base.Seed(db);
        }
Example #16
0
 public IActionResult AddBadWords(BadWords words)
 {
     _blogsterDataContext.BadWords.Add(words);
     _blogsterDataContext.SaveChanges();
     return(RedirectToAction("ViewBadWords", "Home"));
 }