Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
adnjoo committed Oct 23, 2024
1 parent 2d017f5 commit cf2ea1a
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 2 deletions.
9 changes: 9 additions & 0 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,15 @@ class ApplicationController < ActionController::Base
# Set the Stripe API key before any controller action is called.
before_action :set_stripe_key

# Allow related fields to be set during e.g. sign up, account update.
before_action :configure_permitted_parameters, if: :devise_controller?

protected

def configure_permitted_parameters
devise_parameter_sanitizer.permit(:account_update, keys: [ :username, :public ])
end

private
def set_stripe_key
Stripe.api_key = Rails.application.credentials.dig(:stripe, :secret_key)
Expand Down
2 changes: 2 additions & 0 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ class User < ApplicationRecord

has_many :subscriptions, dependent: :destroy

validates :username, presence: true, uniqueness: { case_sensitive: false }, allow_nil: true

def subscribed?
subscriptions.where(status: "active").any?
end
Expand Down
17 changes: 16 additions & 1 deletion app/views/devise/registrations/edit.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,21 @@
<div class="text-black">Currently waiting confirmation for: <%= resource.unconfirmed_email %></div>
<% end %>

<!-- Username Field -->
<div class="flex flex-col">
<%= f.label :username, class: "text-lg font-semibold uppercase tracking-wide text-black" %>
<%= f.text_field :username, class: "border-2 border-black px-4 py-2 bg-white text-black focus:outline-none focus:border-gray-700", placeholder: "Enter username" %>
</div>

<!-- Public Field -->
<div class="flex flex-col">
<%= f.label :public, class: "text-lg font-semibold uppercase tracking-wide text-black" %>
<div class="flex items-center">
<%= f.check_box :public, class: "mr-2" %>
<label for="public" class="text-sm text-black">Public Profile</label>
</div>
</div>

<div class="flex flex-col">
<%= f.label :password, class: "text-lg font-semibold uppercase tracking-wide text-black" %>
<i class="text-sm text-gray-700">(leave blank if you don't want to change it)</i>
Expand Down Expand Up @@ -47,7 +62,7 @@
<h3 class="text-2xl font-bold uppercase tracking-wide text-black mt-10">Cancel my account</h3>
<div class="mt-4 text-black">
Unhappy?
Email us at <%= link_to DEFAULT_TO_EMAIL, "mailto:#{DEFAULT_TO_EMAIL}?subject=Cancel Account}", class: "text-black underline" %> to cancel your account.
Email us at <%= link_to DEFAULT_TO_EMAIL, "mailto:#{DEFAULT_TO_EMAIL}?subject=Cancel Account", class: "text-black underline" %> to cancel your account.
</div>

<%= link_to "Back", :back, class: "text-black underline hover:text-gray-800 mt-6 inline-block" %>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
class AddUsernameAndPublicToUsers < ActiveRecord::Migration[7.2]
def change
add_column :users, :username, :string
# Allow username to be null
add_column :users, :username, :string, null: true
add_column :users, :public, :boolean, default: false

# Add a unique index to the username column
# Ensure the unique index allows multiple null values
add_index :users, :username, unique: true, where: "username IS NOT NULL"
end
end
1 change: 1 addition & 0 deletions db/schema.rb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit cf2ea1a

Please sign in to comment.