Fix validating education class tag whitelist

This commit is contained in:
Andrew Shu 2023-04-30 11:25:29 -07:00
parent 7887553666
commit beafd2daf8

View file

@ -1,7 +1,12 @@
CREATE_MATCH_REGEX = /^username$|^password$|^email$|^new_tags_string$|^is_education$/ CREATE_MATCH_REGEX = /^username$|^password$|^email$|^new_tags_string$|^is_education$/
def education_whitelist_required?
return true if params[:is_education] == 'true' && $config['education_tag_whitelist']
false
end
def education_whitelisted? 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? return true if education_whitelist_required? && !$config['education_tag_whitelist'].select {|t| params[:new_tags_string].match(t)}.empty?
false false
end end
@ -63,8 +68,13 @@ post '/create' do
ga_adgroupid: session[:ga_adgroupid] ga_adgroupid: session[:ga_adgroupid]
) )
if education_whitelist_required?
if education_whitelisted? if education_whitelisted?
@site.email_confirmed = true @site.email_confirmed = true
else
flash[:error] = 'The class tag is invalid.'
return {result: 'error'}.to_json
end
else else
if !hcaptcha_valid? if !hcaptcha_valid?
flash[:error] = 'The captcha was not valid, please try again.' flash[:error] = 'The captcha was not valid, please try again.'