Re: retain form data when a user session expires while filling a form

2018-04-13 Thread Avraham Serour
You may also always save to cookie before submitting the form and clear it
on the thank you page

On Thu, 12 Apr 2018, 14:20 Vijay Shanker,  wrote:

> I have to code this scenario:
>
> Some user comes to fill a form and while user is at it, session expires;
> User tries to submit form, as session has expired it will take him to login
> page after which he is rediredted to form page with a prefilled form with
> data he filled previously.
>
> my propsed solution: on form submit, check if user session is expired with
> an ajax call, if yes, drop a cookie with values of filled form, user comes
> back to same form, prefill the form from cookie value.
>
> how far I got: not much; I used ajax call to check session expiry with a
> backend call to this function:
>
> def check_valid_session(request):
> session_expiry_date = request.session.get_expiry_date()
> now = datetime.now()
> seconds_left = (session_expiry_date - now).total_seconds()
> if seconds_left <= 0:
> return JsonResponse({'session_expired': True, 'seconds_left': 
> seconds_left })
> else:
> return JsonResponse({'session_expired':False, 'seconds_left': 
> seconds_left})
>
> in my settings I have:
>
> SESSION_COOKIE_NAME = "sso-sessionid"
> SESSION_COOKIE_HTTPONLY = False
> SESSION_COOKIE_AGE = 10
> SESSION_COOKIE_DOMAIN = '.mydomain.com'
> SESSION_COOKIE_SECURE = True
> SESSION_EXPIRE_AT_BROWSER_CLOSE = True
>
> but in response, I always get seconds_left as something close to 9.999.
> and session_expiry_date keeps increasing itself by 10 seconds each time i
> hit submit and call the backend code above. How to get correct session
> expire time?
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/e623b707-2014-4511-91f4-7a00420fe196%40googlegroups.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAFWa6tLyCywv3sZn%3D2ch9fdrxBLv-PCRdqPS3CK5ioiimypobg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


retain form data when a user session expires while filling a form

2018-04-12 Thread Vijay Shanker


I have to code this scenario:

Some user comes to fill a form and while user is at it, session expires; 
User tries to submit form, as session has expired it will take him to login 
page after which he is rediredted to form page with a prefilled form with 
data he filled previously.

my propsed solution: on form submit, check if user session is expired with 
an ajax call, if yes, drop a cookie with values of filled form, user comes 
back to same form, prefill the form from cookie value.

how far I got: not much; I used ajax call to check session expiry with a 
backend call to this function:

def check_valid_session(request):
session_expiry_date = request.session.get_expiry_date()
now = datetime.now()
seconds_left = (session_expiry_date - now).total_seconds()
if seconds_left <= 0:
return JsonResponse({'session_expired': True, 'seconds_left': 
seconds_left })
else:
return JsonResponse({'session_expired':False, 'seconds_left': 
seconds_left})

in my settings I have:

SESSION_COOKIE_NAME = "sso-sessionid"
SESSION_COOKIE_HTTPONLY = False
SESSION_COOKIE_AGE = 10 
SESSION_COOKIE_DOMAIN = '.mydomain.com'
SESSION_COOKIE_SECURE = True
SESSION_EXPIRE_AT_BROWSER_CLOSE = True

but in response, I always get seconds_left as something close to 9.999. and 
session_expiry_date keeps increasing itself by 10 seconds each time i hit 
submit and call the backend code above. How to get correct session expire 
time?

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/e623b707-2014-4511-91f4-7a00420fe196%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.