From c34ea8451f12196784420180605cf82b66729ffb Mon Sep 17 00:00:00 2001 From: Alex Turchyn Date: Wed, 7 Jun 2023 12:04:11 +0300 Subject: [PATCH] simplify the profile settings form --- app/controllers/profile_controller.rb | 26 ++++---------- app/models/user.rb | 6 +--- app/views/devise/confirmations/new.html.erb | 14 -------- .../mailer/confirmation_instructions.html.erb | 3 -- app/views/devise/shared/_links.html.erb | 14 ++++---- app/views/profile/_navigation.html.erb | 36 ------------------- app/views/profile/email.html.erb | 30 ---------------- .../{contact.html.erb => index.html.erb} | 22 +++++++++++- app/views/profile/password.html.erb | 25 ------------- app/views/shared/_navbar.html.erb | 2 +- app/views/shared/_settings_nav.html.erb | 2 +- config/routes.rb | 12 +++---- ...0230606210549_add_confirmation_to_users.rb | 8 ----- db/schema.rb | 6 +--- 14 files changed, 43 insertions(+), 163 deletions(-) delete mode 100644 app/views/devise/confirmations/new.html.erb delete mode 100644 app/views/devise/mailer/confirmation_instructions.html.erb delete mode 100644 app/views/profile/_navigation.html.erb delete mode 100644 app/views/profile/email.html.erb rename app/views/profile/{contact.html.erb => index.html.erb} (54%) delete mode 100644 app/views/profile/password.html.erb delete mode 100644 db/migrate/20230606210549_add_confirmation_to_users.rb diff --git a/app/controllers/profile_controller.rb b/app/controllers/profile_controller.rb index f0807995..0b90f5a7 100644 --- a/app/controllers/profile_controller.rb +++ b/app/controllers/profile_controller.rb @@ -3,40 +3,28 @@ class ProfileController < ApplicationController def update_contact if current_user.update(contact_params) - redirect_to contact_settings_profile_index_path, notice: 'Contact information successfully updated' + redirect_to settings_profile_index_path, notice: 'Contact information successfully updated' else - render :contact, status: :unprocessable_entity + render :index, status: :unprocessable_entity end end def update_password - if current_user.update_with_password(password_params) + if current_user.update(password_params) bypass_sign_in(current_user) - redirect_to password_settings_profile_index_path, notice: 'Password successfully changed' + redirect_to settings_profile_index_path, notice: 'Password successfully changed' else - render :password, status: :unprocessable_entity - end - end - - def update_email - if current_user.update_with_password(email_params) - redirect_to email_settings_profile_index_path, notice: 'Email successfully updated. Please check your new email for confirmation instructions.' - else - render :email, status: :unprocessable_entity + render :index, status: :unprocessable_entity end end private def contact_params - params.require(:user).permit(:first_name, :last_name, account_attributes: %i[name]) + params.require(:user).permit(:first_name, :last_name, :email, account_attributes: %i[name]) end def password_params - params.require(:user).permit(:current_password, :password, :password_confirmation) - end - - def email_params - params.require(:user).permit(:current_password, :email) + params.require(:user).permit(:password, :password_confirmation) end end diff --git a/app/models/user.rb b/app/models/user.rb index a53fe09f..68a1f024 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -5,9 +5,6 @@ # Table name: users # # id :bigint not null, primary key -# confirmation_sent_at :datetime -# confirmation_token :string -# confirmed_at :datetime # current_sign_in_at :datetime # current_sign_in_ip :string # deleted_at :datetime @@ -24,7 +21,6 @@ # reset_password_token :string # role :string not null # sign_in_count :integer default(0), not null -# unconfirmed_email :string # unlock_token :string # created_at :datetime not null # updated_at :datetime not null @@ -49,7 +45,7 @@ class User < ApplicationRecord belongs_to :account - devise :database_authenticatable, :recoverable, :rememberable, :validatable, :trackable, :confirmable + devise :database_authenticatable, :recoverable, :rememberable, :validatable, :trackable devise :registerable # if ENV['APP_MULTITENANT'] attribute :role, :string, default: 'admin' diff --git a/app/views/devise/confirmations/new.html.erb b/app/views/devise/confirmations/new.html.erb deleted file mode 100644 index e37dd597..00000000 --- a/app/views/devise/confirmations/new.html.erb +++ /dev/null @@ -1,14 +0,0 @@ -
-

