diff options
author | Dominic DiTaranto <domdit@gmail.com> | 2024-10-29 12:04:25 -0400 |
---|---|---|
committer | Dominic DiTaranto <domdit@gmail.com> | 2024-10-29 12:04:25 -0400 |
commit | d775089ad63f271679b609828c0cdcf6b354d715 (patch) | |
tree | 99772976cf1464a919ffaafba04246f119df48c0 | |
parent | b30da975af9a01e8c4a31c784a422272033fc87f (diff) |
password changepassword-change
-rw-r--r-- | korabo/urls.py | 2 | ||||
-rw-r--r-- | web/templates/base.html | 1 | ||||
-rw-r--r-- | web/templates/change-password/change_password.html | 12 | ||||
-rw-r--r-- | web/templates/change-password/password_change_done.html | 7 | ||||
-rw-r--r-- | web/views.py | 24 |
5 files changed, 43 insertions, 3 deletions
diff --git a/korabo/urls.py b/korabo/urls.py index fbbfded..dfa6079 100644 --- a/korabo/urls.py +++ b/korabo/urls.py @@ -23,4 +23,6 @@ urlpatterns = [ path('admin/', admin.site.urls), path("", views.index, name="index"), path("event/<int:event_id>", views.event, name="event"), + path('change_password/', views.change_password, name='change_password'), + path('password_change_done/', views.password_change_done, name='password_change_done') ] diff --git a/web/templates/base.html b/web/templates/base.html index d6ba2da..b5bc4a3 100644 --- a/web/templates/base.html +++ b/web/templates/base.html @@ -19,6 +19,7 @@ </div> <div style="float:right;"> <a href="{% url 'index' %}">home</a> | + <a href="{% url 'change_password' %}">change password</a> | <a href="{% url 'logout' %}">logout</a> </div> diff --git a/web/templates/change-password/change_password.html b/web/templates/change-password/change_password.html new file mode 100644 index 0000000..d29c901 --- /dev/null +++ b/web/templates/change-password/change_password.html @@ -0,0 +1,12 @@ +{% extends "base.html" %} + +{% block title %}Change Password{% endblock %} + +{% block content %} + <h2>Change Password</h2> + <form method="post"> + {% csrf_token %} + {{ form.as_p }} + <button type="submit">Change Password</button> + </form> +{% endblock %}
\ No newline at end of file diff --git a/web/templates/change-password/password_change_done.html b/web/templates/change-password/password_change_done.html new file mode 100644 index 0000000..d173329 --- /dev/null +++ b/web/templates/change-password/password_change_done.html @@ -0,0 +1,7 @@ +{% extends "base.html" %} + +{% block title %}Change Password{% endblock %} + +{% block content %} +Success! +{% endblock %}
\ No newline at end of file diff --git a/web/views.py b/web/views.py index cc537c4..0009739 100644 --- a/web/views.py +++ b/web/views.py @@ -1,8 +1,11 @@ -from django.shortcuts import render -from web.models import Event, Availability -from django.shortcuts import get_object_or_404, redirect from datetime import timedelta +from django.contrib.auth import update_session_auth_hash from django.contrib.auth.decorators import login_required +from django.contrib.auth.forms import PasswordChangeForm +from django.contrib.auth.views import PasswordChangeView +from django.shortcuts import get_object_or_404, redirect, render +from django.urls import reverse_lazy +from web.models import Event, Availability @login_required() @@ -27,6 +30,21 @@ def index(request): return render(request, "index.html", context) +def change_password(request): + if request.method == 'POST': + form = PasswordChangeForm(request.user, request.POST) + if form.is_valid(): + user = form.save() + update_session_auth_hash(request, user) + return redirect('password_change_done') + else: + form = PasswordChangeForm(request.user) + return render(request, 'change-password/change_password.html', {'form': form}) + +def password_change_done(request): + return render(request, 'change-password/password_change_done.html') + + @login_required() def event(request, event_id): |