layerindex-web/layerindex/auth_forms.py
Paul Eggleton 2c8f979f9c Implement "delete account" function
Make it possible for users to delete their own account and all associated
information from the database, should they decide they no longer wish to
use it.

(I checked the implications of doing this on our model structure -
anything with a foreign key to user is safe to delete with the exception
of RRS MaintenancePlan.admin which I needed to change on_delete for so
that it doesn't get deleted with the user).

Signed-off-by: Paul Eggleton <paul.eggleton@linux.intel.com>
2018-11-06 11:31:57 +13:00

35 lines
1.4 KiB
Python

# layerindex-web - extended authentication forms
#
# Copyright (C) 2018 Intel Corporation
#
# Licensed under the MIT license, see COPYING.MIT for details
from django import forms
from captcha.fields import CaptchaField
from registration.forms import RegistrationForm
from django.contrib.auth.forms import PasswordResetForm
from django.contrib.auth.models import User
from django.contrib.auth.hashers import check_password
class CaptchaRegistrationForm(RegistrationForm):
captcha = CaptchaField(label='Verification', help_text='Please enter the letters displayed for verification purposes', error_messages={'invalid':'Incorrect entry, please try again'})
class CaptchaPasswordResetForm(PasswordResetForm):
captcha = CaptchaField(label='Verification', help_text='Please enter the letters displayed for verification purposes', error_messages={'invalid':'Incorrect entry, please try again'})
class DeleteAccountForm(forms.ModelForm):
confirm_password = forms.CharField(widget=forms.PasswordInput)
class Meta:
model = User
fields = ('confirm_password', )
def clean(self):
cleaned_data = super(DeleteAccountForm, self).clean()
confirm_password = cleaned_data.get('confirm_password')
if not check_password(confirm_password, self.instance.password):
self.add_error('confirm_password', 'Password does not match.')
return cleaned_data