Merge branch 'Evarin/hotfix_allauth' into 'master'
Hotfix allauth deprecation clipper See merge request klub-dev-ens/experiENS!12
This commit is contained in:
commit
2e92d5aa8a
1 changed files with 38 additions and 1 deletions
|
@ -1,5 +1,6 @@
|
|||
from allauth.account.adapter import DefaultAccountAdapter
|
||||
from allauth_ens.adapter import LongTermClipperAccountAdapter
|
||||
from allauth.socialaccount.models import SocialAccount
|
||||
from allauth_ens.adapter import LongTermClipperAccountAdapter, get_ldap_infos
|
||||
|
||||
class AccountAdapter(DefaultAccountAdapter):
|
||||
def is_open_for_signup(self, request):
|
||||
|
@ -18,3 +19,39 @@ class SocialAccountAdapter(LongTermClipperAccountAdapter):
|
|||
# See https://github.com/pennersr/django-allauth/blob/master/allauth/socialaccount/adapter.py
|
||||
return super().is_open_for_signup(request, sociallogin)
|
||||
|
||||
|
||||
# TODO : HOTFIX pour un bug d'allauth_ens
|
||||
# On remplace la déduplication des comptes faites avec "entrance_year"
|
||||
# par une déduplication sur le nom d'utilisateur
|
||||
# (Copié de allauth_ens)
|
||||
def pre_social_login(self, request, sociallogin):
|
||||
if sociallogin.account.provider != "clipper":
|
||||
return super(LongTermClipperAccountAdapter,
|
||||
self).pre_social_login(request, sociallogin)
|
||||
|
||||
clipper_uid = sociallogin.account.uid
|
||||
try:
|
||||
old_conn = SocialAccount.objects.get(provider='clipper_inactive',
|
||||
uid=clipper_uid)
|
||||
except SocialAccount.DoesNotExist:
|
||||
return
|
||||
|
||||
ldap_data = get_ldap_infos(clipper_uid)
|
||||
sociallogin._ldap_data = ldap_data
|
||||
|
||||
if ldap_data is None or 'entrance_year' not in ldap_data:
|
||||
raise ValueError("No entrance year in LDAP data")
|
||||
|
||||
old_conn_username = old_conn.user.username
|
||||
|
||||
# HOTFIX ICI
|
||||
if self.get_username(clipper_uid, ldap_data) != old_conn_username:
|
||||
email = ldap_data.get('email', get_clipper_email(clipper_uid))
|
||||
remove_email(old_conn.user, email)
|
||||
|
||||
return
|
||||
|
||||
old_conn.provider = 'clipper'
|
||||
old_conn.save()
|
||||
|
||||
sociallogin.lookup()
|
||||
|
|
Loading…
Reference in a new issue