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,87 +1,89 @@
<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>
<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> <% 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>
<div id="feature-comparison"> <div id="feature-comparison">
<table> <table>
<thead> <thead>
<tr> <tr>
<th></th> <th></th>
<th>Basic</th> <th>Basic</th>
<th>Gold</th> <th>Gold</th>
<th>Platinum</th> <th>Platinum</th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
<colgroup id="labels"></colgroup> <colgroup id="labels"></colgroup>
<colgroup id="basic"></colgroup> <colgroup id="basic"></colgroup>
<colgroup id="gold"></colgroup> <colgroup id="gold"></colgroup>
<colgroup id="platinum"></colgroup> <colgroup id="platinum"></colgroup>
<tr> <tr>
<td>Cost</td> <td>Cost</td>
<td>Free</td> <td>Free</td>
<td>$20<p class="cost-footnote">One time fee</p></td> <td>$20<p class="cost-footnote">One time fee</p></td>
<td>$40<p class="cost-footnote">One time fee</p></td> <td>$40<p class="cost-footnote">One time fee</p></td>
</tr> </tr>
<tr> <tr>
<td>Tag Limit</td> <td>Tag Limit</td>
<td>2</td> <td>2</td>
<td>6</td> <td>6</td>
<td>12</td> <td>12</td>
</tr> </tr>
<tr> <tr>
<td>Favorite Limit</td> <td>Favorite Limit</td>
<td>10,000</td> <td>10,000</td>
<td>20,000</td> <td>20,000</td>
<td>Unlimited</td> <td>Unlimited</td>
</tr> </tr>
<tr> <tr>
<td>Page Limit</td> <td>Page Limit</td>
<td>1,000</td> <td>1,000</td>
<td>2,000</td> <td>2,000</td>
<td>5,000</td> <td>5,000</td>
</tr> </tr>
<tr> <tr>
<td>Tag Subscriptions</td> <td>Tag Subscriptions</td>
<td>No</td> <td>No</td>
<td>Yes</td> <td>Yes</td>
<td>Yes</td> <td>Yes</td>
</tr> </tr>
<tr> <tr>
<td>See Censored Tags</td> <td>See Censored Tags</td>
<td>No</td> <td>No</td>
<td>Yes</td> <td>Yes</td>
<td>Yes</td> <td>Yes</td>
</tr> </tr>
<tr> <tr>
<td>API Hourly Limit</td> <td>API Hourly Limit</td>
<td>3,000</td> <td>3,000</td>
<td>10,000</td> <td>10,000</td>
<td>20,000</td> <td>20,000</td>
</tr> </tr>
<tr> <tr>
<td>Database Timeout</td> <td>Database Timeout</td>
<td>3 sec</td> <td>3 sec</td>
<td>6 sec</td> <td>6 sec</td>
<td>9 sec</td> <td>9 sec</td>
</tr> </tr>
<tr> <tr>
<td>Variable Posts Per Page</td> <td>Variable Posts Per Page</td>
<td>No</td> <td>No</td>
<td>Yes</td> <td>Yes</td>
<td>Yes</td> <td>Yes</td>
</tr> </tr>
<tr> <tr>
<td>Name Changes</td> <td>Name Changes</td>
<td>No</td> <td>No</td>
<td>Yes</td> <td>Yes</td>
<td>Yes</td> <td>Yes</td>
</tr> </tr>
</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? %>
<li><%= link_to "Upgrade", new_user_upgrade_path %></li> <% if @user.id == CurrentUser.user.id %>
<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? %>