mirror of
https://github.com/neocities/neocities.git
synced 2025-04-24 17:22:35 +02:00
fix for username length spam
This commit is contained in:
parent
4d397df015
commit
0212167b3e
1 changed files with 10 additions and 1 deletions
|
@ -137,8 +137,9 @@ class Site < Sequel::Model
|
|||
DISPOSABLE_EMAIL_BLACKLIST_PATH = File.join(DIR_ROOT, 'files', 'disposable_email_blacklist.conf')
|
||||
|
||||
BLOCK_JERK_THRESHOLD = 2
|
||||
|
||||
MAXIMUM_TAGS = 5
|
||||
MAX_USERNAME_LENGTH = 25.freeze
|
||||
MAX_USERNAME_LENGTH_CUTOFF = Time.parse('May 22, 2017')
|
||||
|
||||
def self.newsletter_sites
|
||||
Site.select(:email).
|
||||
|
@ -565,6 +566,10 @@ class Site < Sequel::Model
|
|||
!username.empty? && username.match(/^[a-zA-Z0-9_\-]+$/i)
|
||||
end
|
||||
|
||||
def username_too_long?
|
||||
(new? || (created_at && created_at > MAX_USERNAME_LENGTH_CUTOFF)) && values[:username].length > MAX_USERNAME_LENGTH
|
||||
end
|
||||
|
||||
def self.disposable_email_domains
|
||||
File.readlines(DISPOSABLE_EMAIL_BLACKLIST_PATH).collect {|d| d.strip}
|
||||
end
|
||||
|
@ -890,6 +895,10 @@ class Site < Sequel::Model
|
|||
errors.add :username, 'Usernames can only contain letters, numbers, underscores and hyphens.'
|
||||
end
|
||||
|
||||
if username_too_long?
|
||||
errors.add :username, "Username length cannot be greater than #{MAX_USERNAME_LENGTH} characters."
|
||||
end
|
||||
|
||||
if new? && !values[:username].nil? && !values[:username].empty?
|
||||
# TODO regex fails for usernames <= 2 chars, tempfix for now.
|
||||
if new? && values[:username].nil? || (values[:username].length > 2 && !values[:username].match(VALID_HOSTNAME))
|
||||
|
|
Loading…
Add table
Reference in a new issue