Skip to content

Commit

Permalink
master pssword is required before deleteing account
Browse files Browse the repository at this point in the history
  • Loading branch information
Shane committed Jan 21, 2021
1 parent 4b37b44 commit 2fddedb
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 20 deletions.
Binary file modified users/__pycache__/views.cpython-39.pyc
Binary file not shown.
27 changes: 16 additions & 11 deletions users/templates/users/account.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@
{% endblock title %}
{%block content%}
{% for message in messages %}
{{message}}
<div class="div-container">
<h1>{{message}}</h1>
</div>
<br />
<br />
{% endfor %}
<div class = "div-container" style = "background-color: #c0bdbd; width: 75%;">
<div class = "div-container" style = "box-shadow:none">
Expand All @@ -28,28 +32,29 @@ <h1 class = "main-color" style="display:inline; position: relative;text-align: l
</div>
<br />
<br />
<div class = "div-container" style = "box-shadow:none;">
<h1 style="text-align: center; font-size:30px; color: #9c0b0b"><a class='hover-color' href = "{% url 'delete' %}">Delete Account</a></h1>
</div>
<br />
<br />
<div>
<input style = "background-color: red; width: 54%"type="submit" value="Submit">
</div>
<div class="div-container" style="box-shadow: none; width=50%">
<form method = "POST">
{% csrf_token %}
<h2 class = "main-color">Change Master Password</h2>

<p1 style="float: left">Master Password:</p1>
<input type="password" name = "password_field" name="Password">
<input type="password" name = "password_field">

<p1 style="float: left">New Password:</p1>
<input type="password" name = "new_password" name="Password">
<input type="password" name = "new_password">

<input type="submit" value="Submit">
</form>
</div>
<br />
<br />
<div class = "div-container" style = "box-shadow:none; width:25%">

<p1 style="text-align: center; font-size:30px; color: #9c0b0b"><a class='hover-color' href = "{% url 'delete' %}">Delete Account</a></p1>

</div>
<br />
<br />
</div>

{%endblock content%}
27 changes: 18 additions & 9 deletions users/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,24 @@ def register(request):

@login_required
def delete_account(request):
username = request.user
user = User.objects.get(username = username)
user.delete()
messages.success(request, f""" "{user}" Has Been Deleted""")
if request.method == 'POST':
form_master_password = request.POST.get("master_password")
user_password = request.user.password
if check_password(form_master_password, user_password):
username = request.user
user = User.objects.get(username = username)
user.delete()
messages.success(request, f""" "{user}" Has Been Deleted""")

form = UserRegisterForm()
context = {
"form": form,
}
form = UserRegisterForm()
context = {
"form": form,
}

return render(request, "users/register.html", context)
return render(request, "users/register.html", context)
else:
messages.error(request, "Invalid Password")
return render(request, "users/delete_account.html")
else:
return render(request, "users/delete_account.html")

0 comments on commit 2fddedb

Please sign in to comment.