I have successfully implemented the social_auth package for django and it is successfully populating the fields in postgres. I am trying to extend the user models so that i can add some additional data while creating the account by user. This is what i could come up with, till now.
I have almost tried all the available resources online available but are not very helpful in this case.
settings.py #pipeline
SOCIAL_AUTH_PIPELINE = (
'social_core.pipeline.social_auth.social_details',
'social_core.pipeline.social_auth.social_uid',
'social_core.pipeline.social_auth.auth_allowed',
'social_core.pipeline.social_auth.social_user',
'social_core.pipeline.user.create_user',
'django_social_app.pipeline.requestprofiledata',
'social_core.pipeline.social_auth.associate_user',
'social_core.pipeline.social_auth.load_extra_data',
'social_core.pipeline.user.user_details',
)
models.py
from django.db import models
from django.contrib.auth.models import User, auth
# Create your models here.
class profiledata(models.Model):
user = models.OneToOneField(User,on_delete=models.CASCADE)
#first_name =models.CharField(max_length=120)
#last_name =models.CharField(max_length=120)
#email =models.CharField(max_length=120)
registeredemail = models.CharField(max_length=120)
mobile = models.CharField(max_length=10)
instname = models.CharField(max_length=10)
idproof = models.FileField(upload_to='documents/')
profiledatacomplete = models.BooleanField()
views.py
def getprofiledata(request):
return render(request,'createCertificates/profile.html')
pipeline.py
from django.shortcuts import redirect
from .models import profiledata
#from socia.pipeline.partial import partial
from django_social_app import views
from social_core.pipeline.partial import partial
@partial
def requestprofiledata(strategy, details, user=None, is_new=False, *args, **kwargs):
print(details)
print(type(user))
#print(user.first_name,"..............")
#print(user.registeredemail)
test = 0
#if user and user.email and test != 0:
if test == 1:
return
#elif is_new and not details.get('email'):
else:
registeredemail = strategy.request_data().get("registeredemail")
#user['registeredemail'] = strategy.request_data().get("registeredemail")
mobile = strategy.request_data().get("mobile")
instname = strategy.request_data().get("instname")
idproof = strategy.request_data().get("idproof")
'''
new_user = profiledata.objects.create(
registeredemail=registeredemail,
mobile=mobile,
instname=instname,
idproof=idproof
)
new_user.save()
print('Profile saved')
'''
if registeredemail:
print("found data")
print("data",registeredemail,mobile,instname)
print("user",user)
print(".................................")
else:
return redirect('getprofiledata')