In order to use our User class with Flask-login, we need to add a few methods to it:
- is_authenticated: Determines whether the user authentication succeeded.
- is_active: Can be used to deactivate users (email address not validated, subscription expired, and so on).
- is_anonymous: This is another way to detect unauthenticated users.
- get_id: Defines the unique identifier for each user.
Since these methods are common to almost all web applications, they have been implemented in a UserMixin, which we can add to our User class to access these methods. The only method we need a custom behavior for is the get_id method since our model does not have an id field; here, the primary key role is taken by the login field:
class User(StructuredNode, Flask_login.UserMixin):
# ... same as above
def get_id(self):
return self.login