Resend confirmation instructions

- <%= form_for(resource, as: resource_name, url: confirmation_path(resource_name), html: { method: :post, class: 'space-y-6' }) do |f| %> - <%= render "devise/shared/error_messages", resource: resource %> -
- <%= f.label :email, class: 'label' %> - <%= f.email_field :email, autofocus: true, autocomplete: "email", value: (resource.pending_reconfirmation? ? resource.unconfirmed_email : resource.email), class: 'base-input' %> -
-
- <%= f.submit "Resend confirmation instructions", class: 'base-button' %> -
- <% end %> - <%= render "devise/shared/links" %> -
diff --git a/app/views/devise/mailer/confirmation_instructions.html.erb b/app/views/devise/mailer/confirmation_instructions.html.erb deleted file mode 100644 index 57193aa7..00000000 --- a/app/views/devise/mailer/confirmation_instructions.html.erb +++ /dev/null @@ -1,3 +0,0 @@ -

Welcome <%= @email %>!

-

You can confirm your account email through the link below:

-

<%= link_to 'Confirm my account', confirmation_url(@resource, confirmation_token: @token) %>

diff --git a/app/views/devise/shared/_links.html.erb b/app/views/devise/shared/_links.html.erb index d6c10878..cc73180b 100644 --- a/app/views/devise/shared/_links.html.erb +++ b/app/views/devise/shared/_links.html.erb @@ -1,22 +1,22 @@ -
+
<%- if controller_name != 'sessions' %> - <%= link_to 'Log in', new_session_path(resource_name), class: 'badge badge-outline my-1' %> + <%= link_to 'Log in', new_session_path(resource_name), class: 'link link-hover' %> <% end %> <%- if devise_mapping.registerable? && controller_name != 'registrations' %> - <%= link_to 'Sign up', new_registration_path, class: 'badge badge-outline my-1' %> + <%= link_to 'Sign up', new_registration_path, class: 'link link-hover' %> <% end %> <%- if devise_mapping.recoverable? && controller_name != 'passwords' && controller_name != 'registrations' %> - <%= link_to 'Forgot your password?', new_password_path(resource_name), class: 'badge badge-outline my-1' %> + <%= link_to 'Forgot your password?', new_password_path(resource_name), class: 'link link-hover' %> <% end %> <%- if devise_mapping.confirmable? && controller_name != 'confirmations' %> - <%= link_to "Didn't receive confirmation instructions?", new_confirmation_path(resource_name), class: 'badge badge-outline my-1' %> + <%= link_to "Didn't receive confirmation instructions?", new_confirmation_path(resource_name), class: 'link link-hover' %> <% end %> <%- if devise_mapping.lockable? && resource_class.unlock_strategy_enabled?(:email) && controller_name != 'unlocks' %> - <%= link_to "Didn't receive unlock instructions?", new_unlock_path(resource_name), class: 'badge badge-outline my-1' %> + <%= link_to "Didn't receive unlock instructions?", new_unlock_path(resource_name), class: 'link link-hover' %> <% end %> <%- if devise_mapping.omniauthable? %> <%- resource_class.omniauth_providers.each do |provider| %> - <%= button_to "Sign in with #{OmniAuth::Utils.camelize(provider)}", omniauth_authorize_path(resource_name, provider), class: 'badge badge-outline my-1', data: { turbo: false } %> + <%= button_to "Sign in with #{OmniAuth::Utils.camelize(provider)}", omniauth_authorize_path(resource_name, provider), class: 'link link-hover', data: { turbo: false } %> <% end %> <% end %>
diff --git a/app/views/profile/_navigation.html.erb b/app/views/profile/_navigation.html.erb deleted file mode 100644 index 39db35ea..00000000 --- a/app/views/profile/_navigation.html.erb +++ /dev/null @@ -1,36 +0,0 @@ - - - diff --git a/app/views/profile/email.html.erb b/app/views/profile/email.html.erb deleted file mode 100644 index cb40c857..00000000 --- a/app/views/profile/email.html.erb +++ /dev/null @@ -1,30 +0,0 @@ -
- <%= render 'shared/settings_nav' %> -
-

