brush up email requirements

This commit is contained in:
Kyle Drake 2014-08-02 15:22:54 -07:00
parent 933fb9fcfd
commit d3fc35989d
10 changed files with 149 additions and 10 deletions

View file

@ -358,6 +358,10 @@ class Site < Sequel::Model
super
end
def before_create
self.email_confirmation_token = SecureRandom.hex 3
end
# def after_destroy
# FileUtils.rm_rf file_path
# super
@ -379,6 +383,17 @@ 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.'
end
# Check for existing email
if new? && self.class.select(:id).filter(email: values[:email]).first
errors.add :email, 'This email address already exists on Neocities, please use your existing account.'
end
# Check for existing user
user = self.class.select(:id, :username).filter(username: values[:username]).first
@ -522,7 +537,7 @@ class Site < Sequel::Model
end
def host
domain ? domain : "#{username}.neocities.org"
!domain.empty? ? domain : "#{username}.neocities.org"
end
def title