diff --git a/app/controllers/users/registrations_controller.rb b/app/controllers/users/registrations_controller.rb index 8e04c0d61..9257488ee 100644 --- a/app/controllers/users/registrations_controller.rb +++ b/app/controllers/users/registrations_controller.rb @@ -10,6 +10,22 @@ class Users::RegistrationsController < Devise::RegistrationsController end end + def delete_form + build_resource({}) + end + + def delete + # The only difference between this version of delete and the original are the following two lines + # (we build the resource differently and we also call erase instead of destroy) + build_resource(erase_params) + resource.erase(params[:erase_reason]) + + yield resource if block_given? + Devise.sign_out_all_scopes ? sign_out : sign_out(resource_name) + set_flash_message :notice, :destroyed if is_flashing_format? + respond_with_navigational(resource){ redirect_to after_sign_out_path_for(resource_name) } + end + def success end @@ -32,6 +48,10 @@ class Users::RegistrationsController < Devise::RegistrationsController params.require(:user).permit(:username, :email, :password, :password_confirmation, :captcha, :captcha_key, :terms_of_service) end + def erase_params + params.require(:user).permit(:erase_reason) + end + def after_inactive_sign_up_path_for(resource_or_scope) users_sign_up_success_path end diff --git a/app/views/account/show.html.erb b/app/views/account/show.html.erb index c52219955..8c9be93c7 100644 --- a/app/views/account/show.html.erb +++ b/app/views/account/show.html.erb @@ -1,6 +1,9 @@
- <%= link_to t("account.show.change_credentials_link"), edit_user_registration_path, class: "button radius small secondary right" %> +
+ <%= link_to t("account.show.change_credentials_link"), edit_user_registration_path, class: "button radius small secondary" %> + <%= link_to t("account.show.erase_account_link"), users_registrations_delete_form_path, class: "button radius small danger" %> +
<%= avatar_image(@account, seed: @account.id, size: 60) %> diff --git a/app/views/users/registrations/delete_form.html.erb b/app/views/users/registrations/delete_form.html.erb new file mode 100644 index 000000000..96bb8a4d5 --- /dev/null +++ b/app/views/users/registrations/delete_form.html.erb @@ -0,0 +1,27 @@ + <%= link_to t("devise_views.users.registrations.edit.back_link"), :back, class: "left back" %> + +

<%= t("devise_views.users.registrations.delete_form.title") %>

+ +<%= form_for(resource, as: resource_name, + url: users_registrations_path, + html: { method: :delete }) do |f| %> + <%= devise_error_messages! %> +

+ <%= t("devise_views.users.registrations.delete_form.info") %> +

+ +
+
+ <%= f.text_field :erase_reason, + autofocus: true, + placeholder: t("devise_views.users.registrations.delete_form.erase_reason_label"), + label: t("devise_views.users.registrations.delete_form.erase_reason_label") %> +
+ +
+ <%= f.submit t("devise_views.users.registrations.delete_form.submit"), class: "button radius danger" %> +
+
+<% end %> + + diff --git a/config/locales/devise_views.en.yml b/config/locales/devise_views.en.yml index 2c04d3ce8..687513e77 100644 --- a/config/locales/devise_views.en.yml +++ b/config/locales/devise_views.en.yml @@ -59,6 +59,11 @@ en: need_current: "We need your current password to confirm your changes" update_submit: "Update" back_link: "Back" + delete_form: + title: "Erase account" + info: "This action can not be undone. Please make sure this is what you want. If you want, you can leave us a reason (this is not mandatory)" + erase_reason_label: "Reason" + submit: "Erase my account" new: title: "Sign up" username_label: "Username" diff --git a/config/locales/devise_views.es.yml b/config/locales/devise_views.es.yml index f2ca13215..c6924ea5e 100644 --- a/config/locales/devise_views.es.yml +++ b/config/locales/devise_views.es.yml @@ -77,6 +77,11 @@ es: instructions_1_html: "Por favor revisa tu correo electrónico - te hemos enviado un enlace para confirmar tu cuenta." instructions_2_html: "Una vez confirmado, podrás empezar a participar." back_to_index: "Entendido, volver a la página principal" + delete_form: + title: "Darme de baja" + info: "Esta acción no se puede deshacer. Una vez que des de baja tu cuenta, no podrás volver a hacer login con ella. Si quieres, puedes informarnos de la razón por la que de tas de baja (no es obligatorio)." + erase_reason_label: "Razón de la baja" + submit: "Borrar mi cuenta" organizations: registrations: new: diff --git a/config/locales/en.yml b/config/locales/en.yml index 14ca26510..c85a4114d 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -282,6 +282,7 @@ en: change_credentials_link: "Change my credentials" email_on_comment_label: "Receive email when someone comments on my debates or proposals" email_on_comment_reply_label: "Receive email when someone replies to my comments" + erase_account_link: "Erase my account" personal: "Personal data" username_label: "Username" phone_number_label: "Phone number" diff --git a/config/locales/es.yml b/config/locales/es.yml index 866b2179e..1faa0196a 100644 --- a/config/locales/es.yml +++ b/config/locales/es.yml @@ -282,6 +282,7 @@ es: change_credentials_link: "Cambiar mis datos de acceso" email_on_comment_label: "Recibir un email cuando alguien comenta en mis propuestas o debates" email_on_comment_reply_label: "Recibir un email cuando alguien contesta a mis comentarios" + erase_account_link: "Darme de baja" personal: "Datos personales" username_label: "Nombre de usuario" phone_number_label: "Teléfono" diff --git a/config/routes.rb b/config/routes.rb index c1a0e38ba..5e6f07c2c 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,9 +1,5 @@ Rails.application.routes.draw do - as :user do - match '/user/confirmation' => 'users/confirmations#update', :via => :patch, :as => :update_user_confirmation - end - devise_for :users, controllers: { registrations: 'users/registrations', sessions: 'users/sessions', @@ -22,7 +18,11 @@ Rails.application.routes.draw do end devise_scope :user do + patch '/user/confirmation', to: 'users/confirmations#update', as: :update_user_confirmation + get 'users/sign_up/success', to: 'users/registrations#success' + get 'users/registrations/delete_form', to: 'users/registrations#delete_form' + delete 'users/registrations', to: 'users/registrations#delete' get :finish_signup, to: 'users/registrations#finish_signup' patch :do_finish_signup, to: 'users/registrations#do_finish_signup' end @@ -60,7 +60,9 @@ Rails.application.routes.draw do end end - resource :account, controller: "account", only: [:show, :update] + resource :account, controller: "account", only: [:show, :update, :delete] do + collection { get :erase } + end resource :verification, controller: "verification", only: [:show] scope module: :verification do