コード例 #1
0
ファイル: auth.py プロジェクト: ananthb/binder
def setup_login_manager(app):
    """ setup_login_manager::flask.Flask->None

        Creates a login manager object and attaches an application
        object to it.

        Also sets up the login view function to redirect to, and
        the user_loader function.

    """

    login_manager = LoginManager()
    login_manager.init_app(app)
    login_manager.login_view = 'facebook.login'
    login_manager.login_message_category = 'warning'

    @login_manager.user_loader
    def load_user(user_id):
        try:
            # we need a request context for a valid db connection
            with current_app.test_request_context('/'):
                db = g.db
                user = db.session.query(User).filter(User.UUID == user_id).one()
                return user
        except NoResultFound as e:
            current_app.logger.debug(e)
            return None
コード例 #2
0
ファイル: core.py プロジェクト: joshkurz/exi
def _get_login_manager(app):
    lm = LoginManager()
    lm.anonymous_user = AnonymousUser
    lm.login_view = '%s.login' % cv('BLUEPRINT_NAME', app=app)
    lm.user_loader(_user_loader)
    lm.token_loader(_token_loader)
    lm.login_message = cv('MSG_LOGIN', app=app)
    lm.login_message_category = 'info'
    lm.needs_refresh_message = cv('MSG_REFRESH', app=app)
    lm.needs_refresh_message_category = 'info'
    lm.init_app(app)
    return lm
コード例 #3
0
ファイル: security.py プロジェクト: bentipping/victims-web
def setup_login_manager(app):
    """
    Configure the LoginManager for the provided app.
    """
    login_manager = LoginManager()
    login_manager.login_view = 'auth.login_user'
    login_manager.login_message = 'Resource access not authorized.'
    login_manager.login_message_category = 'error'
    login_manager.anonymous_user = AnonymousUser
    login_manager.init_app(app)
    login_manager.user_loader(load_user)
    user_logged_in.connect(on_login, app)
コード例 #4
0
def create_app():
    """Generates an instance of the app.

    This function contains all the config values
    for the different parts of the app; it returns
    a variable 'app' that contains all these values
    for use throughout the rest of the application.
    """
    app = Flask(__name__)

    # Sets the application into debug mode
    app.debug = True

    # Sets configuration variables used application-wise
    app.config['SECRET_KEY'] = 'vYqTMY88zsuXSG7R4xYdPxYk'
    app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///../database.db'

    # Configures SQLAlchemy
    db.init_app(app)

    # Configures the login manager
    login_manager = LoginManager()
    login_manager.init_app(app)
    login_manager.login_view = 'auth.login'  # Sets the login view.
    login_manager.login_message_category = 'warning'

    # Loads the current user by running a query on the id
    @login_manager.user_loader
    def load_user(id):
        return User.query.get(int(id))

    # Configures application blueprints
    from app.controllers.main import main
    app.register_blueprint(main)
    
    from app.controllers.auth import auth
    app.register_blueprint(auth)
    
    from app.controllers.ajax import ajax
    app.register_blueprint(ajax)

    return app
コード例 #5
0
ファイル: auth.py プロジェクト: schu/bookmarks
    def __init__(self, app):
        lm = LoginManager()

        lm.login_view = '/login'
        lm.login_message = 'Login required.'
        lm.login_message_category = 'error'
        lm.anonymous_user = AnonymousUser

        lm.setup_app(app)

        @lm.user_loader
        def user_loader(id):
            try:
                id = int(id)
                user = User.query.filter_by(id=id).first()
            except:
                return None
            return user

        app.login_manager = lm
        app.auth_handler = self.auth_handler
コード例 #6
0
ファイル: __init__.py プロジェクト: dregor/flask
app.jinja_env.globals['date_now'] = datetime.utcnow()

app.logger.setLevel(logging.INFO)

mail = Mail(app)

babel = Babel(app)

db = SQLAlchemy(app)

rest = APIManager(app, session=db.session)

lm = LoginManager()
lm.init_app(app)
lm.login_view = 'login'
lm.login_message_category = "info"
lm.login_message = lazy_gettext('Please log in to access this page.')


log_file_name = os.path.join(basedir, 'log/debug.log')

assets = Environment(app)

js = Bundle('js/moment-with-locales.js',
            'js/jquery.cookie.js',
            'js/bootstrap.js',
            'js/helpers.js',
#            filters='jsmin',
            output='gen/jsall.js')

