Allow users to delete their own account :(

This commit is contained in:
Andrew Brown 2017-12-26 15:34:52 -06:00
parent f626b65d53
commit 30e25cea3e
4 changed files with 95 additions and 0 deletions

View File

@ -27,4 +27,38 @@ class UsersController < ApplicationController
render :content_list
end
end
def delete_my_account # :(
unless user_signed_in?
redirect_to root_path
return
end
# Make sure the user is set to Starter on Stripe so we don't keep charging them
stripe_customer = Stripe::Customer.retrieve current_user.stripe_customer_id
stripe_subscription = stripe_customer.subscriptions.data[0]
stripe_subscription.plan = 'starter'
stripe_subscription.save
report_user_deletion_to_slack current_user
current_user.really_destroy!
redirect_to root_path, notice: 'Your account has been deleted. We will miss you greatly!'
end
def report_user_deletion_to_slack user
return unless Rails.env == 'production'
slack_hook = ENV['SLACK_HOOK']
return unless slack_hook
notifier = Slack::Notifier.new slack_hook,
channel: '#analytics',
username: 'tristan'
notifier.ping [
":bomb: :bomb: :bomb:",
"#{user.email.split('@').first}@ (##{user.id}) just deleted their account.",
":bomb: :bomb: :bomb:",
].join("\n")
end
end

View File

@ -7,6 +7,7 @@
<ul class="tabs tabs-fixed-width">
<li class="tab col s3"><a class="active" href="#info">Your Info</a></li>
<li class="tab col s3"><a href="#preferences">Preferences</a></li>
<li class="tab col s3"><a href="#more">More...</a></li>
</ul>
</div>
<div id="info" class="col s12">
@ -15,6 +16,9 @@
<div id="preferences" class="col s12">
<%= render partial: 'devise/registrations/panes/preferences', locals: { f: f } %>
</div>
<div id="more" class="col s12">
<%= render partial: 'devise/registrations/panes/more', locals: { f: f } %>
</div>
</div>
<div class="center">

View File

@ -0,0 +1,56 @@
<div class="card">
<div class="card-content">
<h4>To delete your account</h4>
<p>
This action is <span class="red-text">IRREVERSIBLE</span>. Your account and all of your content
will be immediately and permanently deleted. We will miss you!
</p>
<p>
<br />
<a class="waves-effect waves-light btn red modal-trigger" href="#modal1">Delete my account</a>
<div id="modal1" class="modal modal-fixed-footer">
<div class="modal-content">
<h4>Delete my account</h4>
<p>
I, <%= current_user.email %>, want to delete my account in full. I understand that my entire account,
as well as any and all content created by me, including any content I've contributed to other
universes but still own, will be immediately and permanently deleted and will not be recoverable.
</p>
<p>
I understand all of my posts on <%= link_to 'the forums', thredded_path %> will also be deleted.
</p>
<br /><br />
<div class="row">
<div class="col s12 m6">
<h5>Do you need support instead?</h5>
<p>
You can <a href="https://docs.google.com/forms/d/e/1FAIpQLSe0jnqJlcPJDqwogGere5j8-8F1nSGGYkzbsI-XkOeMnGwLrA/viewform">
report a problem</a> (available under the question-mark menu on any page) or reach out
directly to an<span>dre</span>w<span></span>@<em></em>indent<span>labs</span>.com. I would be happy to help!
</p>
</div>
<div class="col s12 m6">
<h5>
Do you want to leave feedback?
</h5>
<p>
We listen to any and all feedback, no matter how small or large.
</p>
<p>
<br /><br />
<%= link_to 'Leave feedback', 'https://docs.google.com/forms/d/e/1FAIpQLScZWEVMgm8hBWIIVj1LPzo0GqflmWUrLQlc4TAYqsaS087oAA/viewform', class: 'btn' %>
</p>
</div>
</div>
</div>
<div class="modal-footer">
<%= link_to delete_my_account_path, class: 'modal-action modal-close waves-effect waves-green btn-flat', method: :DELETE do %>
Delete my account
<% end %>
</div>
</div>
</p>
</div>
</div>

View File

@ -66,6 +66,7 @@ Rails.application.routes.draw do
end
end
resources :documents
delete 'delete_my_account', to: 'users#delete_my_account'
# Lab apps
scope '/app' do