views: do not permit linking if the user has already a link to FC (#20078)

This commit is contained in:
Benjamin Dauvergne 2017-11-14 11:37:10 +01:00
parent e9b7ed137a
commit a671f6c97c
1 changed files with 8 additions and 1 deletions

View File

@ -338,7 +338,14 @@ class LoginOrLinkView(PopupViewMixin, FcOAuthSessionViewMixin, View):
except models.FcAccount.DoesNotExist:
pass
# Old link are deleted
# Prevent to add a link to an user which is already linked to an FC account
if request.user.fc_accounts.exists():
self.logger.warning(u'cannot link to sub %s, account is already linked to an '
u'FC account', self.sub)
messages.error(request,
_('Your account is already linked to a FranceConnect account'))
return self.redirect(request)
json_token = json.dumps(self.token)
self.fc_account, created = models.FcAccount.objects.get_or_create(
defaults={'token': json_token},