Currently, I have a user model that can access account related information based on its session. I am using the django auth PasswordResetView. The password reset form is used to reset password if the user has forgotten his/her password. But this Django view is also accessed by the user when he is already logged in.
How can I restrict the user to access this page? I cannot find solution for this problem, since it's a total abstraction and nothing is present in my views.py file.
This is how my urls.py file looks like :
from django.contrib import admin
from django.urls import path, include
from django.contrib.auth import views as auth_views
from users import views as user_views
from django.conf import settings
from django.conf.urls.static import static
urlpatterns = [
path('admin/', admin.site.urls),
path('', include('mainapp.urls')),
path('login/', auth_views.LoginView.as_view(template_name='users/login.html'), name="login"),
path('logout/', auth_views.LogoutView.as_view(template_name='users/logout.html'), name="logout"),
path('password_reset/', auth_views.PasswordResetView.as_view(template_name='users/password_reset.html'), name="password_reset"),
path('password_reset/done/', auth_views.PasswordResetDoneView.as_view(template_name='users/password_reset_done.html'), name="password_reset_done"),
path('password_reset_confirm/<uidb64>/<token>', auth_views.PasswordResetConfirmView.as_view(template_name='users/password_reset_confirm.html'), name="password_reset_confirm"),
path('password_reset_complete/', auth_views.PasswordResetCompleteView.as_view(template_name='users/password_reset_complete.html'), name="password_reset_complete"),
path('change_password/', auth_views.PasswordChangeView.as_view(template_name='users/change_password.html', success_url="/"), name="password_change"),
# path('password_change_done/done/', auth_views.PasswordChangeDoneView.as_view(template_name='users/password_change_done.html'), name="password_change_done"),
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
A logged in user should not be able to access password_reset_form since it is only meant when the password is forgotten and when the user is already logged in, it does not make sense for the user to access password_reset.html.