css = Bundle('css/bootstrap.css',
コード例 #7
0
ファイル: __init__.py プロジェクト: gaucan/exams
from flask import Flask, redirect, request, url_for
from flask.ext.sqlalchemy import SQLAlchemy
import os
from flask.ext.login import LoginManager
from pprint import pprint
from config import config

db = SQLAlchemy()
lm = LoginManager()
lm.login_view = 'auth.login'
lm.login_message = u"Tato stranka vyzaduje prihlasenie."
lm.login_message_category = "danger"
lm.session_protection = 'strong'
@lm.unauthorized_handler
def unauthorized_callback():
    return redirect(url_for('auth.login',next=request.path))


def create_app(config_name):
	app = Flask(__name__)
	app.config.from_object(config[config_name])

	from main import main as main_blueprint # reg main blue
	app.register_blueprint(main_blueprint)

	from .auth import auth as auth_blueprint # reg auth blue 
	app.register_blueprint(auth_blueprint, url_prefix='/auth')

	from .student import student as student_blueprint # reg student blue 
	app.register_blueprint(student_blueprint, url_prefix='/student')
コード例 #8
0
ファイル: __init__.py プロジェクト: liyigerry/caixiang
# flask_pagedown
from flask_pagedown import PageDown
pagedown = PageDown(app)

# celery
from celery import Celery
celery = Celery(app.name, broker=app.config['CELERY_BROKER_URL'])
celery.conf.update(app.config)

# flask-login
from flask.ext.login import LoginManager
login_manager = LoginManager()
login_manager.setup_app(app)
login_manager.login_view = 'weibo.authorize'
login_manager.login_message = u'如需继续操作,请登录!'
login_manager.login_message_category = u'warning'

# flask-redis
from flask.ext.redis import FlaskRedis
redis_store = FlaskRedis(app)

# caixiang
from weibo import Client
wtoken = {'uid': '5721486534', 'access_token': '2.00sAmMPGnoNmDB63fece568a5VAURD'}
wclient = Client(app.config['API_KEY'], app.config['API_SECRET'],
	app.config['REDIRECT_URI'], token=wtoken)

import models
import views

# register blueprint
コード例 #9
0
def create_app(config={}):
    app = Flask(__name__, instance_relative_config=True)
    app.config.update(DEFAULT_CONFIG)
    app.config.from_pyfile('settings.py', silent=True)
    app.config.update(config)

    babel = Babel(app)

    @babel.localeselector
    def get_locale():
        return getattr(g, 'language', 'en')

    assets_env.init_app(app)
    db.init_app(app)

    app.register_blueprint(admin)
    app.register_blueprint(auth)
    app.register_blueprint(meetings)

    app.add_template_filter(activity_map)
    app.add_template_filter(countries)
    app.add_template_filter(country_in)
    app.add_template_filter(region_in)
    app.add_template_filter(crop)
    app.add_template_filter(nl2br)
    app.add_template_filter(convert_to_dict, name='dict')
    app.add_template_filter(no_image_cache)
    app.add_template_filter(pluralize)
    app.add_template_filter(slugify)
    app.add_template_filter(sort_by_tuple_element)
    app.add_template_filter(clean_html)
    app.add_template_global(active)
    app.add_template_global(date_processor)
    app.add_template_global(inject_static_file)
    app.add_template_global(inject_badge_context)
    app.add_template_global(has_perm)
    app.add_template_global(Logo, name='get_logo')

    @app.context_processor
    def inject_context():
        return {
            'CustomField': {
                'TEXT': CustomField.TEXT,
                'IMAGE': CustomField.IMAGE,
                'EMAIL': CustomField.EMAIL,
                'CHECKBOX': CustomField.CHECKBOX,
                'SELECT': CustomField.SELECT,
                'COUNTRY': CustomField.COUNTRY,
                'LANGUAGE': CustomField.LANGUAGE,
                'CATEGORY': CustomField.CATEGORY,
                'EVENT': CustomField.EVENT,
            },
            'Participant': {
                'PARTICIPANT': Participant.PARTICIPANT,
                'MEDIA': Participant.MEDIA,
                'DEFAULT': Participant.DEFAULT,
                'DEFAULT_MEDIA': Participant.DEFAULT_MEDIA,
            },
        }

    login_manager = LoginManager()
    login_manager.init_app(app)
    login_manager.login_view = 'auth.login'
    login_manager.login_message_category = 'warning'

    mail.init_app(app)
    redis_store.init_app(app, strict=True)

    if app.config.get('SENTRY_DSN'):
        sentry.init_app(app)

    _configure_uploads(app)
    _configure_logging(app)

    app.config['REPRESENTING_TEMPLATES'] = (
        path('meetings/participant/representing'))

    _translations = app.config['TRANSLATIONS']
    if _DEFAULT_LANG not in _translations:
        _translations = [_DEFAULT_LANG] + _translations
    app.config['TRANSLATIONS'] = _translations

    @login_manager.user_loader
    def load_user(user_id):
        return User.query.get(user_id)

    @app.route('/')
    def index():
        return redirect(url_for('meetings.home'))

    @app.errorhandler(413)
    def file_too_large(error):
        mb = 1024 * 1024
        max_size = app.config.get('UPLOAD_SIZE', mb) / mb
        return render_template('_file_too_large.html',
                               max_size=max_size,
                               url=request.url), 413

    return app
コード例 #10
0
ファイル: __init__.py プロジェクト: masakichi/pocket
# encoding=utf-8
from flask import Flask
from flask.ext.sqlalchemy import SQLAlchemy
from flask.ext.login import LoginManager
from flask.ext.bootstrap import Bootstrap

db = SQLAlchemy()
login_manager = LoginManager()
login_manager.login_view = 'main.login'
# use encoding=utf-8
login_manager.login_message = u'请先登录!'
login_manager.login_message_category = "info"
bs = Bootstrap()


def create_app(config_object):
    app = Flask(__name__)
    app.config.from_object(config_object)

    db.init_app(app)
    login_manager.init_app(app)
    bs.init_app(app)
    #avoid circular import.
    from app.views import main

    app.register_blueprint(main)

    return app

コード例 #11
0
bootstrap = Bootstrap(app)
db = SQLAlchemy(app)

from project.server.models import User

################
#  blueprints  #
################

from project.server.user.views import user_blueprint
from project.server.bathroom.views import bathroom_blueprint
from project.server.main.views import main_blueprint

app.register_blueprint(user_blueprint, url_prefix='/auth')
app.register_blueprint(bathroom_blueprint, url_prefix='/bathrooms')
app.register_blueprint(main_blueprint, url_prefix='/')

#################
#  flask-login  #
#################

from project.server.models import User

login_manager.login_view = "user.login"
login_manager.login_message_category = 'danger'


@login_manager.user_loader
def load_user(user_id):
    return User.query.filter(User.id == int(user_id)).first()
コード例 #12
0
from flask import Flask
from flask.ext.sqlalchemy import SQLAlchemy
from flask.ext.login import LoginManager

# Init Flask app
# Reference: http://flask.pocoo.org/docs/0.10/quickstart/
app = Flask(__name__)
app.config.from_object('config')
db = SQLAlchemy(app)

# Init user session management
# Reference: https://flask-login.readthedocs.org/en/latest/
lm = LoginManager(app)
lm.login_view = 'general.index'
lm.login_message_category = 'danger'

# catalog.views dependencies list contains app package
# this this here to avoid cyclic imports
import catalog.views
コード例 #13
0
ファイル: __init__.py プロジェクト: v2up/queyue
from flask.ext.login import LoginManager    #登录管理
from flask.ext.moment import Moment

from config import config	#不同的配置,不同的运行模式

import os

bootstrap = Bootstrap()
db = SQLAlchemy()
migrate = Migrate()
mail = Mail()
login_manager = LoginManager()
login_manager.session_protection = 'strong' #登录保护等级
login_manager.login_view = 'auth.login'
login_manager.login_message = '登录后方可访问'
login_manager.login_message_category = "alert-warning"
moment = Moment()

def create_app(config_name):
    '''工厂函数'''
    app = Flask(__name__)	#当前目录为根目录
    app.config.from_object(config[config_name])	#读取配置对象
    config[config_name].init_app(app)	#自己实现的staticmethod

    # 文件上传配置
    app.config['UPLOADS_DEFAULT_DEST'] = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'uploads/')    #F:\queyue\qy\uploads
    app.config['UPLOADS_DEFAULT_URL'] = 'http://127.0.0.1:5000/uploads/'

    bootstrap.init_app(app)
    db.init_app(app)
    migrate.init_app(app, db)
