신은섭(Shin Eun Seop)

add account delete

from django.contrib.auth import login, authenticate
from django.contrib.auth.forms import UserCreationForm
from django.shortcuts import render, redirect
from django.contrib.auth.decorators import login_required
def signup(request):
if request.method == 'POST':
......@@ -15,3 +16,21 @@ def signup(request):
else:
form = UserCreationForm()
return render(request, 'registration/signup.html', {'form': form})
@login_required
def delete_account(request):
if request.method == 'GET':
return render(request, 'registration/delete_account.html')
elif request.method == 'POST':
if request.POST.get('yes'):
return redirect('delete_account_success')
else:
return redirect('/')
@login_required
def delete_account_success(request):
if request.method == 'GET':
# TODO Add delete account
return render(request, 'registration/delete_account_success.html')
......
{% extends "website/baseline.html" %}
{% block content %}
{% if user.is_authenticated %}
<h1> {{user.username}} really want to delete your account? </h1>
<form action='#' method="POST">
{% csrf_token %}
<input type="submit" value="yes" name="yes">
<input type="submit" value="no" name="no">
</form>
{% endif %}
{% endblock %}
\ No newline at end of file
{% extends "website/baseline.html" %}
{% block content %}
<h1>DELTED</h1>
<!--TODO logout -->
{% endblock %}
\ No newline at end of file
{% extends 'website/baseline.html' %}
{% block content %}
<h2>Sign up</h2>
<form method="post">
{% csrf_token %}
{% for field in form %}
<p>
{{ field.label_tag }}<br>
{{ field }}
{% if field.help_text %}
<small style="color: grey">{% autoescape off %}{{ field.help_text }}{% endautoescape %}</small>
{% endif %}
{% for error in field.errors %}
<p style="color: red">{{ error }}</p>
{% endfor %}
</p>
{% extends 'website/baseline.html' %} {% block content %}
<h2>Sign up</h2>
<form method="post">
{% csrf_token %} {% for field in form %}
<p>
{{ field.label_tag }}
<br> {{ field }} {% if field.help_text %}
<small style="color: grey">{% autoescape off %}{{ field.help_text }}{% endautoescape %}</small>
{% endif %} {% for error in field.errors %}
<p style="color: red">{{ error }}</p>
{% endfor %}
<button type="submit">Sign up</button>
</form>
</p>
{% endfor %}
<button type="submit">Sign up</button>
</form>
{% endblock %}
\ No newline at end of file
......
......@@ -11,5 +11,7 @@ urlpatterns = [
url(r'^post/(?P<pk>\d+)/publish/$', views.post_publish, name='post_publish'),
url(r'^files/', views.file_list, name='file_list'),
url(r'^signup/$', auth_views.signup, name='signup'),
url(r'^accounts/signup/$', auth_views.signup, name='signup'),
url(r'^accounts/delete_account/$', auth_views.delete_account, name='delete_account'),
url(r'^accounts/delete_account_success/$', auth_views.delete_account_success, name='delete_account_success'),
]
\ No newline at end of file
......