Refactor user settings
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
Use resources instead of custom controllers, following the Rails way and making things much cleaner in the process.
This commit is contained in:
parent
6f2160b479
commit
7f77ad5528
@ -1,13 +0,0 @@
|
||||
class Settings::AccountController < SettingsController
|
||||
|
||||
def index
|
||||
end
|
||||
|
||||
def reset_password
|
||||
current_user.send_reset_password_instructions
|
||||
sign_out current_user
|
||||
msg = "We have sent you an email with a link to reset your password."
|
||||
redirect_to check_your_email_path, notice: msg
|
||||
end
|
||||
|
||||
end
|
@ -1,11 +0,0 @@
|
||||
class Settings::ProfileController < SettingsController
|
||||
|
||||
def index
|
||||
@user = current_user
|
||||
end
|
||||
|
||||
def update
|
||||
|
||||
end
|
||||
|
||||
end
|
@ -1,13 +1,37 @@
|
||||
class SettingsController < ApplicationController
|
||||
before_action :require_user_signed_in
|
||||
before_action :set_current_section
|
||||
before_action :authenticate_user!
|
||||
before_action :set_main_nav_section
|
||||
before_action :set_settings_section, only: ['show', 'update']
|
||||
|
||||
def index
|
||||
redirect_to setting_path(:profile)
|
||||
end
|
||||
|
||||
def show
|
||||
@user = current_user
|
||||
end
|
||||
|
||||
def update
|
||||
end
|
||||
|
||||
def reset_password
|
||||
current_user.send_reset_password_instructions
|
||||
sign_out current_user
|
||||
msg = "We have sent you an email with a link to reset your password."
|
||||
redirect_to check_your_email_path, notice: msg
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def set_current_section
|
||||
def set_main_nav_section
|
||||
@current_section = :settings
|
||||
end
|
||||
|
||||
def set_settings_section
|
||||
@settings_section = params[:section]
|
||||
|
||||
unless [:profile, :account].include?(@settings_section.to_sym)
|
||||
redirect_to setting_path(:profile)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
19
app/views/settings/_account.html.erb
Normal file
19
app/views/settings/_account.html.erb
Normal file
@ -0,0 +1,19 @@
|
||||
<section>
|
||||
<h3>E-Mail</h3>
|
||||
<p class="mb-2">
|
||||
<%= label :email, 'Address', class: 'font-bold' %>
|
||||
</p>
|
||||
<p class="flex gap-1 mb-2 sm:w-3/5">
|
||||
<input type="text" id="email" class="grow"
|
||||
value=<%= current_user.email %> disabled="disabled" />
|
||||
</p>
|
||||
</section>
|
||||
<section>
|
||||
<h3>Password</h3>
|
||||
<p class="mb-8">Use the following button to request an email with a password reset link:</p>
|
||||
<%= form_with(url: reset_password_settings_path, method: :post) do %>
|
||||
<p>
|
||||
<%= submit_tag("Send me a password reset link", class: 'btn-md btn-gray w-full sm:w-auto') %>
|
||||
</p>
|
||||
<% end %>
|
||||
</section>
|
30
app/views/settings/_profile.html.erb
Normal file
30
app/views/settings/_profile.html.erb
Normal file
@ -0,0 +1,30 @@
|
||||
<section>
|
||||
<h3>Profile</h3>
|
||||
<p class="mb-2">
|
||||
<%= label :user_address, 'User address', class: 'font-bold' %>
|
||||
</p>
|
||||
<p data-controller="clipboard" class="flex gap-1 mb-2 sm:w-3/5">
|
||||
<input type="text" id="user_address" class="grow"
|
||||
value=<%= @user.address %> disabled="disabled"
|
||||
data-clipboard-target="source" />
|
||||
<button id="copy-user-address" class="btn-md btn-icon btn-blue shrink-0"
|
||||
data-clipboard-target="trigger" data-action="clipboard#copy"
|
||||
title="Copy to clipboard">
|
||||
<span class="content-initial">
|
||||
<%= render partial: "icons/copy", locals: { custom_class: "text-white h-4 w-4 inline" } %>
|
||||
</span>
|
||||
<span class="content-active hidden">
|
||||
<%= render partial: "icons/check", locals: { custom_class: "text-white h-4 w-4 inline" } %>
|
||||
</span>
|
||||
</button>
|
||||
</p>
|
||||
<p class="text-sm text-gray-500">
|
||||
Your user address for Chat and Lightning Network.
|
||||
</p>
|
||||
|
||||
<%# <%= form_for(@user, as: "profile", url: settings_profile_path) do |f| %>
|
||||
<%# <p class="mt-8">
|
||||
<%# <%= f.submit "Save changes", class: 'btn-md btn-blue w-full sm:w-auto' %>
|
||||
<%# </p>
|
||||
<%# <% end %>
|
||||
</section>
|
@ -1,23 +0,0 @@
|
||||
<%= render HeaderComponent.new(title: "Settings") %>
|
||||
|
||||
<%= render MainWithSidenavComponent.new(sidenav_partial: 'shared/sidenav_settings') do %>
|
||||
<section>
|
||||
<h3>E-Mail</h3>
|
||||
<p class="mb-2">
|
||||
<%= label :email, 'Address', class: 'font-bold' %>
|
||||
</p>
|
||||
<p class="flex gap-1 mb-2 sm:w-3/5">
|
||||
<input type="text" id="email" class="grow"
|
||||
value=<%= current_user.email %> disabled="disabled" />
|
||||
</p>
|
||||
</section>
|
||||
<section>
|
||||
<h3>Password</h3>
|
||||
<p class="mb-8">Use the following button to request an email with a password reset link:</p>
|
||||
<%= form_with(url: settings_reset_password_path, method: :post) do %>
|
||||
<p>
|
||||
<%= submit_tag("Send me a password reset link", class: 'btn-md btn-gray w-full sm:w-auto') %>
|
||||
</p>
|
||||
<% end %>
|
||||
</section>
|
||||
<% end %>
|
@ -1,34 +0,0 @@
|
||||
<%= render HeaderComponent.new(title: "Settings") %>
|
||||
|
||||
<%= render MainWithSidenavComponent.new(sidenav_partial: 'shared/sidenav_settings') do %>
|
||||
<section>
|
||||
<h3>Profile</h3>
|
||||
<p class="mb-2">
|
||||
<%= label :user_address, 'User address', class: 'font-bold' %>
|
||||
</p>
|
||||
<p data-controller="clipboard" class="flex gap-1 mb-2 sm:w-3/5">
|
||||
<input type="text" id="user_address" class="grow"
|
||||
value=<%= @user.address %> disabled="disabled"
|
||||
data-clipboard-target="source" />
|
||||
<button id="copy-user-address" class="btn-md btn-icon btn-blue shrink-0"
|
||||
data-clipboard-target="trigger" data-action="clipboard#copy"
|
||||
title="Copy to clipboard">
|
||||
<span class="content-initial">
|
||||
<%= render partial: "icons/copy", locals: { custom_class: "text-white h-4 w-4 inline" } %>
|
||||
</span>
|
||||
<span class="content-active hidden">
|
||||
<%= render partial: "icons/check", locals: { custom_class: "text-white h-4 w-4 inline" } %>
|
||||
</span>
|
||||
</button>
|
||||
</p>
|
||||
<p class="text-sm text-gray-500">
|
||||
Your user address for Chat and Lightning Network.
|
||||
</p>
|
||||
|
||||
<%# <%= form_for(@user, as: "profile", url: settings_profile_path) do |f| %>
|
||||
<%# <p class="mt-8">
|
||||
<%# <%= f.submit "Save changes", class: 'btn-md btn-blue w-full sm:w-auto' %>
|
||||
<%# </p>
|
||||
<%# <% end %>
|
||||
</section>
|
||||
<% end %>
|
5
app/views/settings/show.html.erb
Normal file
5
app/views/settings/show.html.erb
Normal file
@ -0,0 +1,5 @@
|
||||
<%= render HeaderComponent.new(title: "Settings") %>
|
||||
|
||||
<%= render MainWithSidenavComponent.new(sidenav_partial: 'shared/sidenav_settings') do %>
|
||||
<%= render partial: @settings_section %>
|
||||
<% end %>
|
@ -6,5 +6,5 @@
|
||||
class: main_nav_class(@current_section, :invitations) %>
|
||||
<%= link_to "Wallet", wallet_path,
|
||||
class: main_nav_class(@current_section, :wallet) %>
|
||||
<%= link_to "Settings", settings_profile_path,
|
||||
<%= link_to "Settings", settings_path,
|
||||
class: main_nav_class(@current_section, :settings) %>
|
||||
|
@ -1,10 +1,10 @@
|
||||
<%= render SidenavLinkComponent.new(
|
||||
name: "Profile", path: settings_profile_path, icon: "user",
|
||||
active: current_page?(settings_profile_path)
|
||||
name: "Profile", path: setting_path(:profile), icon: "user",
|
||||
active: current_page?(setting_path(:profile))
|
||||
) %>
|
||||
<%= render SidenavLinkComponent.new(
|
||||
name: "Account", path: settings_account_path, icon: "key",
|
||||
active: current_page?(settings_account_path)
|
||||
name: "Account", path: setting_path(:account), icon: "key",
|
||||
active: current_page?(setting_path(:account))
|
||||
) %>
|
||||
<%= render SidenavLinkComponent.new(
|
||||
name: "Security", path: "#", icon: "shield", disabled: true
|
||||
|
@ -10,13 +10,6 @@ Rails.application.routes.draw do
|
||||
match 'signup/:step', to: 'signup#steps', as: :signup_steps, via: [:get, :post]
|
||||
post 'signup_validate', to: 'signup#validate'
|
||||
|
||||
namespace :settings do
|
||||
get 'profile', to: 'profile#index'
|
||||
post 'profile', to: 'profile#update'
|
||||
get 'account', to: 'account#index'
|
||||
post 'reset_password', to: 'account#reset_password'
|
||||
end
|
||||
|
||||
namespace :contributions do
|
||||
root to: 'donations#index'
|
||||
get 'projects', to: 'projects#index'
|
||||
@ -28,6 +21,12 @@ Rails.application.routes.draw do
|
||||
get 'wallet', to: 'wallet#index'
|
||||
get 'wallet/transactions', to: 'wallet#transactions'
|
||||
|
||||
resources :settings, param: 'section', only: ['index', 'show', 'update'] do
|
||||
collection do
|
||||
post 'reset_password'
|
||||
end
|
||||
end
|
||||
|
||||
get 'lnurlpay/:address', to: 'lnurlpay#index',
|
||||
as: 'lightning_address', constraints: { address: /[^\/]+/}
|
||||
get 'lnurlpay/:address/invoice', to: 'lnurlpay#invoice',
|
||||
|
Loading…
x
Reference in New Issue
Block a user