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:
evazion
2022-05-25 17:28:39 -05:00
parent 7786fbaca6
commit 173e43b192
22 changed files with 461 additions and 22 deletions

View 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