Skip to content

Commit a6ad6f5

Browse files
committed
allow to delete accounts
1 parent 0bb26c6 commit a6ad6f5

9 files changed

Lines changed: 693 additions & 2 deletions

File tree

app/assets/javascripts/i18n/translations.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/controllers/users_controller.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,15 @@ def login
3434
end
3535
end
3636

37+
def destroy
38+
if params[:user][:email] == @user.email
39+
sign_out(current_user)
40+
@user.destroy
41+
redirect_to root_url, notice: I18n.t('notices.account_deleted')
42+
else
43+
redirect_to @user, alert: I18n.t('errors.invalid_email')
44+
end
45+
end
3746

3847
private
3948

app/views/users/show.html.haml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,12 @@
4545
= f.password_field :password, autofocus: true, autocomplete: "off"
4646
= f.password_field :password_confirmation, autocomplete: "off"
4747
= f.submit t('.submit_password')
48+
49+
%br
50+
%p
51+
%strong= link_to t('.delete_account'), '#delete_user_form', data: {toggle: "collapse"}
52+
53+
= twitter_bootstrap_form_for @user, html: {class: (params[:delete_user] ? '' : 'collapse'), id: 'delete_user_form', method: 'DELETE'} do |f|
54+
%p= t('.delete_account_notice')
55+
= f.text_field :email, value: '', autocomplete: "off"
56+
= f.submit t('.delete_account_confirm'), class: 'btn-danger'

config/locales/en.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,13 @@ en:
2525
wrong_bitcoin_address: Error updating bitcoin address
2626
user_not_found: User not found
2727
access_denied: You are not authorized to perform this action!
28+
invalid_email: Invalid email
2829
notices:
2930
project_updated: The project settings have been updated
3031
tips_decided: The tip amounts have been defined
3132
user_updated: Your information saved!
3233
user_unsubscribed: "You unsubscribed! Sorry for bothering you. Although, you can still leave us your bitcoin address to get your tips."
34+
account_deleted: Your account was deleted
3335
tip_amounts:
3436
undecided: "Undecided"
3537
free: "Free: 0%"
@@ -176,6 +178,9 @@ en:
176178
change_password: Change your password
177179
submit_password: Change my password
178180
use_from_gravatar: Use from your gravatar profile
181+
delete_account: Delete Account
182+
delete_account_notice: Enter your bitcoin address and click the button below to delete your account. This account will be gone forever, but you will still be able to sign up with the same github account. Please be certain.
183+
delete_account_confirm: Delete this account!
179184
withdrawals:
180185
index:
181186
title: Last Withdrawals

config/routes.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
resources :tips , :only => [:index]
2323
resources :deposits , :only => [:index]
2424
resources :withdrawals , :only => [:index]
25-
resources :users , :only => [:index , :show , :update]
25+
resources :users , :only => [:index , :show , :update, :destroy]
2626
resources :projects , :only => [:index , :show , :update , :edit ] do
2727
collection do
2828
get 'search'

features/cassettes/Users_should_be_able_to_delete_their_accounts/Users_should_be_able_to_see_delete_account_button_in_their_profile.yml

Lines changed: 211 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)