Skip to content

Commit

Permalink
Merge pull request #311 from whitesmith/connect-social
Browse files Browse the repository at this point in the history
Connect social account when email exists
  • Loading branch information
dethos authored Dec 9, 2020
2 parents e246310 + c711f34 commit 3a7210b
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
2 changes: 2 additions & 0 deletions hawkpost/settings/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,8 @@
}
}

SOCIALACCOUNT_ADAPTER = 'humans.adapter.SocialAccountAdapter'

# Authentication Limits Config (AXES)
AXES_FAILURE_LIMIT = 5
AXES_COOLOFF_TIME = 1 # hour
Expand Down
2 changes: 1 addition & 1 deletion hawkpost/templates/account/verified_email_required.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<section class="text-lightest">
<div class="row center-xs center-sm">
<div class="col-offset-xs-1 col-xs-10 col-offset-sm-2 col-xs-8">
<h1 class="title text-lightest">{{% trans "VERIFY YOUR E-MAIL ADDRESS" %}</h1>
<h1 class="title text-lightest">{% trans "VERIFY YOUR E-MAIL ADDRESS" %}</h1>

{% url 'account_email' as email_url %}

Expand Down
14 changes: 14 additions & 0 deletions humans/adapter.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from allauth.account.models import EmailAddress
from allauth.socialaccount.adapter import DefaultSocialAccountAdapter

class SocialAccountAdapter(DefaultSocialAccountAdapter):
def pre_social_login(self, request, sociallogin):
if sociallogin.is_existing:
return

try:
email = EmailAddress.objects.get(email=sociallogin.user.email)
except EmailAddress.DoesNotExist:
return

sociallogin.connect(request, email.user)

0 comments on commit 3a7210b

Please sign in to comment.