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:
29
app/views/upgrade_codes/index.html.erb
Normal file
29
app/views/upgrade_codes/index.html.erb
Normal file
@@ -0,0 +1,29 @@
|
||||
<div id="c-upgrade-codes">
|
||||
<div id="a-index">
|
||||
<%= search_form_for(upgrade_codes_path) do |f| %>
|
||||
<%= f.input :redeemer_name, label: "Redeemer", input_html: { value: params[:search][:redeemer_name], data: { autocomplete: "user" } } %>
|
||||
<%= f.input :status, collection: UpgradeCode.statuses, include_blank: true, selected: params[:search][:status] %>
|
||||
<%= f.submit "Search" %>
|
||||
<% end %>
|
||||
|
||||
<%= table_for @upgrade_codes, class: "striped autofit" do |t| %>
|
||||
<% t.column :code do |user_upgrade| %>
|
||||
<%= tag.span user_upgrade.code, class: "font-monospace" %>
|
||||
<% end %>
|
||||
|
||||
<% t.column "Redeemer" do |upgrade_code| %>
|
||||
<% if upgrade_code.redeemer.present? %>
|
||||
<%= link_to_user(upgrade_code.redeemer) %>
|
||||
<% end %>
|
||||
<% end %>
|
||||
|
||||
<% t.column :status %>
|
||||
|
||||
<% t.column "Updated" do |upgrade_code| %>
|
||||
<%= time_ago_in_words_tagged(upgrade_code.updated_at) %>
|
||||
<% end %>
|
||||
<% end %>
|
||||
|
||||
<%= numbered_paginator(@upgrade_codes) %>
|
||||
</div>
|
||||
</div>
|
||||
28
app/views/upgrade_codes/redeem.html.erb
Normal file
28
app/views/upgrade_codes/redeem.html.erb
Normal file
@@ -0,0 +1,28 @@
|
||||
<% page_title "Redeem upgrade code" %>
|
||||
|
||||
<%= render "users/secondary_links" %>
|
||||
|
||||
<div id="c-user-upgrades">
|
||||
<div id="a-redeem" class="fixed-width-container mx-auto">
|
||||
<h1 class="text-center mb-4">Redeem upgrade code</h1>
|
||||
|
||||
<% if CurrentUser.user.level <= User::Levels::MEMBER %>
|
||||
<p>Enter your upgrade code below to upgrade your account to Gold.</p>
|
||||
|
||||
<p>After you purchase a Gold account, you will receive an upgrade code. Enter it here to upgrade your account. If you don't have a code,
|
||||
go to the <%= link_to "upgrade page", new_user_upgrade_path %> first to buy one, then come back here to redeem it.</p>
|
||||
|
||||
<% if CurrentUser.user.is_anonymous? %>
|
||||
<p>You must <%= link_to "login", login_path(url: redeem_upgrade_codes_path) %> or
|
||||
<%= link_to "create a new account", new_user_path(url: redeem_upgrade_codes_path) %> first before you can redeem your upgrade code.</p>
|
||||
<% else %>
|
||||
<%= simple_form_for(:upgrade_code, url: upgrade_upgrade_codes_path, remote: true) do |f| %>
|
||||
<%= f.input :code, placeholder: "abcd1234", input_html: { value: params[:code] } %>
|
||||
<%= f.submit "Upgrade account", class: "button-primary" %>
|
||||
<% end %>
|
||||
<% end %>
|
||||
<% else %>
|
||||
<p class="text-center">Your account has already been upgraded.</p>
|
||||
<% end %>
|
||||
</div>
|
||||
</div>
|
||||
1
app/views/upgrade_codes/upgrade.js.erb
Normal file
1
app/views/upgrade_codes/upgrade.js.erb
Normal file
@@ -0,0 +1 @@
|
||||
window.location.assign("<%= j user_upgrade_path(@upgrade_code.user_upgrade) %>");
|
||||
Reference in New Issue
Block a user