Commit 407cb3f2 authored by Alexander Eyl's avatar Alexander Eyl

Add new functionality: user can delete himself.

parent 80d1a88d
......@@ -5,6 +5,7 @@ from app.models import RuleRegExpression
import re
from django.forms import ValidationError
from django.forms.models import BaseInlineFormSet
from django.core import validators
class SignupForm(UserCreationForm):
......@@ -19,6 +20,29 @@ class ProfileForm(forms.ModelForm):
model = User
fields = ('username','email')
class DeleteUserForm(forms.Form):
#stuff
username = forms.CharField(
max_length=100,
label='Gib deinen Benutzernamen ein, um die Accountlöschung zu verifizieren.',
widget=forms.TextInput(attrs={'placeholder': 'Benutzername'})
)
actual_username = ''
def __init__(self, actual_username,*args, **kwargs):
self.actual_username = actual_username
super(DeleteUserForm,self).__init__(*args,**kwargs)
def clean_username(self):
if self.cleaned_data['username'] != self.actual_username:
raise forms.ValidationError("Dein Benutzername ist: '" + self.actual_username + "', du hast stattdessen '" + self.cleaned_data['username']
+ "' eingegeben. Bitte korrigiere deine Eingabe, wenn du deinen Account wirklich löschen möchtest." )
class RuleRegExpressionForm(forms.ModelForm):
message = forms.CharField(max_length=200)
code = forms.CharField(max_length=500,widget=forms.Textarea)
......
from django.shortcuts import render_to_response, redirect, render, get_object_or_404, HttpResponse
from app.forms import SignupForm, ProfileForm, RuleRegExpressionForm,CustomCSSForm
from app.forms import SignupForm, ProfileForm, RuleRegExpressionForm,CustomCSSForm, DeleteUserForm
from django.contrib.auth import login, authenticate, logout, update_session_auth_hash
from django.contrib.auth.decorators import login_required
from django.contrib.auth.decorators import login_required, user_passes_test
from django.db import transaction
from django.contrib import messages
from django.contrib.auth.forms import PasswordChangeForm
......@@ -12,7 +12,9 @@ from app import cleaner
import django.core.management as management
import koja.settings as settings
import os,zipfile,io
#test for userdeletion request output
from django.http import JsonResponse
from django import forms
# def login_user(request):
# logout(request)
......@@ -42,7 +44,7 @@ def logout_view(request):
logout(request)
return render_to_response('account/logout.html')
#@user_passes_test(lambda u: u.is_anonymous)
def signup(request):
if request.method == 'POST':
form = SignupForm(request.POST)
......@@ -93,6 +95,28 @@ def change_password(request):
})
@login_required
@transaction.atomic
def delete_account(request):
if request.method == 'POST':
form = DeleteUserForm(request.user.username, request.POST)
if form.is_valid():
request.user.delete()
return redirect('account_deleted')
return render(request, 'account/delete_current_user.html', {
'form' : form
})
form = DeleteUserForm(request.user.username)
return render(request, 'account/delete_current_user.html', {
'form' : form
})
### Begin App Code
......@@ -382,6 +406,7 @@ def custom_css_view(request):
return render(request, 'app/custom_css.html', {'form': form,})
#@user_passes_test(lambda u: u.is_anonymous)
def user_successfully_deleted(request):
return render(request,'account/user_successfully_deleted.html')
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment