Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

duplicate emails #184

Open
percy3d opened this issue Jan 13, 2014 · 0 comments
Open

duplicate emails #184

percy3d opened this issue Jan 13, 2014 · 0 comments

Comments

@percy3d
Copy link

percy3d commented Jan 13, 2014

Hello,

I'm using social registration with userena to login facebook users and have an issue.

I have the following code for the connect signal:

def social_connect_callback(sender, user, profile, client, **kwargs):
"""
Create a profile for this user after connecting
'''

userenaSignup = UserenaSignup.objects.get_or_create(user=user)

# Create profile for user
try:
    print 'getting an account'
    new_profile = UserProfile.objects.get(user=user)
except:
    print 'creating new user'
    new_profile = UserProfile.objects.create(user=user)

if not user.first_name:
    user.first_name = fb_profile['first_name']
if not user.last_name:
    user.last_name = fb_profile['last_name']
if not user.email:
    user.email = fb_profile['email']
user.save()

# Give permissions to view and change profile
for perm in ASSIGNED_PERMISSIONS['profile']:
    assign(perm[0], user, new_profile)

# Give permissions to view and change itself
for perm in ASSIGNED_PERMISSIONS['user']:
    assign(perm[0], user, user)

signals.connect.connect(social_connect_callback, sender=FacebookProfile, dispatch_uid = 'facebook_connect')

This is code doesn't deal with existing emails so we end up with two records with the same email which causes Userena to break if the user attempts to login the traditional way(username/email, password).

How can I prevent this from happening. I tried to check and see if the fb_profile['email'] existed already but can't delete the current record tied to the user object passed to the and authenticate the user with the existing record.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant