Merge branch 'master' of github.com:neocities/neocities

This commit is contained in:
Victoria Wang 2015-08-17 14:47:15 -07:00
commit 49df4a4d21
10 changed files with 143 additions and 7 deletions

View file

@ -216,6 +216,43 @@ task :hash_ips => [:environment] do
end end
end end
desc 'prime_site_files'
task :prime_site_files => [:environment] do
Site.where(is_banned: false).select(:id, :username).all.each do |site|
Dir.glob(File.join(site.files_path, '**/*')).each do |file|
next unless site.username == 'kyledrake'
path = file.gsub(site.base_files_path, '').sub(/^\//, '')
site_file = site.site_files_dataset[path: path]
if site_file.nil?
next if File.directory? file
mtime = File.mtime file
site.add_site_file(
path: path,
size: File.size(file),
sha1_hash: Digest::SHA1.file(file).hexdigest,
updated_at: mtime,
created_at: mtime
)
end
end
end
end
desc 'dedupe_follows'
task :dedupe_follows => [:environment] do
follows = Follow.all
deduped_follows = Follow.all.uniq {|f| "#{f.site_id}_#{f.actioning_site_id}"}
follows.each do |follow|
unless deduped_follows.include?(follow)
puts "deleting dedupe: #{follow.inspect}"
follow.delete
end
end
end
=begin =begin
desc 'Update screenshots' desc 'Update screenshots'
task :update_screenshots => [:environment] do task :update_screenshots => [:environment] do

View file

@ -334,3 +334,29 @@ get '/settings/unsubscribe_email/?' do
end end
erb :'settings/account/unsubscribe' erb :'settings/account/unsubscribe'
end end
post '/settings/update_card' do
require_login
customer = Stripe::Customer.retrieve current_site.stripe_customer_id
old_card_ids = customer.sources.collect {|s| s.id}
begin
customer.sources.create source: params[:stripe_token]
rescue Stripe::InvalidRequestError => e
if e.message.match /cannot use a.+token more than once/
flash[:error] = 'Card is already being used.'
redirect '/settings#billing'
else
raise e
end
end
old_card_ids.each do |card_id|
customer.sources.retrieve(card_id).delete
end
flash[:success] = 'Card information updated.'
redirect '/settings#billing'
end

View file

@ -0,0 +1,9 @@
Sequel.migration do
up {
DB['alter table follows add constraint one_follow_per_site unique (site_id, actioning_site_id)'].first
}
down {
DB['alter table follows drop constraint one_follow_per_site'].first
}
end

View file

@ -591,7 +591,11 @@ class Site < Sequel::Model
# We gotta flush the dirname too if it's an index file. # We gotta flush the dirname too if it's an index file.
if relative_path != '' && relative_path.match(/\/$|index\.html?$/i) if relative_path != '' && relative_path.match(/\/$|index\.html?$/i)
PurgeCacheOrderWorker.perform_async username, relative_path PurgeCacheOrderWorker.perform_async username, relative_path
PurgeCacheOrderWorker.perform_async username, Pathname(relative_path).dirname.to_s
purge_file_path = Pathname(relative_path).dirname.to_s
PurgeCacheOrderWorker.perform_async username, '/?surf=1' if purge_file_path == '/'
PurgeCacheOrderWorker.perform_async username, purge_file_path
else else
PurgeCacheOrderWorker.perform_async username, relative_path PurgeCacheOrderWorker.perform_async username, relative_path
end end
@ -976,6 +980,10 @@ class Site < Sequel::Model
PLAN_FEATURES[plan_type.to_sym][:name] PLAN_FEATURES[plan_type.to_sym][:name]
end end
def stripe_paying_supporter?
stripe_customer_id && !plan_ended && values[:plan_type].match(/free|special/).nil?
end
def unconverted_legacy_supporter? def unconverted_legacy_supporter?
stripe_customer_id && !plan_ended && values[:plan_type].nil? && stripe_subscription_id.nil? stripe_customer_id && !plan_ended && values[:plan_type].nil? && stripe_subscription_id.nil?
end end

View file

@ -107,13 +107,17 @@ describe 'site_files' do
@site.title.must_equal 'Hello?' @site.title.must_equal 'Hello?'
# Purge cache needs to flush / and index.html for either scenario. # Purge cache needs to flush / and index.html for either scenario.
PurgeCacheOrderWorker.jobs.length.must_equal 2 PurgeCacheOrderWorker.jobs.length.must_equal 3
first_purge = PurgeCacheOrderWorker.jobs.first first_purge = PurgeCacheOrderWorker.jobs.first
surf_purge = PurgeCacheOrderWorker.jobs[1]
dirname_purge = PurgeCacheOrderWorker.jobs.last dirname_purge = PurgeCacheOrderWorker.jobs.last
username, pathname = first_purge['args'] username, pathname = first_purge['args']
username.must_equal @site.username username.must_equal @site.username
pathname.must_equal '/index.html' pathname.must_equal '/index.html'
surf_purge['args'].last.must_equal '/?surf=1'
username, pathame = nil username, pathame = nil
username, pathname = dirname_purge['args'] username, pathname = dirname_purge['args']
username.must_equal @site.username username.must_equal @site.username

View file

@ -6,6 +6,7 @@
<div class="content" style="background: white"> <div class="content" style="background: white">
<form method="POST" action="/admin/report"> <form method="POST" action="/admin/report">
<%== csrf_token_input_html %>
<table class="table"> <table class="table">
<tr> <tr>
<th>Site</th> <th>Site</th>

View file

@ -13,7 +13,7 @@
var signupform = $(event.target) var signupform = $(event.target)
<% if current_site && parent_site.stripe_subscription_id %> <% if current_site && parent_site.stripe_subscription_id && !request.path.match(/\/settings/) %>
return true return true
<% end %> <% end %>

View file

@ -27,6 +27,9 @@
<li><a href="#sites" data-toggle="tab">Sites</a></li> <li><a href="#sites" data-toggle="tab">Sites</a></li>
<li><a href="#password" data-toggle="tab">Password</a></li> <li><a href="#password" data-toggle="tab">Password</a></li>
<li><a href="#email" data-toggle="tab">Email</a></li> <li><a href="#email" data-toggle="tab">Email</a></li>
<% if current_site.stripe_paying_supporter? %>
<li><a href="#billing" data-toggle="tab">Billing</a></li>
<% end %>
</ul> </ul>
<div class="tab-content"> <div class="tab-content">
<div class="tab-pane active" id="plan"> <div class="tab-pane active" id="plan">
@ -41,6 +44,11 @@
<div class="tab-pane" id="email"> <div class="tab-pane" id="email">
<%== erb :'settings/account/email' %> <%== erb :'settings/account/email' %>
</div> </div>
<% if current_site.stripe_paying_supporter? %>
<div class="tab-pane" id="billing">
<%== erb :'settings/account/billing' %>
</div>
<% end %>
</div> </div>
</div> </div>
</section> </section>

View file

@ -0,0 +1,45 @@
<h2>Change Credit Card</h2>
<p>This allows you to change your currently stored credit card. You will be charged at the regular monthly cycle.</p>
<div>
<div id="plan_error" class="alert alert-block alert-error" style="display:none"></div>
<form id="upgradeForm" method="POST" action="/settings/update_card">
<input type="hidden" value="<%= csrf_token %>" name="csrf_token">
<input type="hidden" value="supporter" name="plan_type">
<input id="stripe_token" name="stripe_token" type="hidden" value="<%= params[:stripe_token] %>">
<div class="credit-card-input no-js" id="skeuocard" style="margin-left: auto; margin-right: auto; margin-bottom: 20px">
<p class="no-support-warning"></p>
<label for="cc_type">Card Type</label>
<select name="cc_type">
<option value="">...</option>
<option value="visa">Visa</option>
<option value="discover">Discover</option>
<option value="mastercard">MasterCard</option>
<option value="maestro">Maestro</option>
<option value="jcb">JCB</option>
<option value="unionpay">China UnionPay</option>
<option value="amex">American Express</option>
<option value="dinersclubintl">Diners Club</option>
</select>
<label for="cc_number">Card Number</label>
<input type="text" name="cc_number" id="cc_number" placeholder="XXXX XXXX XXXX XXXX" maxlength="19" size="19">
<label for="cc_exp_month">Expiration Month</label>
<input type="text" name="cc_exp_month" id="cc_exp_month" placeholder="00">
<label for="cc_exp_year">Expiration Year</label>
<input type="text" name="cc_exp_year" id="cc_exp_year" placeholder="00">
<label for="cc_name">Cardholder's Name</label>
<input type="text" name="cc_name" id="cc_name" placeholder="John Doe">
<label for="cc_cvc">Card Validation Code</label>
<input type="text" name="cc_cvc" id="cc_cvc" placeholder="123" maxlength="3" size="3">
</div>
</form>
<a href="/" class="btn-Action" onclick="$('#upgradeForm').submit(); return false">Update Card</a>
</div>
<%== erb :'plan/_signupcode', layout: false %>
<script>
card = new Skeuocard($('#skeuocard'))
</script>

View file

@ -1,8 +1,6 @@
Hi there! Hi there!
A Neocities administrator has upgraded your account to supporter! Someone at Neocities must really like you (or your site). :) A Neocities administrator has upgraded your account to supporter! You can see some of the new features you can use by visiting our supporter page at https://neocities.org/plan
We won't charge you for the upgrade, so no worries on that. You can see some of the new features you can use by visiting our supporter page at https://neocities.org/plan
We're looking forward to seeing the awesome things you will do with it. We're looking forward to seeing the awesome things you will do with it.
@ -12,4 +10,4 @@ If you have any questions or comments, or just want to say hi, feel free to cont
From Penelope (the Neocities' cat/sysadmin), everyone that's helped work on Neocities, and on behalf of all our sites, our very best wishes for you (and your awesome web site). From Penelope (the Neocities' cat/sysadmin), everyone that's helped work on Neocities, and on behalf of all our sites, our very best wishes for you (and your awesome web site).
- The Neocities Team - The Neocities Team