From 58696d21688a6e79a6545eae57eb896c9ba3717b Mon Sep 17 00:00:00 2001 From: Torsten Date: Fri, 20 Jan 2023 08:15:33 +0200 Subject: [PATCH] change email and password pages --- app/controllers/registrations_controller.rb | 62 +++++++++++++++++++ app/views/devise/registrations/edit.html.haml | 24 +++---- .../devise/registrations/edit_email.html.haml | 32 ++++++++++ app/views/members/show.html.haml | 15 ++++- config/routes.rb | 5 +- 5 files changed, 118 insertions(+), 20 deletions(-) create mode 100644 app/controllers/registrations_controller.rb create mode 100644 app/views/devise/registrations/edit_email.html.haml diff --git a/app/controllers/registrations_controller.rb b/app/controllers/registrations_controller.rb new file mode 100644 index 0000000..a28c39e --- /dev/null +++ b/app/controllers/registrations_controller.rb @@ -0,0 +1,62 @@ +# frozen_string_literal: true + +class RegistrationsController < Devise::RegistrationsController + # before_action :configure_sign_up_params, only: [:create] + # before_action :configure_account_update_params, only: [:update] + prepend_before_action :authenticate_scope!, only: [:edit_email] + + + # POST /resource + def create + puts "CREATE" + super + end + + # GET /resource/edit + def edit_email + build_resource + puts "EDIT" + end + + def edit + build_resource + super + end + # PUT /resource + def update + puts "UPDATE" + super + end + + def resource_name + "member" + end + + # DELETE /resource + # def destroy + # super + # end + + # protected + + # If you have extra params to permit, append them to the sanitizer. + # def configure_sign_up_params + # devise_parameter_sanitizer.permit(:sign_up, keys: [:attribute]) + # end + + # If you have extra params to permit, append them to the sanitizer. + # def configure_account_update_params + # devise_parameter_sanitizer.permit(:account_update, keys: [:attribute]) + # end + + # The path used after sign up. + def after_sign_up_path_for(resource) + puts "after sign up" + super(resource) + end + + # The path used after sign up for inactive accounts. + # def after_inactive_sign_up_path_for(resource) + # super(resource) + # end +end diff --git a/app/views/devise/registrations/edit.html.haml b/app/views/devise/registrations/edit.html.haml index 5181bc6..be8c36d 100644 --- a/app/views/devise/registrations/edit.html.haml +++ b/app/views/devise/registrations/edit.html.haml @@ -1,26 +1,17 @@ .flex.justify-center .w-full.max-w-xs - %h1.font-hairline.mb-6.text-center - Edit #{resource_name.to_s.humanize} + %h1.font-hairline.mb-6.text-center.text-2xl + Change password = form_for(resource, as: resource_name, html: { class: "bg-white mb-4 px-8 pt-6 pb-8 rounded shadow-md", method: :put } , url: registration_path(resource_name) ) do |f| = render "devise/shared/error_messages", resource: resource - .mb-4 - = f.label :email, class: "block font-bold mb-2 text-gray-700 text-sm" - %br/ - = f.email_field :email, | - autofocus: true, | - autocomplete: "email", | - class: "appearance-none border rounded w-full py-2 px-3 text-gray-700 leading-tight focus:outline-none shadow focus:shadow-outline" | - if devise_mapping.confirmable? && resource.pending_reconfirmation? %div Currently waiting confirmation for: #{resource.unconfirmed_email} .mb-4 - = f.label :password, class: "block font-bold mb-2 text-gray-700 text-sm" - %i (leave blank if you don't want to change it) - %br/ + = f.label :new_password, class: "block font-bold mb-2 text-gray-700 text-sm" = f.password_field :password, autocomplete: "new-password", class: "shadow appearance-none border rounded w-full py-2 px-3 text-gray-700 mb-3 leading-tight focus:outline-none focus:shadow-outline" .mb-4 = f.label :password_confirmation, class: "block font-bold mb-2 text-gray-700 text-sm" @@ -34,7 +25,8 @@ class: "shadow appearance-none border rounded w-full py-2 px-3 text-gray-700 mb-3 leading-tight focus:outline-none focus:shadow-outline" | .actions = f.submit "Update", class: "button bg-cyan-700 hover:bg-cyan-500 font-bold text-white focus:outline-none py-2 px-4 rounded focus:shadow-outline w-full" - %p - Unhappy? - %span= button_to "Delete my account", registration_path(resource_name), data: { confirm: "Are you sure?" }, method: :delete - = link_to "Back", :back + .flex.justify-between + %p + %span= button_to "Delete my account", registration_path(resource_name), data: { confirm: "Are you sure?" }, method: :delete , class: button_classes + %button{class: button_classes} + = link_to "Back", :back diff --git a/app/views/devise/registrations/edit_email.html.haml b/app/views/devise/registrations/edit_email.html.haml new file mode 100644 index 0000000..92adee5 --- /dev/null +++ b/app/views/devise/registrations/edit_email.html.haml @@ -0,0 +1,32 @@ +.flex.justify-center + .w-full.max-w-xs + %h1.font-hairline.mb-6.text-center.text-2xl + Change your email + .text-center.text-lg + (requires confirmation) + = form_for(resource, as: resource_name, + html: { class: "bg-white mb-4 px-8 pt-6 pb-8 rounded shadow-md", + method: :put } , + url: registration_path(resource_name) ) do |f| + = render "devise/shared/error_messages", resource: resource + .mb-4 + = f.label :new_email, class: "block font-bold mb-2 text-gray-700 text-sm" + %br/ + = f.email_field :email, | + autofocus: true, | + autocomplete: "email", | + class: "appearance-none border rounded w-full py-2 px-3 text-gray-700 leading-tight focus:outline-none shadow focus:shadow-outline" | + - if devise_mapping.confirmable? && resource.pending_reconfirmation? + %div + Currently waiting confirmation for: #{resource.unconfirmed_email} + .mb-4 + = f.label :current_password, class: "block font-bold mb-2 text-gray-700 text-sm" + = f.password_field :current_password, | + autocomplete: "current-password", | + class: "shadow appearance-none border rounded w-full py-2 px-3 text-gray-700 mb-3 leading-tight focus:outline-none focus:shadow-outline" | + .actions + = f.submit "Update", class: "button bg-cyan-700 hover:bg-cyan-500 font-bold text-white focus:outline-none py-2 px-4 rounded focus:shadow-outline w-full" + + = link_to :back do + %button{class: button_classes} + Back diff --git a/app/views/members/show.html.haml b/app/views/members/show.html.haml index fed6c8f..15b5239 100644 --- a/app/views/members/show.html.haml +++ b/app/views/members/show.html.haml @@ -46,6 +46,15 @@ %div= entity.type %div= entity.name %div= entity.value -= form_tag( destroy_member_session_path , {method: :delete } ) do - %button.mt-10.ml-10.bg-cyan-200.mr-3.inline-block.rounded-lg.px-4.py-3.text-md.font-medium.border.border-gray-400{type: :submit} - Sign out + +.grid.grid-cols-1.md:grid-cols-2.lg:grid-cols-3 + .flex.justify-beteen + = form_tag( destroy_member_session_path , {method: :delete } ) do + %button.mt-10.ml-10.bg-cyan-200.mr-3.inline-block.rounded-lg.px-4.py-3.text-md.font-medium.border.border-gray-400{type: :submit} + Sign out + = link_to edit_member_registration_path do + %button.mt-10.ml-10.bg-cyan-200.mr-3.inline-block.rounded-lg.px-4.py-3.text-md.font-medium.border.border-gray-400{type: :submit} + Change Password + = link_to members_edit_email_path do + %button.mt-10.ml-10.bg-cyan-200.mr-3.inline-block.rounded-lg.px-4.py-3.text-md.font-medium.border.border-gray-400{type: :submit} + Change Email diff --git a/config/routes.rb b/config/routes.rb index fb962db..6788534 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -3,7 +3,10 @@ Rails.application.routes.draw do resources :profiles resources :entities - devise_for :members + devise_for :members ,controllers: { registrations: 'registrations' } + devise_scope :member do + get "/members/edit_email" , to: "registrations#edit_email" + end resources :members