0
votes

I'm having a really odd issue that I'm having trouble figuring out.

On my site, I have an option for a user to register via either a normal signup page or via Facebook social auth --I'm using the Social Auth App for Python/Django.

A user can successfully register either way.

If a user registers by the normal signup method and enters username and email and password---they are able to successfully trigger a password reset if desired via a password reset page.

BUT, if a user signs up via Facebook AUTH, after their user profile is created, if they go to enter their email for a password reset, no EMAIL is generated.

Here are my settings in settings.py for the auth apps.

AUTH_USER_MODEL = "accounts.User"
SOCIAL_AUTH_USER_MODEL = 'accounts.User'
SOCIAL_AUTH_FACEBOOK_SCOPE = ['email']
SOCIAL_AUTH_FACEBOOK_PROFILE_EXTRA_PARAMS = {
    'fields': 'id,name,email', 
}
SOCIAL_AUTH_SLUGIFY_USERNAMES = True

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.get_username',
    'social_core.pipeline.social_auth.associate_by_email',  # <--- enable this one
    'social_core.pipeline.user.create_user',
    'social_core.pipeline.social_auth.associate_user',
    'social_core.pipeline.social_auth.load_extra_data',
    'social_core.pipeline.user.user_details',
)

As you can see i'm slugifying the username, so all fields are populated.

Here is my User model

class User(AbstractBaseUser, PermissionsMixin):
    email = models.EmailField(unique=True, error_messages={'unique':"This email has already been registered."})
    username = models.CharField(max_length=40, default='')
    first_name = models.CharField(max_length=40, default='', blank=True)
    last_name = models.CharField(max_length=40, default='', blank=True)
    date_joined = models.DateTimeField(default=timezone.now)
    favorites = models.ManyToManyField(Deal, related_name='favorited_by', null=True, blank=True)
    is_active = models.BooleanField(default=True)
    is_staff = models.BooleanField(default=False)

    objects = UserManager()

    USERNAME_FIELD = 'email'
    REQUIRED_FIELDS = ['username']

Anyone see anything that I might be missing here--or why these emails might not be triggered?

2
What do you expect to happen? Your site being able to reset their global facebook password?Basic
hah..no....but there is a password being created that I can see in the admin...so I would expect that a new password is just re-generated if they reset it (but maybe i'm wrong)John Rogerson
I'm not familiar with the plugin, so may be miles off base, but I'd assume the point of using an external auth provider is that the user doesn't have a password managed by your system. Does the user have to use anything other than their facebook password to log in?Basic
no they only need to be logged into facebook in order to login to my site. maybe you are making a good point, I probably shouldn't even worry about those users, they can just get auth by choosing to login with facebookJohn Rogerson
yep it does start with a '!' --- i guess that answers my question. thanks for the intel on thatJohn Rogerson

2 Answers

2
votes

By default Django will set an unusable password on the user record, also by default Django won't allow you to reset these users password, for that to happen you need to implement your own version of the reset mechanism (you should be able to extend Django built-in on).

python-social-auth doesn't handle passwords or passwords resets.

1
votes

you need to override get_users method of class auth_views.PasswordResetForm example

class yourOverriding(auth_views.PasswordResetForm):

    def get_users(self, email):
        """Given an email, return matching user(s) who should receive a reset.

        This allows subclasses to more easily customize the default policies
        that prevent inactive users and users with unusable passwords from
        resetting their password.
        """
        active_users = UserModel._default_manager.filter(**{
            '%s__iexact' % UserModel.get_email_field_name(): email,
            'is_active': True,
        })
        d = (u for u in active_users)
        return d