mirror of
https://github.com/wassname/flask-security.git
synced 2026-07-03 17:10:25 +08:00
Clean up
This commit is contained in:
+7
-40
@@ -10,7 +10,7 @@
|
||||
"""
|
||||
|
||||
from itsdangerous import URLSafeTimedSerializer
|
||||
from flask import current_app, Blueprint
|
||||
from flask import current_app
|
||||
from flask.ext.login import AnonymousUser as AnonymousUserBase, \
|
||||
UserMixin as BaseUserMixin, LoginManager, current_user
|
||||
from flask.ext.principal import Principal, RoleNeed, UserNeed, Identity, \
|
||||
@@ -20,7 +20,6 @@ from werkzeug.datastructures import ImmutableList
|
||||
|
||||
from . import views, exceptions
|
||||
from .confirmable import requires_confirmation
|
||||
from .decorators import login_required
|
||||
from .utils import config_value as cv, get_config
|
||||
|
||||
|
||||
@@ -144,40 +143,6 @@ def _get_token_auth_serializer(app):
|
||||
return _get_serializer(app, app.config['SECURITY_AUTH_SALT'])
|
||||
|
||||
|
||||
def _create_blueprint(app):
|
||||
bp = Blueprint('flask_security', __name__, template_folder='templates')
|
||||
|
||||
bp.route(cv('AUTH_URL', app=app),
|
||||
methods=['POST'],
|
||||
endpoint='authenticate')(views.authenticate)
|
||||
|
||||
bp.route(cv('LOGOUT_URL', app=app),
|
||||
endpoint='logout')(login_required(views.logout))
|
||||
|
||||
if cv('REGISTERABLE', app=app):
|
||||
bp.route(cv('REGISTER_URL', app=app),
|
||||
methods=['GET', 'POST'],
|
||||
endpoint='register')(views.register_user)
|
||||
|
||||
if cv('RECOVERABLE', app=app):
|
||||
bp.route(cv('RESET_URL', app=app),
|
||||
methods=['GET', 'POST'],
|
||||
endpoint='forgot_password')(views.forgot_password)
|
||||
bp.route(cv('RESET_URL', app=app) + '/<token>',
|
||||
methods=['GET', 'POST'],
|
||||
endpoint='reset_password')(views.reset_password)
|
||||
|
||||
if cv('CONFIRMABLE', app=app):
|
||||
bp.route(cv('CONFIRM_URL', app=app),
|
||||
methods=['GET', 'POST'],
|
||||
endpoint='send_confirmation')(views.send_confirmation)
|
||||
bp.route(cv('CONFIRM_URL', app=app) + '/<token>',
|
||||
methods=['GET', 'POST'],
|
||||
endpoint='confirm_account')(views.confirm_account)
|
||||
|
||||
return bp
|
||||
|
||||
|
||||
class RoleMixin(object):
|
||||
"""Mixin for `Role` model definitions"""
|
||||
def __eq__(self, other):
|
||||
@@ -233,7 +198,7 @@ class Security(object):
|
||||
def __init__(self, app=None, datastore=None, **kwargs):
|
||||
self.init_app(app, datastore, **kwargs)
|
||||
|
||||
def init_app(self, app, datastore):
|
||||
def init_app(self, app, datastore, register_blueprint=True):
|
||||
"""Initializes the Flask-Security extension for the specified
|
||||
application and datastore implentation.
|
||||
|
||||
@@ -263,9 +228,11 @@ class Security(object):
|
||||
|
||||
identity_loaded.connect_via(app)(_on_identity_loaded)
|
||||
|
||||
bp = _create_blueprint(app)
|
||||
pre = cv('URL_PREFIX', app=app)
|
||||
app.register_blueprint(bp, url_prefix=pre)
|
||||
if register_blueprint:
|
||||
bp = views.create_blueprint(app, 'flask_security', __name__,
|
||||
template_folder='templates',
|
||||
url_prefix=cv('URL_PREFIX', app=app))
|
||||
app.register_blueprint(bp)
|
||||
|
||||
app.security = self
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
|
||||
from flask import current_app
|
||||
|
||||
from . import exceptions, confirmable, utils
|
||||
from . import exceptions, utils
|
||||
|
||||
|
||||
class UserDatastore(object):
|
||||
|
||||
@@ -15,8 +15,7 @@ import os
|
||||
from contextlib import contextmanager
|
||||
from datetime import datetime, timedelta
|
||||
|
||||
from flask import url_for, flash, current_app, request, session, \
|
||||
render_template
|
||||
from flask import url_for, flash, current_app, request, session, render_template
|
||||
from flask.ext.login import make_secure_token
|
||||
|
||||
from .signals import user_registered, password_reset_requested
|
||||
|
||||
+37
-2
@@ -12,13 +12,14 @@
|
||||
from datetime import datetime
|
||||
|
||||
from flask import current_app as app, redirect, request, session, \
|
||||
render_template, jsonify
|
||||
render_template, jsonify, Blueprint
|
||||
from flask.ext.login import login_user, logout_user
|
||||
from flask.ext.principal import Identity, AnonymousIdentity, identity_changed
|
||||
from werkzeug.datastructures import MultiDict
|
||||
from werkzeug.local import LocalProxy
|
||||
|
||||
from .confirmable import confirm_by_token, reset_confirmation_token
|
||||
from .decorators import login_required
|
||||
from .exceptions import ConfirmationError, BadCredentialsError, \
|
||||
ResetPasswordError
|
||||
from .forms import LoginForm, RegisterForm, ForgotPasswordForm, \
|
||||
@@ -28,7 +29,7 @@ from .recoverable import reset_by_token, \
|
||||
from .signals import user_registered
|
||||
from .tokens import generate_authentication_token
|
||||
from .utils import get_url, get_post_login_redirect, do_flash, \
|
||||
get_remember_token, get_message
|
||||
get_remember_token, get_message, config_value
|
||||
|
||||
|
||||
# Convenient references
|
||||
@@ -276,3 +277,37 @@ def reset_password(token):
|
||||
return render_template('security/passwords/edit.html',
|
||||
reset_password_form=form,
|
||||
password_reset_token=token)
|
||||
|
||||
|
||||
def create_blueprint(app, name, import_name, **kwargs):
|
||||
bp = Blueprint(name, import_name, **kwargs)
|
||||
|
||||
bp.route(config_value('AUTH_URL', app=app),
|
||||
methods=['POST'],
|
||||
endpoint='authenticate')(authenticate)
|
||||
|
||||
bp.route(config_value('LOGOUT_URL', app=app),
|
||||
endpoint='logout')(login_required(logout))
|
||||
|
||||
if config_value('REGISTERABLE', app=app):
|
||||
bp.route(config_value('REGISTER_URL', app=app),
|
||||
methods=['GET', 'POST'],
|
||||
endpoint='register')(register_user)
|
||||
|
||||
if config_value('RECOVERABLE', app=app):
|
||||
bp.route(config_value('RESET_URL', app=app),
|
||||
methods=['GET', 'POST'],
|
||||
endpoint='forgot_password')(forgot_password)
|
||||
bp.route(config_value('RESET_URL', app=app) + '/<token>',
|
||||
methods=['GET', 'POST'],
|
||||
endpoint='reset_password')(reset_password)
|
||||
|
||||
if config_value('CONFIRMABLE', app=app):
|
||||
bp.route(config_value('CONFIRM_URL', app=app),
|
||||
methods=['GET', 'POST'],
|
||||
endpoint='send_confirmation')(send_confirmation)
|
||||
bp.route(config_value('CONFIRM_URL', app=app) + '/<token>',
|
||||
methods=['GET', 'POST'],
|
||||
endpoint='confirm_account')(confirm_account)
|
||||
|
||||
return bp
|
||||
|
||||
Reference in New Issue
Block a user