Profile

- <%= render 'navigation' %> - <%= form_for current_user, url: update_email_settings_profile_index_path, method: :patch, html: { autocomplete: 'off', class: 'space-y-4' } do |f| %> - <% if current_user.pending_reconfirmation? %> -
- -
-

Currently waiting confirmation

-
Unconfirmed email: <%= current_user.unconfirmed_email %>
-
-
- <% end %> -
- <%= f.label :email, 'New email', class: 'label' %> - <%= f.email_field :email, autocomplete: 'off', class: 'base-input' %> -
-
- <%= f.label :current_password, 'Current password', class: 'label' %> - <%= f.password_field :current_password, autocomplete: 'off', class: 'base-input' %> -
-
- <%= f.button button_title, class: 'base-button' %> -
- <% end %> -
-
-
diff --git a/app/views/profile/contact.html.erb b/app/views/profile/index.html.erb similarity index 54% rename from app/views/profile/contact.html.erb rename to app/views/profile/index.html.erb index 5c686b9c..5dc63779 100644 --- a/app/views/profile/contact.html.erb +++ b/app/views/profile/index.html.erb @@ -2,7 +2,9 @@ <%= render 'shared/settings_nav' %>

Profile

- <%= render 'navigation' %> +

+ Manage your contact information +

<%= form_for current_user, url: update_contact_settings_profile_index_path, method: :patch, html: { autocomplete: 'off', class: 'space-y-4' } do |f| %>
@@ -14,6 +16,10 @@ <%= f.text_field :last_name, required: true, class: 'base-input' %>
+
+ <%= f.label :email, 'Email', class: 'label' %> + <%= f.email_field :email, autocomplete: 'off', class: 'base-input' %> +
<%= f.fields_for :account do |ff| %>
<%= ff.label :name, 'Company Name', class: 'label' %> @@ -24,6 +30,20 @@ <%= f.button button_title, class: 'base-button' %>
<% end %> +

Change Password

+ <%= form_for current_user, url: update_password_settings_profile_index_path, method: :patch, html: { autocomplete: 'off', class: 'space-y-4' } do |f| %> +
+ <%= f.label :password, 'New password', class: 'label' %> + <%= f.password_field :password, autocomplete: 'off', class: 'base-input' %> +
+
+ <%= f.label :password_confirmation, 'Confirm new password', class: 'label' %> + <%= f.password_field :password_confirmation, autocomplete: 'off', class: 'base-input' %> +
+
+ <%= f.button button_title, class: 'base-button' %> +
+ <% end %>
diff --git a/app/views/profile/password.html.erb b/app/views/profile/password.html.erb deleted file mode 100644 index 8a54cb03..00000000 --- a/app/views/profile/password.html.erb +++ /dev/null @@ -1,25 +0,0 @@ -
- <%= render 'shared/settings_nav' %> -
-

Profile

- <%= render 'navigation' %> - <%= form_for current_user, url: update_password_settings_profile_index_path, method: :patch, html: { autocomplete: 'off', class: 'space-y-4' } do |f| %> -
- <%= f.label :current_password, 'Current password', class: 'label' %> - <%= f.password_field :current_password, autocomplete: 'off', class: 'base-input' %> -
-
- <%= f.label :password, 'New password', class: 'label' %> - <%= f.password_field :password, autocomplete: 'off', class: 'base-input' %> -
-
- <%= f.label :password_confirmation, 'Confirm new password', class: 'label' %> - <%= f.password_field :password_confirmation, autocomplete: 'off', class: 'base-input' %> -
-
- <%= f.button button_title, class: 'base-button' %> -
- <% end %> -
-
-
diff --git a/app/views/shared/_navbar.html.erb b/app/views/shared/_navbar.html.erb index 27b8a588..6716731e 100644 --- a/app/views/shared/_navbar.html.erb +++ b/app/views/shared/_navbar.html.erb @@ -12,7 +12,7 @@