1
0
mirror of https://git.teknik.io/Teknikode/Teknik.git synced 2023-08-02 14:16:22 +02:00

- Added reserved username definition file.

- Added method to read file within user helper.
This commit is contained in:
Uncled1023 2016-05-16 21:56:17 -07:00
parent 89683efcad
commit f6a72c5160
5 changed files with 155 additions and 4 deletions

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

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

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;

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;
}
}
}

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" />