The Security class initializes the Flask-Security extension.
| Parameters: |
|
|---|
Initializes the Flask-Security extension for the specified application and datastore implentation.
| Parameters: |
|
|---|
A proxy for the current user.
If you decorate a view with this, it will ensure that the current user is logged in and authenticated before calling the actual view. (If they are not, it calls the ~LoginManager.unauthorized callback.) For example:
@app.route("/post")
@login_required
def post():
pass
If there are only certain times you need to require that your user is logged in, you can do so with:
if not current_user.is_authenticated():
return current_app.login_manager.unauthorized()
(which is essentially the code that this function adds to your views).
| Parameters: | fn – The view function to decorate. |
|---|
Decorator which specifies that a user must have all the specified roles. Example:
@app.route('/dashboard')
@roles_required('admin', 'editor')
def dashboard():
return 'Dashboard'
The current user must have both the admin role and editor role in order to view the page.
| Parameters: | args – The required roles. |
|---|
Decorator which specifies that a user must have at least one of the specified roles. Example:
@app.route('/create_post')
@roles_accepted('editor', 'author')
def create_post():
return 'Create Post'
The current user must have either the editor role or author role in order to view the page.
| Parameters: | args – The possible roles. |
|---|
Decorator that protects endpoints using Basic HTTP authentication. The username should be set to the user’s email address.
| Parameters: | realm – optional realm name |
|---|
Decorator that protects endpoints using token authentication. The token should be added to the request by the client by using a query string variable with a name equal to the configuration value of SECURITY_TOKEN_AUTHENTICATION_KEY or in a request header named that of the configuration value of SECURITY_TOKEN_AUTHENTICATION_HEADER
Mixin for User model definitions
Returns the user’s authentication token.
Returns True if the user identifies with the specified role.
| Parameters: | role – A role name or Role instance |
|---|
Returns True if the user is active.
Mixin for Role model definitions
Abstracted user datastore.
| Parameters: |
|
|---|
Activates a specified user. Returns True if a change was made.
| Parameters: | user – The user to activate |
|---|
Adds a role tp a user
| Parameters: |
|
|---|
Creates and returns a new role from the given parameters.
Creates and returns a new user from the given parameters.
Deactivates a specified user. Returns True if a change was made.
| Parameters: | user – The user to deactivate |
|---|
Delete the specified user
| Parameters: | user – The user to delete |
|---|
Returns a role matching the given name or creates it with any additionally provided parameters
Returns a role matching the provided name.
Returns a user matching the provided parameters.
Removes a role from a user
| Parameters: |
|
|---|
Toggles a user’s active status. Always returns True.
A SQLAlchemy datastore implementation for Flask-Security that assumes the use of the Flask-SQLAlchemy extension.
Activates a specified user. Returns True if a change was made.
| Parameters: | user – The user to activate |
|---|
Adds a role tp a user
| Parameters: |
|
|---|
Creates and returns a new role from the given parameters.
Creates and returns a new user from the given parameters.
Deactivates a specified user. Returns True if a change was made.
| Parameters: | user – The user to deactivate |
|---|
Delete the specified user
| Parameters: | user – The user to delete |
|---|
Returns a role matching the given name or creates it with any additionally provided parameters
Removes a role from a user
| Parameters: |
|
|---|
Toggles a user’s active status. Always returns True.
A MongoEngine datastore implementation for Flask-Security that assumes the use of the Flask-MongoEngine extension.
Activates a specified user. Returns True if a change was made.
| Parameters: | user – The user to activate |
|---|
Adds a role tp a user
| Parameters: |
|
|---|
Creates and returns a new role from the given parameters.
Creates and returns a new user from the given parameters.
Deactivates a specified user. Returns True if a change was made.
| Parameters: | user – The user to deactivate |
|---|
Delete the specified user
| Parameters: | user – The user to delete |
|---|
Returns a role matching the given name or creates it with any additionally provided parameters
Removes a role from a user
| Parameters: |
|
|---|
Toggles a user’s active status. Always returns True.
A PeeweeD datastore implementation for Flask-Security that assumes the use of the Flask-Peewee extension.
| Parameters: |
|
|---|
Activates a specified user. Returns True if a change was made.
| Parameters: | user – The user to activate |
|---|
Adds a role tp a user
| Parameters: |
|
|---|
Creates and returns a new role from the given parameters.
Creates and returns a new user from the given parameters.
Deactivates a specified user. Returns True if a change was made.
| Parameters: | user – The user to deactivate |
|---|
Delete the specified user
| Parameters: | user – The user to delete |
|---|
Returns a role matching the given name or creates it with any additionally provided parameters
Removes a role from a user
| Parameters: |
|
|---|
Toggles a user’s active status. Always returns True.
See the Flask documentation on signals for information on how to use these signals in your code.
See the documentation for the signals provided by the Flask-Login and Flask-Principal extensions. In addition to those signals, Flask-Security sends the following signals.
Sent when a user registers on the site. It is passed a dict with the user and confirm_token, the user being logged in and the (if so configured) the confirmation token issued.
Sent when a user is confirmed. It is passed user, which is the user being confirmed.
Sent when a user requests confirmation instructions. It is passed the user.
Sent when passwordless login is used and user logs in. It is passed a dict with the user and login_token, the user being logged in and the (if so configured) the login token issued.
Sent when a user completes a password reset. It is passed the user.
Sent when a user completes a password change. It is passed the user.
Sent when a user requests a password reset. It is passed a dict with the user and token, the user being logged in and the (if so configured) the reset token issued.
All signals are also passed a app keyword argument, which is the current application.