Browse Source

- Added reserved username definition file.

- Added method to read file within user helper.
tags/2.0.3
Teknikode 4 years ago
parent
commit
f6a72c5160

+ 132
- 0
Teknik/App_Data/reservedUsernames.txt View File

@@ -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

+ 1
- 1
Teknik/Areas/User/Controllers/UserController.cs View File

@@ -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." });
}

+ 19
- 1
Teknik/Areas/User/Utility/UserHelper.cs View File

@@ -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<string> GetReservedUsernames(Config config)
{
List<string> foundNames = new List<string>();
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<string> reserved = GetReservedUsernames(config);
if (reserved.Exists(u => u.ToLower() == username.ToLower()))
isValid = false;

return isValid;

+ 2
- 2
Teknik/Configuration/UserConfig.cs View File

@@ -10,13 +10,13 @@ namespace Teknik.Configuration
{
public bool RegistrationEnabled { get; set; }
public bool LoginEnabled { get; set; }
public List<string> ReservedUsernames { get; set; }
public string ReservedUsernameDefinitionFile { get; set; }

public UserConfig()
{
RegistrationEnabled = true;
LoginEnabled = true;
ReservedUsernames = new List<string>();
ReservedUsernameDefinitionFile = string.Empty;
}
}
}

+ 1
- 0
Teknik/Teknik.csproj View File

@@ -300,6 +300,7 @@
<Compile Include="App_Start\SubdomainRouteExtension.cs" />
</ItemGroup>
<ItemGroup>
<Content Include="App_Data\reservedUsernames.txt" />
<Content Include="Areas\Blog\Content\Blog.css" />
<Content Include="Areas\Blog\Scripts\Blog.js" />
<Content Include="Areas\Contact\Scripts\Contact.js" />

Loading…
Cancel
Save