5
votes

my User class does not inherit from UserMixin but rather defines its own members and functions necessary for flask-login.

the login process only works if i set get_id() to return the instance email. if i attempt to do this on the user's name or actual id i don't get an error but i notice i am not logged (i am unable to access url's that require me to be logged in using @required_login)

class User(db.Model):
    id = db.Column(db.Integer,primary_key=True)
    email = db.Column(db.Unicode(128))
    name = db.Column(db.Unicode(128))
    password = db.Column(db.Unicode(1024))
    authenticated = db.Column(db.Boolean, default=False)
    posts = db.relationship('Post')
    #-----login requirements-----
    def is_active(self):
        # all users are active
        return True 

    def get_id(self):
        # returns the user e-mail
        return unicode(self.email)

    def is_authenticated(self):
        return self.authenticated

    def is_anonymous(self):
        # False as we do not support annonymity
        return False

EDIT: at the time asking the question i did not understand get_id() needs to match load_user()

@login_manager.user_loader
def load_user(email):
    return User.get_user(email)
1
Post your user loader also?Busturdust
@Busturdust saw your comment after finding that out for myself. cheers mateGil Hiram
@Busturdust I believe the whole question here was about which module communicates with the User classuser2469775

1 Answers

5
votes

it only works this way because get_id() needs to match login_manager.user_loader which in my case is expecting the email of the user.