From 13c7359294c6fffaacba65cf9ff35683274caac3 Mon Sep 17 00:00:00 2001 From: Valentin Samir Date: Mon, 1 Aug 2016 02:07:50 +0200 Subject: [PATCH] Remember warn using a cookie --- cas_server/forms.py | 4 ++-- cas_server/views.py | 16 ++++++++++++++-- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/cas_server/forms.py b/cas_server/forms.py index b0d8ad4..c7b2d76 100644 --- a/cas_server/forms.py +++ b/cas_server/forms.py @@ -87,13 +87,13 @@ class FederateSelect(BaseLogin): to_field_name="suffix", label=_('Identity provider'), ) - #: A checkbox to remember the user choices of :attr:`provider` - remember = forms.BooleanField(label=_('Remember the identity provider'), required=False) #: A checkbox to ask to be warn before emiting a ticket for another service warn = forms.BooleanField( label=_('Warn me before logging me into other sites.'), required=False ) + #: A checkbox to remember the user choices of :attr:`provider` + remember = forms.BooleanField(label=_('Remember the identity provider'), required=False) class UserCredential(BaseLogin): diff --git a/cas_server/views.py b/cas_server/views.py index 54fec53..b6a8e5f 100644 --- a/cas_server/views.py +++ b/cas_server/views.py @@ -498,7 +498,17 @@ class LoginView(View, LogoutMixin): else: # pragma: no cover (should no happen) raise EnvironmentError("invalid output for LoginView.process_post") # call the GET/POST common part - return self.common() + response = self.common() + if self.warn: + utils.set_cookie( + response, + "warn", + "on", + 10 * 365 * 24 * 3600 + ) + else: + response.delete_cookie("warn") + return response def process_post(self): """ @@ -607,7 +617,9 @@ class LoginView(View, LogoutMixin): form_initial = { 'service': self.service, 'method': self.method, - 'warn': self.warn or self.request.session.get("warn"), + 'warn': ( + self.warn or self.request.session.get("warn") or self.request.COOKIES.get('warn') + ), 'lt': self.request.session['lt'][-1], 'renew': self.renew }