Flask-login only works if get_id () returns self.email

my User class is not inherited from UserMixin, but defines its own elements and functions necessary for entering checkboxes.

The login process only works if I set get_id () to return the email of the instance. if I try to do this by username or actual id, I do not receive an error message, but I noticed that I am not registered (I cannot access a URL that requires me to log 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 moment, asking the question, I did not understand, get_id () should match load_user ()

@login_manager.user_loader
def load_user(email):
    return User.get_user(email)
+4
1

, get_id() login_manager.user_loader, .

+4

Source: https://habr.com/ru/post/1625533/


All Articles