コード例 #14
0
from flask.ext.bootstrap import Bootstrap
from flask.ext.moment import Moment
from flask.ext.login import LoginManager
from flask.ext.mail import Mail
from config import config, log_dir, cache_file, cache_file_write
from mycache import MyCache

_log = logging.getLogger(__name__)

bootstrap = Bootstrap()
moment = Moment()
mail = Mail()
db = SQLAlchemy()
lm = LoginManager()
lm.login_view = 'main.login'
lm.login_message_category = "info"
cache = MyCache(cache_file, cache_file_write)


def create_app(config_name):
    # initialize application
    app = Flask(__name__)
    app.config.from_object(config[config_name])

    # initialize extentions
    bootstrap.init_app(app)
    moment.init_app(app)
    db.init_app(app)
    mail.init_app(app)
    lm.init_app(app)
コード例 #15
0
ファイル: util.py プロジェクト: drewmalin/WodTag
from flask.ext.login import LoginManager
from flask.ext.sqlalchemy import SQLAlchemy
from flask.ext.sendmail import Mail
from Main import app

lm = LoginManager()
lm.init_app(app)
lm.login_view = 'index'
lm.login_message_category = 'error'
lm.refresh_view = 'index'
lm.needs_refresh_message = 'You have been logged out due to inactivity.'
lm.needs_refresh_message_category = 'error'

