lingthio / Flask-User

Customizable User Authorization & User Management: Register, Confirm, Login, Change username/password, Forgot password and more.
http://flask-user.readthedocs.io/
MIT License
1.06k stars 292 forks source link

argument of type 'User' is not iterable #212

Closed beebird closed 6 years ago

beebird commented 6 years ago

When reseting my password (reset_password_view), I got the error TypeError: argument of type 'User' is not iterable. After debugging, it seems that the there's a problem with function get_primary_user_email in db_manager.py,

    def get_primary_user_email(self, user):
        """Retrieve the email from User object or the primary UserEmail object (if multiple emails
        per user are enabled)."""
        if self.UserEmailClass:
            user_email = self.db_adapter.find_first_object(
                self.UserEmailClass,
                user_id=user.id,
                is_primary=True)
            return user_email
        else:
            return user

I'm not using UserEmailClass, so the result returned is a User object, which is not iterable...

Can you take a look? Thanks!

beebird commented 6 years ago

I temporarily fixed this by modifying user_manager__views.py

- self.email_manager.send_password_changed_email(current_user)
+ self.email_manager.send_password_changed_email(current_user.email)

- self.email_manager.send_password_changed_email(user)
+ self.email_manager.send_password_changed_email(user.email)
lingthio commented 6 years ago

Thanks for this bug report. I've fixed it in a slightly different way:

    user_or_user_email_object = self.user_manager.db_manager.get_primary_user_email_object(user)
    email = user_or_user_email_object.email

It will be part of the next release build.

lingthio commented 6 years ago

Fixed in v1.0.1.4