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,6 +81,9 @@ post '/create' do
ip: request.ip
)
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
@ -88,18 +98,21 @@ post '/create' do
flash[:error] = 'Cannot use a disposable email address.'
return {result: 'error'}.to_json
end
end
@site.email_confirmed = true if self.class.development?
@site.save
session[:captcha_valid] = nil
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
end
session[:id] = @site.id
{result: 'ok'}.to_json

View file

@ -30,7 +30,7 @@ describe 'signup' do
it 'succeeds with valid data' do
fill_in_valid
click_button 'Create My Site'
page.must_have_content /Welcome to your new site/
page.must_have_content /Let's Get Started/
index_file_path = File.join Site::SITE_FILES_ROOT, @site[:username], 'index.html'
File.exist?(index_file_path).must_equal true

View file

@ -7,7 +7,7 @@
if(errors.length == 0) {
$.post('/create', $('#createSiteForm').serialize(), function(res) {
if($('input[name=is_education]').val() == 'true') {
window.location.href = '/dashboard'
window.location.href = '/tutorial'
} else {
window.location.href = '/welcome'
}

View file

@ -120,13 +120,10 @@
</div>
<div class="col col-50" style="padding-left:0;">
<label>
Confirm you are human
</label>
<div id="captcha-input" class="g-recaptcha"
data-sitekey="<%= $config['recaptcha_public_key'] %>"
data-theme="dark" data-placement="left" data-trigger="manual">
</div>
</div>
<div class="col col-50">
@ -148,6 +145,8 @@
</header>
<!--
<main class="content-Base">
<div class="section instructor-quotes">
@ -193,6 +192,8 @@
</div>
</main>
-->
<footer class="footer-Base" role="contentinfo">
<div class="footer-Intro">
<div class="footer-Content">