Repository: readthedocs/readthedocs.org

Issue:
Enable users to delete their own account
Currently, people are posting issues if they need their account deleted. This leads to extra noise in the issues, and to some privacy concerns. 

I propose we add an email account and notice to the README, letting users know where they can email to request account deletion. This will allow better triaging and chunking of deletions. 

@ericholscher What do you think? 


Discussion:
Is adding a "Delete Account" button somewhere out of the question?
That would also work. This is a proposed stop-gap measure which would be easier to set up, I believe. 
There's a bunch of background here: https://github.com/rtfd/readthedocs.org/issues/1408 -- tl;dr, we need to decide how to handle a number of cases when deleting folks, and it isn't as simple as running user.delete(). 
I lied, #1408 is about deleting projects, which is a follow on effect on deleting users. 
Yep. What we can do now, though, is to set up a clearer, more private way for users to contact you (or someone else who can do this task), which doesn't require them spamming all of the watchers. What do you think? 
Hmm, I guess. Though having the requests just come to my email isn't a great solution either. We should really implement a proper delete function; but I guess the people who want to delete their accounts are the least likely to contribute :/
I feel you. How about we rename this "Enable users to delete their own account", tag it as Help Wanted, and see if anyone wants to bite? :) 
Works for me. I'd like to get to it, but as above, users who are leaving the platform are hard to prioritize, so it hasn't gotten done. 
> users who are leaving the platform are hard to prioritize,

Ah. I'm sorry, I wasn't clear! I agree, I'm not prioritizing them. What I'm prioritizing is the notifications of watchers to this repo - people we want to keep! - and ensuring that we don't flood their streams with issues from people saying 'Delete my account please'. Some of the noise can be removed with a better process, leading to higher signal. 

I'll change the name of the issue now! Anyone who wants to take this on, feel free to comment here!
@RichardLitt So the fix would be adding a button for the user to delete their account?
@safwanrahman Yep. Want to take a crack at it? 
@RichardLitt I will go through the code and check if I can make it work. Hope that will work

Resolving patch:
diff --git a/readthedocs/core/forms.py b/readthedocs/core/forms.py
--- a/readthedocs/core/forms.py
+++ b/readthedocs/core/forms.py
@@ -4,6 +4,7 @@
 from builtins import object
 import logging
 
+from django.contrib.auth.models import User
 from haystack.forms import SearchForm
 from haystack.query import SearchQuerySet
 from django import forms
@@ -44,6 +45,22 @@ def save(self, commit=True):
         return profile
 
 
+class UserDeleteForm(forms.ModelForm):
+    username = CharField(label=_('Username'), help_text=_('Please type your username to confirm.'))
+
+    class Meta(object):
+        model = User
+        fields = ['username']
+
+    def clean_username(self):
+        data = self.cleaned_data['username']
+
+        if self.instance.username != data:
+            raise forms.ValidationError(_("Username does not match!"))
+
+        return data
+
+
 class FacetField(forms.MultipleChoiceField):
 
     """
diff --git a/readthedocs/profiles/urls/private.py b/readthedocs/profiles/urls/private.py
--- a/readthedocs/profiles/urls/private.py
+++ b/readthedocs/profiles/urls/private.py
@@ -18,4 +18,5 @@
             'template_name': 'profiles/private/edit_profile.html',
         },
         name='profiles_profile_edit'),
+    url(r'^delete/', views.delete_account, name='delete_account')
 ]
diff --git a/readthedocs/profiles/views.py b/readthedocs/profiles/views.py
--- a/readthedocs/profiles/views.py
+++ b/readthedocs/profiles/views.py
@@ -1,16 +1,21 @@
 """Views for creating, editing and viewing site-specific user profiles."""
 
 from __future__ import absolute_import
+
+from django.contrib import messages
+from django.contrib.auth import logout
 from django.contrib.auth.decorators import login_required
 from django.contrib.auth.models import User
 from django.core.exceptions import ObjectDoesNotExist
 from django.core.urlresolvers import reverse
 from django.http import Http404
 from django.http import HttpResponseRedirect
-from django.shortcuts import get_object_or_404
+from django.shortcuts import get_object_or_404, render, redirect
 from django.shortcuts import render_to_response
 from django.template import RequestContext
 
+from readthedocs.core.forms import UserDeleteForm
+
 
 def create_profile(request, form_class, success_url=None,
                    template_name='profiles/private/create_profile.html',
@@ -183,6 +188,27 @@ def edit_profile(request, form_class, success_url=None,
 edit_profile = login_required(edit_profile)
 
 
+@login_required()
+def delete_account(request):
+    form = UserDeleteForm()
+    template_name = 'profiles/private/delete_account.html'
+
+    if request.method == 'POST':
+        form = UserDeleteForm(instance=request.user, data=request.POST)
+        if form.is_valid():
+
+            # Do not delete the account permanently because it may create disaster
+            # Inactive the user instead.
+            request.user.is_active = False
+            request.user.save()
+            logout(request)
+            messages.info(request, 'You have successfully deleted your account')
+
+            return redirect('homepage')
+
+    return render(request, template_name, {'form': form})
+
+
 def profile_detail(request, username, public_profile_field=None,
                    template_name='profiles/public/profile_detail.html',
                    extra_context=None):


Test patch: