mirror of
https://github.com/neocities/neocities.git
synced 2025-08-04 16:51:36 +02:00
Better checking for valid site name
This commit is contained in:
parent
3233494281
commit
aab39212ef
2 changed files with 49 additions and 1 deletions
|
@ -245,6 +245,10 @@ class Site < Sequel::Model
|
|||
filename.gsub(/[^a-zA-Z0-9_\-.]/, '')
|
||||
end
|
||||
|
||||
def self.valid_username?(username)
|
||||
!username.empty? && username.match(/^[a-zA-Z0-9_\-]+$/i)
|
||||
end
|
||||
|
||||
def self.valid_file_type?(uploaded_file)
|
||||
mime_type = Magic.guess_file_mime_type uploaded_file[:tempfile].path
|
||||
|
||||
|
@ -375,6 +379,10 @@ class Site < Sequel::Model
|
|||
errors.add :over_capacity, 'We are currently at capacity, and cannot create your home page. We will fix this shortly. Please come back later and try again, our apologies.'
|
||||
end
|
||||
|
||||
if !self.class.valid_username?(values[:username])
|
||||
errors.add :username, 'A valid user/site name is required.'
|
||||
end
|
||||
|
||||
# TODO regex fails for usernames <= 2 chars, tempfix for now.
|
||||
if new? && values[:username].length > 2 && !values[:username].match(VALID_HOSTNAME)
|
||||
errors.add :username, 'A valid user/site name is required.'
|
||||
|
@ -384,7 +392,6 @@ class Site < Sequel::Model
|
|||
errors.add :username, 'User/site name cannot exceed 32 characters.'
|
||||
end
|
||||
|
||||
|
||||
# Check that email has been provided
|
||||
if new? && values[:email].empty?
|
||||
errors.add :email, 'An email address is required.'
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue