allow gift upgrades for accounts

This commit is contained in:
r888888888
2014-12-10 10:21:10 -08:00
parent a6c389a281
commit cb1be62577
4 changed files with 111 additions and 88 deletions

View File

@@ -1,17 +1,17 @@
class UserUpgradesController < ApplicationController class UserUpgradesController < ApplicationController
before_filter :member_only, :only => [:new, :show] before_filter :member_only, :only => [:new, :show]
helper_method :encrypt_custom, :coinbase helper_method :encrypt_custom, :coinbase, :user
force_ssl :if => :ssl_enabled? force_ssl :if => :ssl_enabled?
skip_before_action :verify_authenticity_token, only: [:create] skip_before_action :verify_authenticity_token, only: [:create]
def create def create
if params[:order][:status] == "completed" if params[:order][:status] == "completed"
user_id, level = decrypt_custom user_id, level = decrypt_custom
user = User.find(user_id) member = User.find(user_id)
if user.level < User::Levels::PLATINUM && level >= User::Levels::GOLD && level <= User::Levels::PLATINUM if member.level < User::Levels::PLATINUM && level >= User::Levels::GOLD && level <= User::Levels::PLATINUM
CurrentUser.scoped(User.admins.first, "127.0.0.1") do CurrentUser.scoped(User.admins.first, "127.0.0.1") do
user.promote_to!(level, :skip_feedback => true) member.promote_to!(level, :skip_feedback => true)
end end
end end
end end
@@ -25,17 +25,28 @@ class UserUpgradesController < ApplicationController
end end
end end
def gift
end
def show def show
end end
def encrypt_custom(level) def encrypt_custom(level)
crypt.encrypt_and_sign("#{CurrentUser.user.id},#{level}") crypt.encrypt_and_sign("#{user.id},#{level}")
end end
def coinbase def coinbase
@coinbase_api ||= Coinbase::Client.new(Danbooru.config.coinbase_api_key, Danbooru.config.coinbase_api_secret) @coinbase_api ||= Coinbase::Client.new(Danbooru.config.coinbase_api_key, Danbooru.config.coinbase_api_secret)
end end
def user
if params[:user_id]
User.find(params[:user_id])
else
CurrentUser.user
end
end
private private
def decrypt_custom def decrypt_custom

View File

@@ -1,8 +1,14 @@
<p>You can pay with Bitcoin. You will pay either $20 USD or $40 USD equivalent in Bitcoin. Danbooru uses <a href="https://www.coinbase.com">Coinbase</a> as a payment intermediary so none of your personal information will be stored on the site.</p> <p>You can pay with Bitcoin. You will pay either $20 USD or $40 USD equivalent in Bitcoin. Danbooru uses <a href="https://www.coinbase.com">Coinbase</a> as a payment intermediary so none of your personal information will be stored on the site.</p>
<% if CurrentUser.user.level < User::Levels::GOLD %> <% if params[:user_id] %>
<p>You are gifting this account upgrade to <%= link_to user.pretty_name, user_path(params[:user_id]) %>.</p>
<% else %>
<p>You can also upgrade someone else's account for the same price. The easiest way is to go to their profile page and look for a "Gift Upgrade" link.</p>
<% end %>
<% if user.level < User::Levels::GOLD %>
<%= raw coinbase.create_button("Upgrade to Gold", 20.to_money("USD"), "Upgrade your Basic Account to a Gold Account", encrypt_custom(User::Levels::GOLD), :button => {:style => "custom_small", :text => "Upgrade to Gold", :callback_url => user_upgrade_path(:only_path => false, :host => Danbooru.config.hostname, :protocol => "https")}).embed_html %> <%= raw coinbase.create_button("Upgrade to Gold", 20.to_money("USD"), "Upgrade your Basic Account to a Gold Account", encrypt_custom(User::Levels::GOLD), :button => {:style => "custom_small", :text => "Upgrade to Gold", :callback_url => user_upgrade_path(:only_path => false, :host => Danbooru.config.hostname, :protocol => "https")}).embed_html %>
<%= raw coinbase.create_button("Upgrade to Platinum", 40.to_money("USD"), "Upgrade your Basic Account to a Platinum Account", encrypt_custom(User::Levels::PLATINUM), :button => {:style => "custom_small", :text => "Upgrade to Platinum", :callback_url => user_upgrade_path(:only_path => false, :host => Danbooru.config.hostname, :protocol => "https")}).embed_html %> <%= raw coinbase.create_button("Upgrade to Platinum", 40.to_money("USD"), "Upgrade your Basic Account to a Platinum Account", encrypt_custom(User::Levels::PLATINUM), :button => {:style => "custom_small", :text => "Upgrade to Platinum", :callback_url => user_upgrade_path(:only_path => false, :host => Danbooru.config.hostname, :protocol => "https")}).embed_html %>
<% elsif CurrentUser.level < User::Levels::PLATINUM %> <% elsif user.level < User::Levels::PLATINUM %>
<%= raw coinbase.create_button("Upgrade to Platinum", 20.to_money("USD"), "Upgrade your Gold Account to a Platinum Account", encrypt_custom(User::Levels::PLATINUM), :button => {:style => "custom_small", :text => "Upgrade to Platinum", :callback_url => user_upgrade_path(:only_path => false, :host => Danbooru.config.hostname, :protocol => "https")}).embed_html %> <%= raw coinbase.create_button("Upgrade to Platinum", 20.to_money("USD"), "Upgrade your Gold Account to a Platinum Account", encrypt_custom(User::Levels::PLATINUM), :button => {:style => "custom_small", :text => "Upgrade to Platinum", :callback_url => user_upgrade_path(:only_path => false, :host => Danbooru.config.hostname, :protocol => "https")}).embed_html %>
<% end %> <% end %>

View File

@@ -1,7 +1,8 @@
<div id="c-users"> <div id="c-users">
<div id="a-upgrade-information"> <div id="a-upgrade-information">
<h1>Upgrade Your Account</h1> <h1>Upgrade Account</h1>
<% unless params[:user_id] %>
<p class="copy">Annoyed by ads? Want more searching power? Upgrade your account and become a power user of the best database of anime artwork on the internet.</p> <p class="copy">Annoyed by ads? Want more searching power? Upgrade your account and become a power user of the best database of anime artwork on the internet.</p>
<div id="feature-comparison"> <div id="feature-comparison">
@@ -82,6 +83,7 @@
</tbody> </tbody>
</table> </table>
</div> </div>
<% end %>
<% if Danbooru.config.coinbase_api_key %> <% if Danbooru.config.coinbase_api_key %>
<%= render "coinbase_payment" %> <%= render "coinbase_payment" %>

View File

@@ -22,7 +22,11 @@
<% end %> <% end %>
<% if CurrentUser.is_member? || CurrentUser.is_gold? %> <% if CurrentUser.is_member? || CurrentUser.is_gold? %>
<% if @user.id == CurrentUser.user.id %>
<li><%= link_to "Upgrade", new_user_upgrade_path %></li> <li><%= link_to "Upgrade", new_user_upgrade_path %></li>
<% else %>
<li><%= link_to "Gift Upgrade", new_user_upgrade_path(:user_id => @user.id) %></li>
<% end %>
<% end %> <% end %>
<% if CurrentUser.is_moderator? %> <% if CurrentUser.is_moderator? %>