Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Account deletion feature. #491

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions handlers/account.py
Original file line number Diff line number Diff line change
Expand Up @@ -1132,6 +1132,54 @@ def get(self):
return self.render('account/payment-cancel.html')


class AccountDeleteHandler(BaseHandler):
@tornado.web.authenticated
def post(self):
username = self.get_argument("username")
user = self.get_current_user_object()
if user.name != username:
self.add_error("username", "The username entered did not match your MLTSHP username.")
return self.get()

# username confirmation matched; assign for deletion (handled via on_finish)
# logout and return to the home page.
self._user = self.get_current_user_object()
self.log_out()

return self.redirect('/')

def on_finish(self):
"""
Account deletion can take a while, so we sign out the
user and delete the account via on_finish.

"""
if not hasattr(self, "_user"):
return

user = self._user
self._user = None

if user is None:
return

user.delete()

payment_notifications(user, "deleted")

@tornado.web.authenticated
def get(self):
user = self.get_current_user_object()
user_post_count = user.all_sharedfile_count()
user_comment_count = user.comment_count()
user_shake_count = len(user.shakes())
return self.render('account/delete.html',
user_post_count=user_post_count,
user_comment_count=user_comment_count,
user_shake_count=user_shake_count,
)


class ResendVerificationEmailHandler(BaseHandler):
"""
Simply resends an email to verify your email address.
Expand Down
4 changes: 4 additions & 0 deletions lib/utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,10 @@ def payment_notifications(user, action, amount=None):
msg = """<https://%s/user/%s|%s> just gave us some cold hard cash: %s! :smile:""" % (
options.app_host, user.name, user.name, amount
)
elif action == "deleted":
msg = """<https://%s/user/%s|%s> has deleted their account. :ghost:""" % (
options.app_host, user.name, user.name
)
elif action == "cancellation":
msg = """<https://%s/user/%s|%s> has canceled their subscription. :frowning:""" % (
options.app_host, user.name, user.name
Expand Down
13 changes: 13 additions & 0 deletions models/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import externalservice
import invitation_request
import shakemanager
import comment
# we use models.favorite due to some weird edge case where the reference
# to the module gets lost. To recreate, rename to "import favorite" and
# change references from models.favorite to just favorite. You can then
Expand Down Expand Up @@ -279,6 +280,18 @@ def sharedfiles(self, page=1, per_page=10):
user_shake = self.shake()
return user_shake.sharedfiles(page=page, per_page=per_page)

def comment_count(self):
"""
Count of all of a user's comments, excluding deleted.
"""
return comment.Comment.where_count("user_id = %s and deleted=0", self.id)

def all_sharedfile_count(self):
"""
Count of all of a user's sharedfile records, excluding deleted.
"""
return sharedfile.Sharedfile.where_count("user_id = %s and deleted=0", self.id)

def sharedfiles_count(self):
"""
Count of all of a user's saved sharedfiles, excluding deleted.
Expand Down
1 change: 1 addition & 0 deletions routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@
(r"/account/welcome-to-mltshp", handlers.account.WelcomeToMltshp),
(r"/account/membership", handlers.account.MembershipHandler),
(r"/account/payment/cancel", handlers.account.PaymentCancelHandler),
(r"/account/delete", handlers.account.AccountDeleteHandler),
(r"/account/payment/update", handlers.account.PaymentUpdateHandler),
(r'/account/settings/resend-verification-email',
handlers.account.ResendVerificationEmailHandler),
Expand Down
5 changes: 5 additions & 0 deletions static/sass/base/_core.scss
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,11 @@ h1 {
color: #333;
}

.content-narrow li {
font-size: 20px;
line-height: 30px;
}

.content-narrow .extra-info p {
line-height: 22px;
font-size: 16px;
Expand Down
71 changes: 71 additions & 0 deletions templates/account/delete.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
{% extends "base.html" %}
{% block title %}Delete Your Account{% end %}
{% block main %}
<div class="content content-narrow">
<h1 class="thank-you">Deleting Your Account</h1>

{% if errors %}
<p class="fun-form-errors"><strong>Account deletion confirmation failed.</strong>
Please enter your MLTSHP username to confirm deletion of your account.</p>
{% else %}
<p>
Was it something we said? If you want to talk about anything, feel free to
email us at <a href="mailto:[email protected]">[email protected]</a> before
continuing...
</p>

{% if user_post_count or user_comment_count or user_shake_count %}
<p>Please note that this
is <strong>an irreversible action.</strong> All content you have posted to MLTSHP will be deleted
as a result, including comments, and shakes you have created, posts you have made to any shake that you may have
contributed to.
</p>

<p>
This content includes:</p>
<ul>
{% if user_shake_count %}
<li>{{ user_shake_count }} shake{% if user_shake_count != 1 %}s{% end %}</li>
{% end %}
{% if user_post_count %}
<li>{{ user_post_count }} post{% if user_post_count != 1 %}s{% end %}</li>
{% end %}
{% if user_comment_count %}
<li>{{ user_comment_count }} comment{% if user_comment_count != 1 %}s{% end %}</li>
{% end %}
</ul>
{% end %}

<p>
To delete your MLTSHP account right now including all your content, type in your MLTSHP username
below and click the Delete button to confirm.
</p>
{% end %}

<div class="fun-form fun-form-stacked fun-form-border">
<form action="/account/delete" method="POST">
{{ xsrf_form_html() }}

<div id="create-shake-name-field" class="field">
<label>Your username</label>
<div class="field-input">
<input class="input-text" type="text" name="username">
{% if errors.username %}
<div class="error">
<span class="error-text">
{{errors.username }}
</span>
</div>
{% end %}
</div>
</div>

<div class="field field-submit">
<a class="btn btn-primary btn-shadow" href="">Delete My Account</a>
</div>
</form>
</div>

<div class="clear"><!-- --></div>
</div>
{% end %}
18 changes: 11 additions & 7 deletions templates/account/payment-cancel.html
Original file line number Diff line number Diff line change
@@ -1,21 +1,25 @@
{% extends "base.html" %}
{% block title %}Cancel Your Subscription{% end %}
{% block main %}
<div class="content content-membership">
<h1 class="thank-you">Canceling</h1>
<div class="content content-narrow">
<h1 class="thank-you">Canceling Your Subscription</h1>
<p>
Thanks for trying us out, we're sorry to see you go but understand the site isn't for everyone.
</p>

<p>
To cancel your account right now, click this button to confirm your the cancellation of your
subscription:
</p>

<form action="/account/payment/cancel" method="POST">
{{ xsrf_form_html() }}
<input type="submit"
class="subscription-button" value="Yes, Please Cancel" border="0">
</form>
<div class="fun-form fun-form-stacked fun-form-border">
<form action="/account/payment/cancel" method="POST">
{{ xsrf_form_html() }}
<div class="field field-submit">
<a class="btn btn-primary btn-shadow" href="">Yes, Please Cancel</a>
</div>
</form>
</div>

<div class="clear"><!-- --></div>
<p>
Expand Down
22 changes: 16 additions & 6 deletions templates/account/settings.html
Original file line number Diff line number Diff line change
Expand Up @@ -198,30 +198,40 @@ <h4>Your Membership Plan: <a href="/account/membership">{{ plan_name }}</a></h4>
{% end %}
</p>

{% if not site_is_readonly %}
<button id="update-card-details-btn" class="btn btn-secondary btn-shadow">Update Card Details</button>

<form id="update-card-details-form" action="/account/payment/update" method="POST">
{{ xsrf_form_html() }}
<input name="token" type="hidden" id="update-token" value="">
</form>
{% end %}
{% end %}

{% if not cancel_flag %}
{% if not cancel_flag and not site_is_readonly %}
<p>If you'd like to cancel your subscription <a href="/account/payment/cancel">you can do so here</a>.</p>
{% end %}
{% else %}
{% if cancel_flag %}
<h4>You have canceled your subscription.</h4>
{% else %}
<p>
You are currently using a free account. If you'd like
to support MLTSHP and get some nifty new benefits you can
<a href="/account/membership">upgrade to a paid account</a>.
</p>
{% end %}

{% if not site_is_readonly %}
<p>If you would like to delete your account, <a href="/account/delete">you can do so here</a>.</p>
{% end %}

{% if promotions and not site_is_readonly %}
<p>
We have an active promotion running now. To learn more about them and
to redeem a code, click this button:
</p>
<a class="btn btn-primary btn-shadow" href="/account/redeem">Redeem Code</a>
<p>
We have an active promotion running now. To learn more about them and
to redeem a code, click this button:
</p>
<a class="btn btn-primary btn-shadow" href="/account/redeem">Redeem Code</a>
{% end %}
{% end %}
</div>
Expand Down