diff --git a/flask_security/__init__.py b/flask_security/__init__.py index 647d1f07..0c3c5139 100644 --- a/flask_security/__init__.py +++ b/flask_security/__init__.py @@ -10,8 +10,6 @@ :license: MIT, see LICENSE for more details. """ -__version__ = '1.7.4' - from .core import Security, RoleMixin, UserMixin, AnonymousUser, current_user from .datastore import SQLAlchemyUserDatastore, MongoEngineUserDatastore, PeeweeUserDatastore from .decorators import auth_token_required, http_auth_required, \ @@ -21,3 +19,5 @@ from .signals import confirm_instructions_sent, password_reset, \ reset_password_instructions_sent, user_confirmed, user_registered from .utils import login_user, logout_user, url_for_security + +__version__ = '1.7.4' diff --git a/flask_security/core.py b/flask_security/core.py index 188c0cb5..fe436165 100644 --- a/flask_security/core.py +++ b/flask_security/core.py @@ -199,11 +199,11 @@ def _token_loader(token): return user except: pass - return AnonymousUser() + return _security.login_manager.anonymous_user() def _identity_loader(): - if not isinstance(current_user._get_current_object(), AnonymousUser): + if not isinstance(current_user._get_current_object(), AnonymousUserMixin): identity = Identity(current_user.id) return identity @@ -218,9 +218,9 @@ def _on_identity_loaded(sender, identity): identity.user = current_user -def _get_login_manager(app): +def _get_login_manager(app, anonymous_user): lm = LoginManager() - lm.anonymous_user = AnonymousUser + lm.anonymous_user = anonymous_user or AnonymousUser lm.login_view = '%s.login' % cv('BLUEPRINT_NAME', app=app) lm.user_loader(_user_loader) lm.token_loader(_token_loader) @@ -258,14 +258,14 @@ def _get_serializer(app, name): return URLSafeTimedSerializer(secret_key=secret_key, salt=salt) -def _get_state(app, datastore, **kwargs): +def _get_state(app, datastore, anonymous_user=None, **kwargs): for key, value in get_config(app).items(): kwargs[key.lower()] = value kwargs.update(dict( app=app, datastore=datastore, - login_manager=_get_login_manager(app), + login_manager=_get_login_manager(app, anonymous_user), principal=_get_principal(app), pwd_context=_get_pwd_context(app), remember_token_serializer=_get_serializer(app, 'remember'), @@ -399,7 +399,8 @@ def init_app(self, app, datastore=None, register_blueprint=True, login_form=None, confirm_register_form=None, register_form=None, forgot_password_form=None, reset_password_form=None, change_password_form=None, - send_confirmation_form=None, passwordless_login_form=None): + send_confirmation_form=None, passwordless_login_form=None, + anonymous_user=None): """Initializes the Flask-Security extension for the specified application and datastore implentation. @@ -425,7 +426,8 @@ def init_app(self, app, datastore=None, register_blueprint=True, reset_password_form=reset_password_form, change_password_form=change_password_form, send_confirmation_form=send_confirmation_form, - passwordless_login_form=passwordless_login_form) + passwordless_login_form=passwordless_login_form, + anonymous_user=anonymous_user) if register_blueprint: app.register_blueprint(create_blueprint(state, __name__))