Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"Refresh" Django session variables to avoid session timeouts?

I have a multi-page Django signup process in which a user goes through the following steps:

  1. Create an account (username, password)
  2. Create a profile
  3. Upload a photo
  4. Review and approve/change profile and photo
  5. Pass username and user ID to payment processor
  6. Receive "Payment OK or Payment not OK" signal from payment processor
  7. Log user in if "Payment OK" and display website's "home" page.

In step 1 above, the user's ID and a couple of other pieces of information are stored in a session. They're then examined when necessary during steps 2 through 4. The user ID and username will also be passed to the payment processor in step 5. I'm thinking of setting the session timeout period to either 30 minutes or an hour. Here's my question. Should I read and re-assign the session variables when the user GETs each of the above pages in order to help the user avoid having their session timed out? The Django documentation says Django only saves a session when the session has been modified (i.e. when any of the dictionary values have been assigned or deleted). I'm thinking that if I "refresh" the user's session as they move from page to page, it will be less likely that they'll be timed out and will thus experience a smoother signup process.

Any advice? Thanks.

like image 256
Jim Avatar asked Mar 21 '23 00:03

Jim


1 Answers

There's SESSION_SAVE_EVERY_REQUEST setting that saves session and sends session cookie with every request, effectively turning session into sliding expiration session (btw, it's a widespread name for what you want to achieve)

Refer to session docs for details

like image 150
J0HN Avatar answered Apr 01 '23 15:04

J0HN