Fix non-CAS users case
This commit is contained in:
parent
c3d6e2b144
commit
89cb540f02
2 changed files with 31 additions and 13 deletions
|
@ -166,10 +166,17 @@ class GenericLoginViewTests(TestCase):
|
|||
self.client.login(username="team", password="team")
|
||||
|
||||
r = self.client.post(self.url)
|
||||
|
||||
profile = getattr(self.user, "profile", None)
|
||||
if profile and profile.login_clipper:
|
||||
self.assertRedirects(
|
||||
r,
|
||||
"https://cas.eleves.ens.fr/logout?service=http%3A%2F%2Ftestserver%2Fk-fet%2Flogin%2Fgeneric",
|
||||
"https://cas.eleves.ens.fr/logout?service={}".format(self.url),
|
||||
fetch_redirect_response=False,
|
||||
)
|
||||
else:
|
||||
self.assertRedirects(
|
||||
r,
|
||||
"/logout?next=http%3A%2F%2Ftestserver{}".format(self.url),
|
||||
fetch_redirect_response=False,
|
||||
)
|
||||
|
||||
|
|
|
@ -72,15 +72,26 @@ class GenericLoginView(View):
|
|||
# which is why the CAS logout URL with callback is constructed ad hoc,
|
||||
# without relying on Django redirection to Django CAS.
|
||||
|
||||
generic_login_url = request.build_absolute_uri() # preserves next parameter
|
||||
here_url = request.build_absolute_uri() # preserves next parameter
|
||||
profile = getattr(request.user, "profile", None)
|
||||
|
||||
if profile and profile.login_clipper:
|
||||
generic_login_url = here_url
|
||||
generic_login_qd = QueryDict(mutable=True)
|
||||
generic_login_qd["service"] = generic_login_url
|
||||
|
||||
cas_server_url = django_settings.CAS_SERVER_URL
|
||||
cas_logout_url = cas_server_url + "logout"
|
||||
cas_callback_url = cas_logout_url + "?{}".format(generic_login_qd.urlencode())
|
||||
cas_callback_url = cas_logout_url + "?{}".format(
|
||||
generic_login_qd.urlencode()
|
||||
)
|
||||
|
||||
logout_url = cas_callback_url
|
||||
else:
|
||||
logout_url = reverse("cof-logout")
|
||||
logout_qd = QueryDict(mutable=True)
|
||||
logout_qd["next"] = here_url
|
||||
logout_url += "?{}".format(logout_qd.urlencode(safe="/"))
|
||||
|
||||
resp = redirect(logout_url)
|
||||
resp.set_signed_cookie(self.TOKEN_COOKIE_NAME, token.token, httponly=True)
|
||||
|
|
Loading…
Reference in a new issue