From f6a72c5160922922fd413081cafaeee9b4abbb1f Mon Sep 17 00:00:00 2001 From: Uncled1023 Date: Mon, 16 May 2016 21:56:17 -0700 Subject: [PATCH] - Added reserved username definition file. - Added method to read file within user helper. --- Teknik/App_Data/reservedUsernames.txt | 132 ++++++++++++++++++ .../Areas/User/Controllers/UserController.cs | 2 +- Teknik/Areas/User/Utility/UserHelper.cs | 20 ++- Teknik/Configuration/UserConfig.cs | 4 +- Teknik/Teknik.csproj | 1 + 5 files changed, 155 insertions(+), 4 deletions(-) create mode 100644 Teknik/App_Data/reservedUsernames.txt diff --git a/Teknik/App_Data/reservedUsernames.txt b/Teknik/App_Data/reservedUsernames.txt new file mode 100644 index 0000000..93b8697 --- /dev/null +++ b/Teknik/App_Data/reservedUsernames.txt @@ -0,0 +1,132 @@ +about +abuse +account +add +admin +administration +api +app +apps +archive +archives +auth +better +billing +blog +cache +cdn +changelog +codereview +compare +config +connect +contact +create +delete +dev +developer +direct_messages +downloads +edit +email +enterprise +faq +favorites +feed +feeds +follow +followers +following +ftp +gist +help +home +host +hosting +hostmaster +imap +info +invitations +invite +jobs +list +list-request +lists +local +localdomain +localhost +log +login +logout +logs +mail +mailman +map +maps +marketing +master +messages +mine +mod +moderator +news +next +no-reply +noc +noreply +oauth +oauth_clients +openid +organizations +owner +plans +pop +popular +postman +postmaster +privacy +production +projects +register +remove +replies +root +rss +rsync +sales +save +search +security +sessions +settings +sftp +shop +signup +sitemap +ssh +ssl +staging +status +stories +styleguide +subscribe +support +team +teknik +terms +tour +translations +trends +unfollow +unsubscribe +url +usenet +user +uucp +webmaster +widget +widgets +wiki +www +xfn +xmpp \ No newline at end of file diff --git a/Teknik/Areas/User/Controllers/UserController.cs b/Teknik/Areas/User/Controllers/UserController.cs index 3fdb516..cb4f427 100644 --- a/Teknik/Areas/User/Controllers/UserController.cs +++ b/Teknik/Areas/User/Controllers/UserController.cs @@ -218,7 +218,7 @@ namespace Teknik.Areas.Users.Controllers { if (Config.UserConfig.RegistrationEnabled) { - if (UserHelper.UsernameAvailable(db, Config, model.Username)) + if (!UserHelper.UsernameAvailable(db, Config, model.Username)) { return Json(new { error = "That username is not available." }); } diff --git a/Teknik/Areas/User/Utility/UserHelper.cs b/Teknik/Areas/User/Utility/UserHelper.cs index 2a8ec41..f66eba7 100644 --- a/Teknik/Areas/User/Utility/UserHelper.cs +++ b/Teknik/Areas/User/Utility/UserHelper.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Data.Entity; +using System.IO; using System.Linq; using System.Net; using System.Runtime.InteropServices; @@ -19,6 +20,21 @@ namespace Teknik.Areas.Users.Utility { public static class UserHelper { + public static List GetReservedUsernames(Config config) + { + List foundNames = new List(); + if (config != null) + { + string path = config.UserConfig.ReservedUsernameDefinitionFile; + if (File.Exists(path)) + { + string[] names = File.ReadAllLines(path); + foundNames = names.ToList(); + } + } + return foundNames; + } + #region User Management public static User GetUser(TeknikEntities db, string username) { @@ -48,7 +64,9 @@ namespace Teknik.Areas.Users.Utility { bool isValid = true; - if (config.UserConfig.ReservedUsernames.Exists(u => u.ToLower() == username.ToLower())) + // Load reserved usernames + List reserved = GetReservedUsernames(config); + if (reserved.Exists(u => u.ToLower() == username.ToLower())) isValid = false; return isValid; diff --git a/Teknik/Configuration/UserConfig.cs b/Teknik/Configuration/UserConfig.cs index 7989876..08d3472 100644 --- a/Teknik/Configuration/UserConfig.cs +++ b/Teknik/Configuration/UserConfig.cs @@ -10,13 +10,13 @@ namespace Teknik.Configuration { public bool RegistrationEnabled { get; set; } public bool LoginEnabled { get; set; } - public List ReservedUsernames { get; set; } + public string ReservedUsernameDefinitionFile { get; set; } public UserConfig() { RegistrationEnabled = true; LoginEnabled = true; - ReservedUsernames = new List(); + ReservedUsernameDefinitionFile = string.Empty; } } } diff --git a/Teknik/Teknik.csproj b/Teknik/Teknik.csproj index 4bfdaf6..8ef5303 100644 --- a/Teknik/Teknik.csproj +++ b/Teknik/Teknik.csproj @@ -300,6 +300,7 @@ +