Django allauth login with google account
Tag : api , By : n1ckless_id
Date : March 29 2020, 07:55 AM
around this issue You have configured a HTTPS redirect URI, whereas your Django app is using HTTP URIs. Either add http://tutor.herokuapp.com/accounts/google/login/callback over at the Google API console, or use HTTPS for your Django project.
|
django-allauth social account connect to existing account on login
Tag : python , By : lifchicker
Date : March 29 2020, 07:55 AM
it helps some times I managed to get this working by changing the code for adapter a little bit. adapter.py from allauth.socialaccount.adapter import DefaultSocialAccountAdapter
class MySocialAccountAdapter(DefaultSocialAccountAdapter):
def pre_social_login(self, request, sociallogin):
user = sociallogin.user
if user.id:
return
try:
customer = Customer.objects.get(email=user.email) # if user exists, connect the account to the existing account and login
sociallogin.state['process'] = 'connect'
perform_login(request, customer, 'none')
except Customer.DoesNotExist:
pass
|
How to allow user to delete account in django allauth?
Date : March 29 2020, 07:55 AM
hope this fix your issue For issue 1, over-ride the help-text attribute of this field; you can do that in your ModelForm's init method. class DeactivateUserForm(forms.ModelForm):
class Meta:
model = User
fields = ['is_active']
def __init__(self, *args, **kwargs):
super(DeactivateUserForm, self).__init__(*args, **kwargs)
self.fields['is_active'].help_text = "Check this box if you are sure you want to delete this account."
def clean_is_active(self):
# Reverses true/false for your form prior to validation
#
# You can also raise a ValidationError here if you receive
# a value you don't want, to prevent the form's is_valid
# method from return true if, say, the user hasn't chosen
# to deactivate their account
is_active = not(self.cleaned_data["is_active"])
return is_active
ACCOUNT_LOGOUT_ON_GET = True
from django.shortcuts import HttpResponseRedirect
from django.core.urlresolvers import reverse_lazy
# ... in your view
if user_form.is_valid():
deactivate_user = user_form.save(commit=False)
user.is_active = False
deactivate_user.save()
return HttpResponseRedirect(reverse_lazy('account_logout'))
|
Enable oauth login with django-allauth but a custom provider
Date : March 29 2020, 07:55 AM
|
Django allauth social login(google OAuth 2) - limit list of domains
Date : March 29 2020, 07:55 AM
This might help you The approach I use is to write a custom SocialAccountAdapter which returns false for is_open_for_signup in certain conditions. In settings, add this: SOCIALACCOUNT_ADAPTER = 'myapp.auth.adapters.SocialAccountAdapter'
from allauth.socialaccount.adapter import DefaultSocialAccountAdapter
def email_domain(email):
"""Extracts the domain from an email address.
Warning: this is simplified and you may want a true email address parser.
"""
return email.split('@')[-1]
# Note: this would be better in settings.py
allowed_signup_domains = [
'abc.com',
'seconddomain.com',
'etcetc.com',
]
class SocialAccountAdapter(DefaultSocialAccountAdapter):
def is_open_for_signup(self, request, sociallogin):
if email_domain(sociallogin.user.email) not in allowed_signup_domains:
return False
return super(SocialAccountAdapter, self).is_open_for_signup(request, sociallogin)
|