diff --git a/handlers/account.py b/handlers/account.py index 42028d73..28620eb3 100644 --- a/handlers/account.py +++ b/handlers/account.py @@ -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. diff --git a/lib/utilities.py b/lib/utilities.py index 9ccf5793..6b2e1327 100644 --- a/lib/utilities.py +++ b/lib/utilities.py @@ -221,6 +221,10 @@ def payment_notifications(user, action, amount=None): msg = """ just gave us some cold hard cash: %s! :smile:""" % ( options.app_host, user.name, user.name, amount ) + elif action == "deleted": + msg = """ has deleted their account. :ghost:""" % ( + options.app_host, user.name, user.name + ) elif action == "cancellation": msg = """ has canceled their subscription. :frowning:""" % ( options.app_host, user.name, user.name diff --git a/models/user.py b/models/user.py index d81b8776..ed4fc4ac 100644 --- a/models/user.py +++ b/models/user.py @@ -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 @@ -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. diff --git a/routes.py b/routes.py index 910ad65a..1e214472 100644 --- a/routes.py +++ b/routes.py @@ -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), diff --git a/static/sass/base/_core.scss b/static/sass/base/_core.scss index 89ea9b7e..4d315592 100644 --- a/static/sass/base/_core.scss +++ b/static/sass/base/_core.scss @@ -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; diff --git a/templates/account/delete.html b/templates/account/delete.html new file mode 100644 index 00000000..2759284c --- /dev/null +++ b/templates/account/delete.html @@ -0,0 +1,71 @@ +{% extends "base.html" %} +{% block title %}Delete Your Account{% end %} +{% block main %} +
+

Deleting Your Account

+ + {% if errors %} +

Account deletion confirmation failed. + Please enter your MLTSHP username to confirm deletion of your account.

+ {% else %} +

+ Was it something we said? If you want to talk about anything, feel free to + email us at hello@mltshp.com before + continuing... +

+ + {% if user_post_count or user_comment_count or user_shake_count %} +

Please note that this + is an irreversible action. 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. +

+ +

+ This content includes:

+
    + {% if user_shake_count %} +
  • {{ user_shake_count }} shake{% if user_shake_count != 1 %}s{% end %}
  • + {% end %} + {% if user_post_count %} +
  • {{ user_post_count }} post{% if user_post_count != 1 %}s{% end %}
  • + {% end %} + {% if user_comment_count %} +
  • {{ user_comment_count }} comment{% if user_comment_count != 1 %}s{% end %}
  • + {% end %} +
+ {% end %} + +

+ To delete your MLTSHP account right now including all your content, type in your MLTSHP username + below and click the Delete button to confirm. +

+ {% end %} + +
+
+ {{ xsrf_form_html() }} + +
+ +
+ + {% if errors.username %} +
+ + {{errors.username }} + +
+ {% end %} +
+
+ + +
+
+ +
+
+{% end %} diff --git a/templates/account/payment-cancel.html b/templates/account/payment-cancel.html index d8991d10..6b5d9408 100644 --- a/templates/account/payment-cancel.html +++ b/templates/account/payment-cancel.html @@ -1,21 +1,25 @@ {% extends "base.html" %} {% block title %}Cancel Your Subscription{% end %} {% block main %} -
-

Canceling

+
+

Canceling Your Subscription

Thanks for trying us out, we're sorry to see you go but understand the site isn't for everyone.

+

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

-
- {{ xsrf_form_html() }} - -
+
+
+ {{ xsrf_form_html() }} + +
+

diff --git a/templates/account/settings.html b/templates/account/settings.html index 4cddc4e1..3aafc618 100644 --- a/templates/account/settings.html +++ b/templates/account/settings.html @@ -198,6 +198,7 @@

Your Membership Plan: {{ plan_name }}

{% end %}

+ {% if not site_is_readonly %}
@@ -205,23 +206,32 @@

Your Membership Plan: {{ plan_name }}

{% end %} + {% end %} - {% if not cancel_flag %} + {% if not cancel_flag and not site_is_readonly %}

If you'd like to cancel your subscription you can do so here.

{% end %} {% else %} + {% if cancel_flag %} +

You have canceled your subscription.

+ {% else %}

You are currently using a free account. If you'd like to support MLTSHP and get some nifty new benefits you can upgrade to a paid account.

+ {% end %} + + {% if not site_is_readonly %} +

If you would like to delete your account, you can do so here.

+ {% end %} {% if promotions and not site_is_readonly %} -

- We have an active promotion running now. To learn more about them and - to redeem a code, click this button: -

- Redeem Code +

+ We have an active promotion running now. To learn more about them and + to redeem a code, click this button: +

+ Redeem Code {% end %} {% end %}