app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///WodTag.sqlite'

app.config.update(dict(
    MAIL_FAIL_SILENTLY=False,
    MAIL_SUPPRESS_SEND=False,
    TESTING=False
))

db = SQLAlchemy(app)
mail = Mail(app)
コード例 #16
0
ファイル: __init__.py プロジェクト: andytom/snippets
app.config.from_object(os.environ.get('APP_SETTINGS',
                                      'config.DevelopmentConfig'))


# Data stores related stuff
db.init_app(app)
es = FlaskElasticsearch(app)
Migrate(app, db)
make_searchable(es, Snippet)


# Login stuff
login_manager = LoginManager(app)
login_manager.login_view = "login.login"
login_manager.login_message = "Please login"
login_manager.login_message_category = "alert-warning"


@login_manager.user_loader
def load_user(userid):
    """User loader for flask-login

       :param userid: It passed in from login_manager

       :returns: A User object if one exists returns None otherwise.
    """
    return User.query.get(userid)


# Front end stuff
Misaka(app, autolink=True, escape=True, fenced_code=True, no_html=True,
コード例 #17
0
ファイル: __init__.py プロジェクト: maquinuz/Revealer
from flask.ext.admin import Admin

app = Flask(__name__, static_url_path='/static')
app.config.from_pyfile('config.py')

socketio = SocketIO(app, async_mode='gevent')

slideshows = UploadSet('slideshows', ('html'))
resources = UploadSet('resources', ('css', 'js') + IMAGES)
configure_uploads(app, (slideshows, resources))

login_manager = LoginManager()
login_manager.init_app(app)
login_manager.session_protection = 'strong'
login_manager.login_view = 'auth.login'
login_manager.login_message_category = 'success'

db = SQLAlchemy()
db.init_app(app)

bootstrap = Bootstrap(app)

moment = Moment(app)

from auth import auth
from slides import slides
from presentation import presentation

app.register_blueprint(auth)
app.register_blueprint(slides)
app.register_blueprint(presentation)
コード例 #18
0
#!/usr/bin/env python
# encoding: utf-8

"""
@author: zhanghe
@software: PyCharm
@file: __init__.py
@time: 16-1-7 上午12:08
"""


from flask import Flask
from flask.ext.login import LoginManager


app = Flask(__name__)
app.config.from_object('config')
login_manager = LoginManager()
login_manager.init_app(app)  # setup_app 方法已淘汰
login_manager.login_view = 'login'
# login_manager.login_message = 'Please log in to access this page.'  # 设置登陆提示消息
login_manager.login_message_category = 'info'  # 设置消息分类

# 这个 import 语句放在这里, 防止views, models import发生循环import
from app import views, models
コード例 #19
0
from flask.ext.restful import Api

bcrypt = Bcrypt()
oid = OpenID()
oauth = OAuth()
principals = Principal()

admin_permission = Permission(RoleNeed('admin'))
poster_permission = Permission(RoleNeed('poster'))
default_permission = Permission(RoleNeed('default'))

login_manager = LoginManager()
login_manager.login_view = "main.login"
login_manager.session_protection = "strong"
login_manager.login_message = "Please login to access this page"
login_manager.login_message_category = "info"

rest_api = Api()


@login_manager.user_loader
def load_user(userid):
    from models import User
    return User.query.get(userid)


@oid.after_login
def create_or_login(resp):
    from models import db, User
    username = resp.fullname or resp.nickname or resp.email
コード例 #20
0
ファイル: __init__.py プロジェクト: mrfishball/O2
# Admin
# Handles the templating and rendering of the admin dashboard that allows site manager to curate the contents on the server.
# Such as create, modify and delete users, posts, comments, static files etc.
from admin import SlugModelView, UserModelView, PostModelView, BlogFileAdmin, IndexView, CommentModelView

admin = Admin(app, 'Administrator Dashboard', index_view=IndexView())
admin.add_view(PostModelView(models.Post, db.session))
admin.add_view(SlugModelView(models.Tag, db.session))
admin.add_view(UserModelView(models.User, db.session))
admin.add_view(CommentModelView(models.Comment, db.session))
admin.add_view(
    BlogFileAdmin(app.config['STATIC_DIR'], '/static/', name='Static Files'))

# Set default login landing page and flash message style.
lm.login_view = 'user_blueprint.login'
lm.login_message_category = 'info'

# API manager that handles json requests from the clients to the server.
from helpers import post_preprocessor

api.create_api(
    models.Comment,
    include_columns=['id', 'name', 'url', 'body', 'created_timestamp'],
    include_methods=['avatar'],
    methods=['GET', 'POST'],  #, 'DELETE'],
    preprocessors={
        'POST': [post_preprocessor],
    })


# Login manager to manager users that are currently logged in to our website
コード例 #21
0
from flask.ext.cache import Cache
from flask.ext.debugtoolbar import DebugToolbarExtension
from flask.ext.login import LoginManager
from flask_assets import Environment

from appname.models import User

# Setup flask cache
cache = Cache()

# init flask assets
assets_env = Environment()

debug_toolbar = DebugToolbarExtension()

login_manager = LoginManager()
login_manager.login_view = "main.login"
login_manager.login_message_category = "warning"


@login_manager.user_loader
def load_user(userid):
    return User.query.get(userid)
コード例 #22
0
ファイル: __init__.py プロジェクト: SYFT/GalaxyOJ
from rq import Queue
from rq.job import Job
from judge.worker import conn

from judge import judge

app = Flask(__name__)
app.config.from_object(config)

db = SQLAlchemy(app)

login_manager = LoginManager(app)
from .models.user import AnonymousUser
login_manager.anonymous_user = AnonymousUser
login_manager.login_view = 'auth.user_login'
login_manager.login_message = 'You need to login to access this page.'
login_manager.login_message_category = 'error'

Bootstrap(app)

q = Queue(connection = conn)

from .views import views
for view, prefix in views:
    app.register_blueprint(view, url_prefix=prefix)

# custom jinja2 filters
from .tools import datetime_format
app.jinja_env.filters['dtformat'] = datetime_format

コード例 #23
0
This licence text applies to all other files in this repository as well.

The source code which is used to run the application at fsfw-dresden.de is
available at https://github.com/fsfw-dresden/ldap-dingens
"""

from flask import Flask, flash, redirect, render_template, url_for
from flask.ext.login import (LoginManager, login_required, login_user,
                             logout_user, current_user, user_logged_out)

# first, we create the app, so that it is available for all our modules
app = Flask(__name__, instance_relative_config=True)
login_manager = LoginManager()
login_manager.login_view = 'index'
login_manager.login_message_category = "error"
login_manager.init_app(app)

import ldap3

from sqlalchemy.orm.exc import NoResultFound
from .database import CommitSession, init_db, get_session
from .forms import CreateInviteForm, RedeemForm, LoginForm, PasswdForm
from .ldap import get_group_members
from .model import Invitation, InvitationState, User, clean_stale_users
from .utils import (send_invitationmail, create_invitation, transfer_ldap_user)

from . import ldap


@login_manager.user_loader
コード例 #24
0
ファイル: controllers.py プロジェクト: wprager/clearwater
from urlparse import urlparse, urljoin
from werkzeug import secure_filename

# replace this with os.urandom(24) when we can make this secret:
app.secret_key = 'secret_key'
lm = LoginManager()
lm.init_app(app)

# TODO: allow users to register?
# TODO: minify assets

# -----------------------------------------------
# LOGIN MANAGER CONFIG
# -----------------------------------------------
lm.login_view = 'index'
lm.login_message_category = 'info'
# lm.refresh_view = 'reauthenticate'

@lm.user_loader
def load_user(userid):
	return User.get(userid)

@lm.token_loader
def load_token(token):
	max_age = app.config['REMEMBER_COOKIE_DURATION'].total_seconds()
	data = login_serializer.loads(token, max_age=max_age)
	user = User.get(data[0])
	if user and data[1] == user.password:
		return user
	return None
コード例 #25
0
from flask.ext.cache import Cache
from flask.ext.debugtoolbar import DebugToolbarExtension
from flask.ext.login import LoginManager
from flask_assets import Environment

from cancersucks.models import User

# Setup flask cache
cache = Cache()

# init flask assets
assets_env = Environment()

debug_toolbar = DebugToolbarExtension()

login_manager = LoginManager()
login_manager.login_view = "main.login"
login_manager.login_message_category = "warning"


@login_manager.user_loader
def load_user(userid):
    return User.query.get(userid)
コード例 #26
0
from flask.ext.pymongo import PyMongo
from flask.ext.login import LoginManager
from flask.ext.mail import Mail

# app imports
from config import config
from core.sessionhelpers import MongoSessionInterface


#setup for various utilities
mongo = PyMongo()
login_manager = LoginManager()
login_manager.session_protection = 'strong'
login_manager.login_view = 'users.login'
login_manager.login_message = 'Va rugam sa va logati pentru a accesa aceasta pagina!'
login_manager.login_message_category = 'alert-info'
mail = Mail()


def create_admins(app,admin):
    '''
    used in the create_app function to check if the admins need to be created and create them if needed

    INPUT: dict
    OUPUT: none

    '''
    from users.models import Users
    try:
        user = Users.get({"email": admin['email']})
    except Exception as e:
コード例 #27
0
# Create the basic Flask application
app = Flask(__name__)
app.config.from_object('config')


# Create the object-to-relational mapping engine for the application
db = SQLAlchemy(app)

# Project 5 - moved this until after the db object was created.
# Note: this should occur here.
from talent_match.models.userProfile import User


login_manager = LoginManager(app)
login_manager.login_view = 'login'
login_manager.login_message_category = 'info'
bcrypt = Bcrypt(app)
gravatar = Gravatar(app,
                    size=100,
                    rating='g',
                    default='mm',
                    force_default=False,
                    use_ssl=True,
                    base_url=None)

from talent_match import models, forms
from .views import auth, profile, index, invites, skills, categories, api, activity
from talent_match.startup import addTestData, testLoadFunction

app.createTestData = addTestData
app.testLoadFunction = testLoadFunction
コード例 #28
0
ファイル: __init__.py プロジェクト: Palisand/mlwc
from flask import Flask
from flask.ext.sqlalchemy import SQLAlchemy
from flask.ext.admin import Admin
from flask.ext.login import LoginManager
# from flask.ext.bcrypt import Bcrypt

app = Flask(__name__)
app.config.from_object('config')

db = SQLAlchemy(app)

admin = Admin(app, name='MLCW Admin', template_mode='bootstrap3')

login_manager = LoginManager()
login_manager.init_app(app)
login_manager.login_view = 'login'
login_manager.login_message_category = u'This page can only be accessed by site admins.'

# bcrypt = Bcrypt(app)

import metropolitanweightlifting.views
import metropolitanweightlifting.util.jinja_filters
コード例 #29
0
ファイル: login.py プロジェクト: feeneyp/synonyms
from flask.ext.login import LoginManager

from synonyms import app
from .database import session
from .models import User

login_manager = LoginManager()
login_manager.init_app(app)

login_manager.login_view = "login_get"
login_manager.login_message_category = "danger"

@login_manager.user_loader
def load_user(id):
    return session.query(User).get(int(id))
コード例 #30
0
from flask.ext.login import LoginManager

from application import application, models
from application.auth.oauth_classes import OAuthService
from application.models import User

__author__ = 'Chris'

import services
import routes

login_manager = LoginManager()
login_manager.init_app(app=application)
login_manager.login_view = 'login'
login_manager.login_message_category = 'alert-danger'


@login_manager.user_loader
def load_user(id):
    return User.query.get(id)


@login_manager.token_loader
def load_token(token):
    return User.query.filter_by(
        auth_token=token).first() or models.AnonymousUser()