django-bootstrap-modal-forms icon indicating copy to clipboard operation
django-bootstrap-modal-forms copied to clipboard

issue when need to authenticate (after a session expires)

Open sdementen opened this issue 5 years ago • 2 comments

I have a case where my session expire after a modal form is active.

When I click on the action button, it calls the URL and it triggers the redirects to login and there it fails,

image

If I log directly on the page from the browser I see

image

My uneducated guess it that the request is done in xhr/ajax vs plain call.

Would you know how to fix this ?

sdementen avatar Mar 23 '20 11:03 sdementen

@sdementen Sorry, I don't understand exactly what you are asking. Please try to explain better and provide me an information how to replicate the issue.

trco avatar Mar 25 '20 09:03 trco

sorry for not being clear, I try to rephrase based on your example application. In your example, protect the create_book view behind a login_required

urlpatterns = [
    path('', views.Index.as_view(), name='index'),
    path('create/', login_required(views.BookCreateView.as_view()), name='create_book'),
    path('update/<int:pk>', views.BookUpdateView.as_view(), name='update_book'),
    path('read/<int:pk>', views.BookReadView.as_view(), name='read_book'),
    path('delete/<int:pk>', views.BookDeleteView.as_view(), name='delete_book'),
    path('signup/', views.SignUpView.as_view(), name='signup'),
    path('login/', views.CustomLoginView.as_view(), name='login'),
]

and add in the settings.py use as login URL an external page that would simulate a login page (i.e. do not use the modal login view you propose). LOGIN_URL = "https://myaccount.google.com/"

As you are not logged in the website per default, any call to create_book will redirect to the login page (which is not BSModal compatible). Hence, if you click on "Create book", you will see image and the modal form will not appear (nor an error message).

as there is a redirect due to login that do not accept "xhr" (and that cannot go in the Modal form anyway).

In my case, I have all the pages that are behind login_required so I do not have the problem except when the session expires. Then, the next call will be redirected to the login page. And if the next call is the one of BSModal, I have the problem described here above.

I am not sure of the kind of solution that could be used... :

  • if a redirect is detected when calling a modal form => redirect the full page ?
  • if an error happens when calling a modal form => display a customised error message ?

Is it clearer now ?

sdementen avatar Mar 26 '20 11:03 sdementen