@@ -1889,7 +1889,114 @@ _default_config = {
18891889```
18901890
18911891
1892- # # Example 12 from Flasky
1892+ # # Example 12 from Flask-User
1893+ [Flask- User](https:// github.com/ lingthio/ Flask- User)
1894+ ([PyPI information](https:// pypi.org/ project/ Flask- User/ )
1895+ and
1896+ [project documentation](https:// flask- user.readthedocs.io/ en/ latest/ ))
1897+ is a [Flask](/ flask.html) extension that makes it easier to add
1898+ custom user account management and authentication to the projects
1899+ you are building. The extension supports persistent data storage
1900+ through both [relational databases](/ databases.html) and
1901+ [MongoDB](/ mongodb.html). The project is provided as open source under
1902+ the [MIT license ](https:// github.com/ lingthio/ Flask- User/ blob/ master/ LICENSE .txt).
1903+
1904+ [** Flask- User / flask_user / user_manager.py** ](https:// github.com/ lingthio/ Flask- User/ blob/ master/ flask_user/ ./ user_manager.py)
1905+
1906+ ```python
1907+ # user_manager.py
1908+
1909+
1910+ import datetime
1911+
1912+ ~~ from flask import abort, Blueprint, current_app, Flask, session
1913+ from flask_login import LoginManager
1914+ from wtforms import ValidationError
1915+
1916+ from . import ConfigError
1917+ from . import forms
1918+ from .db_manager import DBManager
1919+ from .email_manager import EmailManager
1920+ from .password_manager import PasswordManager
1921+ from .token_manager import TokenManager
1922+ from .translation_utils import lazy_gettext as _ # map _() to lazy_gettext()
1923+ from .user_manager__settings import UserManager__Settings
1924+ from .user_manager__utils import UserManager__Utils
1925+ from .user_manager__views import UserManager__Views
1926+
1927+
1928+ class UserManager(UserManager__Settings, UserManager__Utils, UserManager__Views):
1929+
1930+ def __init__ (self , app, db, UserClass, ** kwargs):
1931+
1932+ self .app = app
1933+ if app:
1934+ self .init_app(app, db, UserClass, ** kwargs)
1935+
1936+ def init_app(
1937+
1938+
1939+ # # ... source file abbreviated to get to current_app examples ...
1940+
1941+
1942+ def advance_session_timeout():
1943+ session.permanent = True # Timeout after app.permanent_session_lifetime period
1944+ session.modified = True # Advance session timeout each time a user visits a page
1945+
1946+ self .login_manager = LoginManager(app)
1947+ self .login_manager.login_view = ' user.login'
1948+
1949+ @ self .login_manager.user_loader
1950+ def load_user_by_user_token(user_token):
1951+ user = self .db_manager.UserClass.get_user_by_token(user_token)
1952+ return user
1953+
1954+ self .babel = app.extensions.get(' babel' , None )
1955+ from .translation_utils import init_translations
1956+ init_translations(self .babel)
1957+
1958+ if not hasattr (app.jinja_env, ' install_gettext_callables' ):
1959+ app.jinja_env.add_extension(' jinja2.ext.i18n' )
1960+ app.jinja_env.install_null_translations()
1961+
1962+ def flask_user_context_processor():
1963+ def call_or_get(function_or_property):
1964+ return function_or_property() if callable (function_or_property) else function_or_property
1965+
1966+ return dict (
1967+ ~~ user_manager = current_app.user_manager,
1968+ call_or_get = call_or_get,
1969+ )
1970+
1971+ app.context_processor(flask_user_context_processor)
1972+
1973+ blueprint = Blueprint(' flask_user' , __name__ , template_folder = ' templates' )
1974+ app.register_blueprint(blueprint)
1975+
1976+ self .AddEmailFormClass = forms.AddEmailForm
1977+ self .ChangePasswordFormClass = forms.ChangePasswordForm
1978+ self .ChangeUsernameFormClass = forms.ChangeUsernameForm
1979+ self .EditUserProfileFormClass = forms.EditUserProfileForm
1980+ self .ForgotPasswordFormClass = forms.ForgotPasswordForm
1981+ self .InviteUserFormClass = forms.InviteUserForm
1982+ self .LoginFormClass = forms.LoginForm
1983+ self .RegisterFormClass = forms.RegisterForm
1984+ self .ResendEmailConfirmationFormClass = forms.ResendEmailConfirmationForm
1985+ self .ResetPasswordFormClass = forms.ResetPasswordForm
1986+
1987+ self .db_manager = DBManager(app, db, UserClass, UserEmailClass, UserInvitationClass, RoleClass)
1988+
1989+ self .password_manager = PasswordManager(app)
1990+
1991+ if self .USER_ENABLE_EMAIL :
1992+
1993+
1994+ # # ... source file continues with no further current_app examples...
1995+
1996+ ```
1997+
1998+
1999+ # # Example 13 from Flasky
18932000[Flasky](https:// github.com/ miguelgrinberg/ flasky) is a wonderful
18942001example application by
18952002[Miguel Grinberg](https:// github.com/ miguelgrinberg) that he builds
@@ -1944,7 +2051,7 @@ def run_migrations_online():
19442051```
19452052
19462053
1947- # # Example 13 from sandman2
2054+ # # Example 14 from sandman2
19482055[sandman2](https:// github.com/ jeffknupp/ sandman2)
19492056([project documentation](https:// sandman2.readthedocs.io/ en/ latest/ )
19502057and
@@ -2069,7 +2176,7 @@ def register_model(cls, admin=None):
20692176```
20702177
20712178
2072- # # Example 14 from tedivms-flask
2179+ # # Example 15 from tedivms-flask
20732180[tedivm' s flask starter app](https://github.com/tedivm/tedivms-flask) is a
20742181base of [Flask](/ flask.html) code and related projects such as
20752182[Celery](/ celery.html) which provides a template to start your own
0 commit comments