UserManager Class¶
The UserManager class implements most of the Flask-User functionality.
Flask-User can be customized by extending or overriding any of the methods listed below.
-
class
UserManager
(app, db, UserClass, **kwargs)¶ Customizable User Authentication and Management.
Parameters: - app (Flask) – The Flask application instance.
- db – An Object-Database Mapper instance such as SQLAlchemy or MongoEngine.
- UserClass – The User class (not an instance!).
Keyword Arguments: - UserEmailClass – The optional UserEmail class (not an instance!). Required for the ‘multiple emails per user’ feature.
- UserInvitationClass – The optional UserInvitation class (not an instance!). Required for the ‘register by invitation’ feature.
Example
user_manager = UserManager(app, db, User, UserEmailClass=UserEmail)
Customizable UserManager methods
-
customize
(app)¶ Override this method to customize properties.
Example:
# Customize Flask-User class CustomUserManager(UserManager): def customize(self, app): # Add custom managers and email mailers here self.email_manager = CustomEmailManager(app) self.password_manager = CustomPasswordManager(app) self.token_manager = CustomTokenManager(app) self.email_adapter = CustomEmailAdapter(app) # Setup Flask-User user_manager = CustomUserManager(app, db, User)
-
password_validator
(form, field)¶ Ensure that passwords have at least 6 characters with one lowercase letter, one uppercase letter and one number.
Override this method to customize the password validator.
-
username_validator
(form, field)¶ Ensure that Usernames contains at least 3 alphanumeric characters.
Override this method to customize the username validator.