Showing
5 changed files
with
48 additions
and
14 deletions
| 1 | from django.contrib.auth import login, authenticate | 1 | from django.contrib.auth import login, authenticate |
| 2 | from django.contrib.auth.forms import UserCreationForm | 2 | from django.contrib.auth.forms import UserCreationForm |
| 3 | from django.shortcuts import render, redirect | 3 | from django.shortcuts import render, redirect |
| 4 | +from django.contrib.auth.decorators import login_required | ||
| 4 | 5 | ||
| 5 | def signup(request): | 6 | def signup(request): |
| 6 | if request.method == 'POST': | 7 | if request.method == 'POST': |
| ... | @@ -15,3 +16,21 @@ def signup(request): | ... | @@ -15,3 +16,21 @@ def signup(request): |
| 15 | else: | 16 | else: |
| 16 | form = UserCreationForm() | 17 | form = UserCreationForm() |
| 17 | return render(request, 'registration/signup.html', {'form': form}) | 18 | return render(request, 'registration/signup.html', {'form': form}) |
| 19 | + | ||
| 20 | + | ||
| 21 | +@login_required | ||
| 22 | +def delete_account(request): | ||
| 23 | + if request.method == 'GET': | ||
| 24 | + return render(request, 'registration/delete_account.html') | ||
| 25 | + elif request.method == 'POST': | ||
| 26 | + if request.POST.get('yes'): | ||
| 27 | + return redirect('delete_account_success') | ||
| 28 | + else: | ||
| 29 | + return redirect('/') | ||
| 30 | + | ||
| 31 | +@login_required | ||
| 32 | +def delete_account_success(request): | ||
| 33 | + if request.method == 'GET': | ||
| 34 | + # TODO Add delete account | ||
| 35 | + return render(request, 'registration/delete_account_success.html') | ||
| 36 | + | ... | ... |
| 1 | +{% extends "website/baseline.html" %} | ||
| 2 | + | ||
| 3 | +{% block content %} | ||
| 4 | +{% if user.is_authenticated %} | ||
| 5 | +<h1> {{user.username}} really want to delete your account? </h1> | ||
| 6 | +<form action='#' method="POST"> | ||
| 7 | + {% csrf_token %} | ||
| 8 | + <input type="submit" value="yes" name="yes"> | ||
| 9 | + <input type="submit" value="no" name="no"> | ||
| 10 | +</form> | ||
| 11 | +{% endif %} | ||
| 12 | +{% endblock %} | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file |
| 1 | -{% extends 'website/baseline.html' %} | 1 | +{% extends 'website/baseline.html' %} {% block content %} |
| 2 | - | 2 | +<h2>Sign up</h2> |
| 3 | -{% block content %} | 3 | +<form method="post"> |
| 4 | - <h2>Sign up</h2> | 4 | + {% csrf_token %} {% for field in form %} |
| 5 | - <form method="post"> | ||
| 6 | - {% csrf_token %} | ||
| 7 | - {% for field in form %} | ||
| 8 | <p> | 5 | <p> |
| 9 | - {{ field.label_tag }}<br> | 6 | + {{ field.label_tag }} |
| 10 | - {{ field }} | 7 | + <br> {{ field }} {% if field.help_text %} |
| 11 | - {% if field.help_text %} | ||
| 12 | <small style="color: grey">{% autoescape off %}{{ field.help_text }}{% endautoescape %}</small> | 8 | <small style="color: grey">{% autoescape off %}{{ field.help_text }}{% endautoescape %}</small> |
| 13 | - {% endif %} | 9 | + {% endif %} {% for error in field.errors %} |
| 14 | - {% for error in field.errors %} | ||
| 15 | <p style="color: red">{{ error }}</p> | 10 | <p style="color: red">{{ error }}</p> |
| 16 | {% endfor %} | 11 | {% endfor %} |
| 17 | </p> | 12 | </p> |
| 18 | {% endfor %} | 13 | {% endfor %} |
| 19 | <button type="submit">Sign up</button> | 14 | <button type="submit">Sign up</button> |
| 20 | - </form> | 15 | +</form> |
| 21 | {% endblock %} | 16 | {% endblock %} |
| ... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
| ... | @@ -11,5 +11,7 @@ urlpatterns = [ | ... | @@ -11,5 +11,7 @@ urlpatterns = [ |
| 11 | url(r'^post/(?P<pk>\d+)/publish/$', views.post_publish, name='post_publish'), | 11 | url(r'^post/(?P<pk>\d+)/publish/$', views.post_publish, name='post_publish'), |
| 12 | 12 | ||
| 13 | url(r'^files/', views.file_list, name='file_list'), | 13 | url(r'^files/', views.file_list, name='file_list'), |
| 14 | - url(r'^signup/$', auth_views.signup, name='signup'), | 14 | + url(r'^accounts/signup/$', auth_views.signup, name='signup'), |
| 15 | + url(r'^accounts/delete_account/$', auth_views.delete_account, name='delete_account'), | ||
| 16 | + url(r'^accounts/delete_account_success/$', auth_views.delete_account_success, name='delete_account_success'), | ||
| 15 | ] | 17 | ] |
| ... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
-
Please register or login to post a comment