Remember warn using a cookie

This commit is contained in:
Valentin Samir 2016-08-01 02:07:50 +02:00
parent aae3a0186e
commit 13c7359294
2 changed files with 16 additions and 4 deletions

View File

@ -87,13 +87,13 @@ class FederateSelect(BaseLogin):
to_field_name="suffix",
label=_('Identity provider'),
)
#: A checkbox to remember the user choices of :attr:`provider<FederateSelect.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<FederateSelect.provider>`
remember = forms.BooleanField(label=_('Remember the identity provider'), required=False)
class UserCredential(BaseLogin):

View File

@ -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
}