Skip to content

Commit

Permalink
implements a first version of the forms. Missing: a) tests and b) che…
Browse files Browse the repository at this point in the history
…ck db constraints (duplicate email "", etc)
  • Loading branch information
kikito committed Oct 16, 2015
1 parent 1511f81 commit 9cc1585
Show file tree
Hide file tree
Showing 8 changed files with 70 additions and 6 deletions.
20 changes: 20 additions & 0 deletions app/controllers/users/registrations_controller.rb
Expand Up @@ -10,6 +10,22 @@ def create
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

Expand All @@ -32,6 +48,10 @@ def sign_up_params
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
Expand Down
5 changes: 4 additions & 1 deletion app/views/account/show.html.erb
@@ -1,6 +1,9 @@
<div class="row account">
<div class="small-12 column">
<%= link_to t("account.show.change_credentials_link"), edit_user_registration_path, class: "button radius small secondary right" %>
<div class="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" %>
</div>

<%= avatar_image(@account, seed: @account.id, size: 60) %>

Expand Down
27 changes: 27 additions & 0 deletions app/views/users/registrations/delete_form.html.erb
@@ -0,0 +1,27 @@
<i class="icon-angle-left left"></i>&nbsp;<%= link_to t("devise_views.users.registrations.edit.back_link"), :back, class: "left back" %>

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

<%= form_for(resource, as: resource_name,
url: users_registrations_path,
html: { method: :delete }) do |f| %>
<%= devise_error_messages! %>
<p>
<%= t("devise_views.users.registrations.delete_form.info") %>
</p>

<div class="row">
<div class="small-12 column">
<%= 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") %>
</div>

<div class="small-12 column">
<%= f.submit t("devise_views.users.registrations.delete_form.submit"), class: "button radius danger" %>
</div>
</div>
<% end %>


5 changes: 5 additions & 0 deletions config/locales/devise_views.en.yml
Expand Up @@ -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"
Expand Down
5 changes: 5 additions & 0 deletions config/locales/devise_views.es.yml
Expand Up @@ -77,6 +77,11 @@ es:
instructions_1_html: "Por favor <b>revisa tu correo electrónico</b> - te hemos enviado un <b>enlace para confirmar tu cuenta</b>."
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:
Expand Down
1 change: 1 addition & 0 deletions config/locales/en.yml
Expand Up @@ -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"
Expand Down
1 change: 1 addition & 0 deletions config/locales/es.yml
Expand Up @@ -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"
Expand Down
12 changes: 7 additions & 5 deletions 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',
Expand All @@ -22,7 +18,11 @@
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
Expand Down Expand Up @@ -60,7 +60,9 @@
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
Expand Down

0 comments on commit 9cc1585

Please sign in to comment.