Ejemplo n.º 1
0
def init_app(app, echo=False):
    db_url = app.config['DB_URL']
    session.configure(bind=get_engine(db_url, echo=echo))
    init_social(app, session)

    @app.teardown_appcontext
    def shutdown_session(exception=None):
        session.remove()
Ejemplo n.º 2
0
def extensions_fabrics(app):
    db.init_app(app)
    mail.init_app(app)
    babel.init_app(app)
    pages.init_app(app)
    init_social(app, db)
    login_manager.init_app(app)
    manager.init_app(app, flask_sqlalchemy_db=db)
    migrate.init_app(app, db)
    csrf.init_app(app)
    cache.init_app(app)
    celery.config_from_object(app.config)
Ejemplo n.º 3
0
Archivo: app.py Proyecto: xen/flask-ptc
def extensions_fabrics(app):
    db.init_app(app)
    mail.init_app(app)
    babel.init_app(app)
    pages.init_app(app)
    init_social(app, db)
    login_manager.init_app(app)
    manager.init_app(app, db)
    migrate.init_app(app, db)
    csrf.init_app(app)
    cache.init_app(app)
    celery.config_from_object(app.config)
Ejemplo n.º 4
0
def init_social_login():
    """
    Init login with Google OAuth2.
    """
    app.register_blueprint(social_auth)
    init_social(app, db)

    login_manager = login.LoginManager()
    login_manager.login_view = 'index'
    login_manager.login_message = ''
    login_manager.init_app(app)

    @login_manager.user_loader
    def load_user(userid):
        """
        Get User object.
        """
        from . import models
        try:
            return models.User.query.get(userid)
        except (TypeError, ValueError):
            pass

    @app.before_request
    def global_user():
        """
        Save User object in globals so it can be easily accessed.
        """
        g.user = login.current_user

    @app.context_processor
    def inject_user():
        """
        Save User object so it can be easily accessed in templates.
        """
        try:
            return {'user': g.user}
        except AttributeError:
            return {'user': None}

    app.context_processor(backends)
Ejemplo n.º 5
0
def init_social_models(app):
    try:
        import viralata
    except:
        sys.path.append('..')
    init_social(app, db.session)
Ejemplo n.º 6
0
# App
app = Flask(__name__)
app.config.from_object('flask_example.settings')

try:
    app.config.from_object('flask_example.local_settings')
except ImportError:
    pass

# DB
engine = create_engine(app.config['SQLALCHEMY_DATABASE_URI'])
Session = sessionmaker(autocommit=False, autoflush=False, bind=engine)
db_session = scoped_session(Session)

app.register_blueprint(social_auth)
init_social(app, db_session)

login_manager = LoginManager()
login_manager.login_view = 'main'
login_manager.login_message = ''
login_manager.init_app(app)

from flask_example import models
from flask_example import routes


@login_manager.user_loader
def load_user(userid):
    try:
        return models.user.User.query.get(int(userid))
    except (TypeError, ValueError):
Ejemplo n.º 7
0
def register_extensions(app):
    """Register Flask extensions."""
    bcrypt.init_app(app)
    login_manager.init_app(app)
    db.init_app(app)
    init_social(app, db.session)
Ejemplo n.º 8
0
from social.apps.flask_app.template_filters import backends
from social.apps.flask_app.default.models import init_social

# App
app = Flask(__name__)
app.config.from_object('flask_example.settings')

try:
    app.config.from_object('flask_example.local_settings')
except ImportError:
    pass

# DB
db = SQLAlchemy(app)
app.register_blueprint(social_auth)
init_social(app, db)

login_manager = login.LoginManager()
login_manager.login_view = 'main'
login_manager.login_message = ''
login_manager.init_app(app)

from flask_example import models
from flask_example import routes


@login_manager.user_loader
def load_user(userid):
    try:
        return models.user.User.query.get(int(userid))
    except (TypeError, ValueError):
Ejemplo n.º 9
0
from fudcon.ui.frontend.utils import avatar_url
from functools import wraps
from fudcon.modules.users.models import User
from social.apps.flask_app.routes import social_auth
from social.apps.flask_app.template_filters import backends
from social.apps.flask_app.default.models import init_social
from social.exceptions import SocialAuthBaseException

# Instantiate application.
app = Flask(__name__)
app.config.from_object('config.DevelopmentConfig')

# Instantiate database object
db.init_app(app)

init_social(app, db)


# Set up FAS
FAS = FAS(app)

login_manager = login.LoginManager()
login_manager.login_view = 'frontend.login'
login_manager.login_message = ''
login_manager.init_app(app)


# Set OpenID

@login_manager.user_loader
def load_user(user_id):