add support for service slugs on login

This commit is contained in:
Benjamin Dauvergne 2018-01-22 11:54:28 +01:00
parent a0bc944e84
commit 298c7faca7
1 changed files with 4 additions and 3 deletions

View File

@ -24,7 +24,7 @@ from django.core.urlresolvers import reverse
from django.forms import Form
from authentic2 import app_settings as a2_app_settings
from authentic2 import utils as a2_utils, hooks
from authentic2 import utils as a2_utils, hooks, constants
from authentic2.a2_rbac.utils import get_default_ou
from . import app_settings, models, utils
@ -324,6 +324,7 @@ class LoginOrLinkView(PopupViewMixin, FcOAuthSessionViewMixin, View):
def get(self, request, *args, **kwargs):
registration = True if 'registration' in request.GET else False
'''Request an access grant code and associate it to the current user'''
self.service_slug = request.GET.get(constants.SERVICE_FIELD_NAME)
if request.user.is_authenticated():
# Prevent to add a link with an FC account already linked with another user.
try:
@ -406,10 +407,10 @@ class LoginOrLinkView(PopupViewMixin, FcOAuthSessionViewMixin, View):
u'%s, logging anyway',
email, user.fc_accounts.values_list('sub', flat=True))
# login the user anyway, but do not update its user_info, it's not ideal
a2_utils.simulate_login(user, 'france-connect')
a2_utils.simulate_login(user, 'france-connect', service_slug=self.service_slug)
return self.redirect(request)
if user:
a2_utils.login(request, user, 'france-connect')
a2_utils.login(request, user, 'france-connect', service_slug=self.service_slug)
self.fc_account = models.FcAccount.objects.get(sub=self.sub, user=user)
self.fc_account.token = json.dumps(self.token)
self.fc_account.save(update_fields=['token'])