user upgrades: add upgrade code system.
Add a system for upgrading accounts using upgrade codes. Users purchase an upgrade code off-site then redeem it on-site to upgrade their account to Gold. Upgrade codes are randomly pre-generated and are one time use only. Codes have enough randomness that guessing a code is infeasible.
This commit is contained in:
@@ -136,6 +136,8 @@ class ApplicationController < ActionController::Base
|
||||
render_error_page(422, exception, template: "static/tag_limit_error", message: "You cannot search for more than #{CurrentUser.tag_query_limit} tags at a time.")
|
||||
when PostQuery::Error
|
||||
render_error_page(422, exception, message: exception.message)
|
||||
when UpgradeCode::InvalidCodeError, UpgradeCode::RedeemedCodeError, UpgradeCode::AlreadyUpgradedError
|
||||
render_error_page(422, exception, message: exception.message)
|
||||
when RateLimiter::RateLimitError
|
||||
render_error_page(429, exception, message: "Rate limit exceeded. You're doing that too fast")
|
||||
when PageRemovedError
|
||||
|
||||
19
app/controllers/upgrade_codes_controller.rb
Normal file
19
app/controllers/upgrade_codes_controller.rb
Normal file
@@ -0,0 +1,19 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class UpgradeCodesController < ApplicationController
|
||||
respond_to :js, :html, :json, :xml
|
||||
|
||||
def index
|
||||
@upgrade_codes = authorize UpgradeCode.visible(CurrentUser.user).paginated_search(params, count_pages: true)
|
||||
respond_with(@upgrade_codes)
|
||||
end
|
||||
|
||||
def redeem
|
||||
end
|
||||
|
||||
def upgrade
|
||||
@upgrade_code = UpgradeCode.redeem!(code: params.dig(:upgrade_code, :code), redeemer: CurrentUser.user)
|
||||
|
||||
respond_with(@upgrade_code, location: @upgrade_code.user_upgrade)
|
||||
end
|
||||
end
|
||||
@@ -11,6 +11,9 @@ class WebhooksController < ApplicationController
|
||||
when "stripe"
|
||||
PaymentTransaction::Stripe.receive_webhook(request)
|
||||
head 200
|
||||
when "shopify"
|
||||
PaymentTransaction::Shopify.receive_webhook(request)
|
||||
head 200
|
||||
when "discord"
|
||||
json = DiscordSlashCommand.receive_webhook(request)
|
||||
render json: json
|
||||
|
||||
Reference in New Issue
Block a user