mirror of
https://github.com/neocities/neocities.git
synced 2025-04-25 17:52:39 +02:00
special upgrade machine
This commit is contained in:
parent
4271a5e223
commit
d42c4a3c7e
3 changed files with 69 additions and 15 deletions
57
app/plan.rb
57
app/plan.rb
|
@ -12,29 +12,45 @@ get '/plan/?' do
|
||||||
erb :'plan/index'
|
erb :'plan/index'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def is_special_upgrade
|
||||||
|
params[:username] && params[:plan_type] == 'special'
|
||||||
|
end
|
||||||
|
|
||||||
post '/plan/update' do
|
post '/plan/update' do
|
||||||
require_login
|
require_login
|
||||||
|
|
||||||
|
if is_special_upgrade
|
||||||
|
require_admin
|
||||||
|
site = Site[username: params[:username]]
|
||||||
|
|
||||||
|
if site.nil?
|
||||||
|
flash[:error] = 'Cannot find the requested user.'
|
||||||
|
redirect '/admin'
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
site ||= parent_site
|
||||||
|
|
||||||
DB.transaction do
|
DB.transaction do
|
||||||
if parent_site.stripe_subscription_id
|
if site.stripe_subscription_id
|
||||||
customer = Stripe::Customer.retrieve parent_site.stripe_customer_id
|
customer = Stripe::Customer.retrieve site.stripe_customer_id
|
||||||
subscription = customer.subscriptions.retrieve parent_site.stripe_subscription_id
|
subscription = customer.subscriptions.retrieve site.stripe_subscription_id
|
||||||
subscription.plan = params[:plan_type]
|
subscription.plan = params[:plan_type]
|
||||||
subscription.save
|
subscription.save
|
||||||
|
|
||||||
parent_site.update(
|
site.update(
|
||||||
plan_ended: false,
|
plan_ended: false,
|
||||||
plan_type: params[:plan_type]
|
plan_type: params[:plan_type]
|
||||||
)
|
)
|
||||||
else
|
else
|
||||||
customer = Stripe::Customer.create(
|
customer = Stripe::Customer.create(
|
||||||
card: params[:stripe_token],
|
card: params[:stripe_token],
|
||||||
description: "#{parent_site.username} - #{parent_site.id}",
|
description: "#{site.username} - #{site.id}",
|
||||||
email: (current_site.email || parent_site.email),
|
email: site.email,
|
||||||
plan: params[:plan_type]
|
plan: params[:plan_type]
|
||||||
)
|
)
|
||||||
|
|
||||||
parent_site.update(
|
site.update(
|
||||||
stripe_customer_id: customer.id,
|
stripe_customer_id: customer.id,
|
||||||
stripe_subscription_id: customer.subscriptions.first.id,
|
stripe_subscription_id: customer.subscriptions.first.id,
|
||||||
plan_ended: false,
|
plan_ended: false,
|
||||||
|
@ -43,14 +59,25 @@ post '/plan/update' do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if current_site.email || parent_site.email
|
if site.email
|
||||||
EmailWorker.perform_async({
|
if is_special_upgrade
|
||||||
from: 'web@neocities.org',
|
site.send_email(
|
||||||
reply_to: 'contact@neocities.org',
|
subject: "[Neocities] Your site has been upgraded to supporter!",
|
||||||
to: current_site.email || parent_site.email,
|
body: Tilt.new('./views/templates/email/supporter_upgrade.erb', pretty: true).render(self)
|
||||||
subject: "[Neocities] You've become a supporter!",
|
)
|
||||||
body: Tilt.new('./views/templates/email_subscription.erb', pretty: true).render(self, plan_name: Site::PLAN_FEATURES[params[:plan_type].to_sym][:name], plan_space: Site::PLAN_FEATURES[params[:plan_type].to_sym][:space].to_space_pretty)
|
|
||||||
})
|
redirect '/admin'
|
||||||
|
else
|
||||||
|
site.send_email(
|
||||||
|
subject: "[Neocities] You've become a supporter!",
|
||||||
|
body: Tilt.new('./views/templates/email_subscription.erb', pretty: true).render(self, plan_name: Site::PLAN_FEATURES[params[:plan_type].to_sym][:name], plan_space: Site::PLAN_FEATURES[params[:plan_type].to_sym][:space].to_space_pretty)
|
||||||
|
)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
if is_special_upgrade
|
||||||
|
flash[:success] = "#{site.username} has been upgraded to supporter."
|
||||||
|
redirect '/admin'
|
||||||
end
|
end
|
||||||
|
|
||||||
redirect params[:plan_type] == 'free' ? '/plan' : '/plan/thanks'
|
redirect params[:plan_type] == 'free' ? '/plan' : '/plan/thanks'
|
||||||
|
|
|
@ -49,5 +49,17 @@
|
||||||
<p><input class="btn btn-Action" type="submit" value="Ban"></p>
|
<p><input class="btn btn-Action" type="submit" value="Ban"></p>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div class="col col-50">
|
||||||
|
<h2>Upgrade to Supporter</h2>
|
||||||
|
<form action="/plan/update" method="POST">
|
||||||
|
<input type="hidden" name="plan_type" value="special">
|
||||||
|
<%== csrf_token_input_html %>
|
||||||
|
<p>This site will be upgraded to the supporter plan.</p>
|
||||||
|
<p>Site Name:</p>
|
||||||
|
<p><input type="text" name="username" placeholder="edwardsnowden" autocapitalize="off" autocorrect="off"></p>
|
||||||
|
<p><input class="btn btn-Action" type="submit" value="Ban"></p>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
15
views/templates/email/supporter_upgrade.erb
Normal file
15
views/templates/email/supporter_upgrade.erb
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
Hi there!
|
||||||
|
|
||||||
|
A Neocities administrator has upgraded your account to supporter! Someone at Neocities must really like you (or your site). :)
|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
|
Thank you very, very much for supporting Neocities. It means a lot to us. We'll try our hardest to keep improving the site and stick to our core values (NO MARKETING OR ADVERTISING, EVER).
|
||||||
|
|
||||||
|
If you have any questions or comments, or just want to say hi, feel free to contact us at https://neocities.org/contact. You can also reach us on Twitter at @neocitiesweb.
|
||||||
|
|
||||||
|
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
|
Loading…
Add table
Reference in a new issue