Commit c4a9a323 authored by Volkov Gherman's avatar Volkov Gherman

исправил ошибки смены пароля

parent e15d7152
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
{% block content %} {% block content %}
<div class="log"> <div class="log">
<form action="{% url 'accounts:password_change_done' request.user.pk %}" method="post"> <form action="{% url 'accounts:change_password' request.user.pk %}" method="post">
{% csrf_token %} {% csrf_token %}
{{ form|crispy }} {{ form|crispy }}
<button class="btn btn-outline-dark log_btn" type="submit">Change</button> <button class="btn btn-outline-dark log_btn" type="submit">Change</button>
......
from django.contrib.auth.views import LoginView, LogoutView, PasswordChangeView from django.contrib.auth.views import LoginView, LogoutView, PasswordChangeView
from django.urls import path, reverse_lazy from django.urls import path, reverse_lazy
from accounts.views import RegisterView from accounts.views import RegisterView, ChangePasswordView
app_name = "accounts" app_name = "accounts"
...@@ -9,5 +9,5 @@ urlpatterns = [ ...@@ -9,5 +9,5 @@ urlpatterns = [
path("account/login/", LoginView.as_view(), name="login"), path("account/login/", LoginView.as_view(), name="login"),
path("account/logout/", LogoutView.as_view(), name="logout"), path("account/logout/", LogoutView.as_view(), name="logout"),
path("account/registration/", RegisterView.as_view(), name="register"), path("account/registration/", RegisterView.as_view(), name="register"),
path("account/<int:pk>/change_password", PasswordChangeView.as_view(success_url=reverse_lazy('accounts:password_change_done')), name="password_change_done"), path("account/<int:pk>/change_password/", ChangePasswordView.as_view(), name="change_password"),
] ]
from django.contrib.auth import get_user_model, login from django.contrib.auth import get_user_model, login
from django.contrib.auth.views import PasswordChangeView
from django.shortcuts import redirect from django.shortcuts import redirect
from django.urls import reverse_lazy from django.urls import reverse_lazy
from django.views.generic import CreateView from django.views.generic import CreateView
...@@ -17,3 +18,8 @@ class RegisterView(CreateView): ...@@ -17,3 +18,8 @@ class RegisterView(CreateView):
login(self.request, user) login(self.request, user)
return redirect("webapp:index") return redirect("webapp:index")
class ChangePasswordView(PasswordChangeView):
template_name = 'registration/password_change.html'
success_url = reverse_lazy('webapp:index')
No preview for this file type
...@@ -33,7 +33,7 @@ ...@@ -33,7 +33,7 @@
{% if request.user.is_superuser %} {% if request.user.is_superuser %}
<a style="margin-right: 10px;" href="{% url "webapp:post_create" %}" class="text-dark" title="Add post"><i class="bi bi-file-plus icon"></i></a> <a style="margin-right: 10px;" href="{% url "webapp:post_create" %}" class="text-dark" title="Add post"><i class="bi bi-file-plus icon"></i></a>
{% endif %} {% endif %}
<a style="margin-right: 10px;" href="{% url "accounts:password_change_done" request.user.pk %}" class="text-dark" title="Change password"><i class="bi bi-pencil icon"></i></a> <a style="margin-right: 10px;" href="{% url "accounts:change_password" request.user.pk %}" class="text-dark" title="Change password"><i class="bi bi-pencil icon"></i></a>
</div> </div>
{% else %} {% else %}
<div class="link_anon d-flex justify-content-between reg_cont"> <div class="link_anon d-flex justify-content-between reg_cont">
......
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