whitelisting for education

This commit is contained in:
Kyle Drake 2016-11-14 15:49:09 -06:00
parent c77299cd05
commit 3272b16f47
4 changed files with 37 additions and 23 deletions

View file

@ -18,6 +18,11 @@ end
CREATE_MATCH_REGEX = /^username$|^password$|^email$|^new_tags_string$|^is_education$/
def education_whitelisted?
return true if params[:is_education] == 'true' && $config['education_tag_whitelist'] && !$config['education_tag_whitelist'].select {|t| params[:new_tags_string].match(t)}.empty?
false
end
post '/create_validate_all' do
content_type :json
fields = params.select {|p| p.match CREATE_MATCH_REGEX}
@ -25,6 +30,8 @@ post '/create_validate_all' do
site = Site.new fields
if site.valid?
return [].to_json if education_whitelisted?
return [].to_json if new_recaptcha_valid?
return [['captcha', 'Please complete the captcha.']].to_json
end
@ -74,19 +81,23 @@ post '/create' do
ip: request.ip
)
if session[:captcha_valid] != true
flash[:error] = 'The captcha was not valid, please try again.'
return {result: 'error'}.to_json
end
if education_whitelisted?
@site.email_confirmed = true
else
if session[:captcha_valid] != true
flash[:error] = 'The captcha was not valid, please try again.'
return {result: 'error'}.to_json
end
if !@site.valid? || Site.ip_create_limit?(request.ip)
flash[:error] = 'There was an unknown error, please try again.'
return {result: 'error'}.to_json
end
if !@site.valid? || Site.ip_create_limit?(request.ip)
flash[:error] = 'There was an unknown error, please try again.'
return {result: 'error'}.to_json
end
if Site.disposable_mx_record?(@site.email)
flash[:error] = 'Cannot use a disposable email address.'
return {result: 'error'}.to_json
if Site.disposable_mx_record?(@site.email)
flash[:error] = 'Cannot use a disposable email address.'
return {result: 'error'}.to_json
end
end
@site.email_confirmed = true if self.class.development?
@ -94,12 +105,14 @@ post '/create' do
session[:captcha_valid] = nil
@site.send_email(
subject: "[Neocities] Welcome to Neocities!",
body: Tilt.new('./views/templates/email_welcome.erb', pretty: true).render(self)
)
unless education_whitelisted?
@site.send_email(
subject: "[Neocities] Welcome to Neocities!",
body: Tilt.new('./views/templates/email_welcome.erb', pretty: true).render(self)
)
send_confirmation_email @site
send_confirmation_email @site
end
session[:id] = @site.id
{result: 'ok'}.to_json