本文整理汇总了Python中flaskext.login.LoginManager.setup_app方法的典型用法代码示例。如果您正苦于以下问题:Python LoginManager.setup_app方法的具体用法?Python LoginManager.setup_app怎么用?Python LoginManager.setup_app使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类flaskext.login.LoginManager
的用法示例。
在下文中一共展示了LoginManager.setup_app方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: login_message
# 需要导入模块: from flaskext.login import LoginManager [as 别名]
# 或者: from flaskext.login.LoginManager import setup_app [as 别名]
def login_message(app):
lm = LoginManager()
lm.login_view = "login"
lm.login_message = u"Log in or the owl will eat you."
lm.setup_app(app)
lm.unauthorized()
assert u"Log in or the owl will eat you." in get_flashed_messages()
示例2: unauthorized_redirect
# 需要导入模块: from flaskext.login import LoginManager [as 别名]
# 或者: from flaskext.login.LoginManager import setup_app [as 别名]
def unauthorized_redirect(app):
lm = LoginManager()
lm.login_view = "login"
lm.setup_app(app)
res = lm.unauthorized()
assert res.headers["Location"] == "/login?next=%2F"
assert LOGIN_MESSAGE in get_flashed_messages()
示例3: setup_interactive
# 需要导入模块: from flaskext.login import LoginManager [as 别名]
# 或者: from flaskext.login.LoginManager import setup_app [as 别名]
def setup_interactive(app):
lm = LoginManager()
lm.login_view = "login"
lm.user_loader(get_user)
@lm.unauthorized_handler
def unauth():
return "UNAUTHORIZED!"
lm.setup_app(app)
示例4: unauthorized_callback
# 需要导入模块: from flaskext.login import LoginManager [as 别名]
# 或者: from flaskext.login.LoginManager import setup_app [as 别名]
def unauthorized_callback(app):
lm = LoginManager()
lm.login_view = "login"
@lm.unauthorized_handler
def unauth():
return "UNAUTHORIZED!"
lm.setup_app(app)
assert lm.unauthorized() == "UNAUTHORIZED!"
assert len(get_flashed_messages()) == 0
示例5: logging_in
# 需要导入模块: from flaskext.login import LoginManager [as 别名]
# 或者: from flaskext.login.LoginManager import setup_app [as 别名]
def logging_in(app):
lm = LoginManager()
lm.login_view = "login"
lm.user_loader(get_user)
lm.setup_app(app)
app.preprocess_request()
assert not current_user.is_authenticated()
assert current_user.is_anonymous()
with assert_fired(user_logged_in):
login_user(notch)
assert current_user.name == u"Notch"
assert session["user_id"] == u"1"
示例6: configure_login_manager
# 需要导入模块: from flaskext.login import LoginManager [as 别名]
# 或者: from flaskext.login.LoginManager import setup_app [as 别名]
def configure_login_manager(app):
login_manager = LoginManager()
login_manager.setup_app(app)
login_manager.login_view = "login"
login_manager.login_message = u"You must login!"
@login_manager.user_loader
def load_user(user_id):
beaker_session = request.environ['beaker.session']
beaker_user_id = beaker_session['user_id']
#user = User()
#user.id = beaker_user_id #use user_id in beaker!
return user
示例7: create_users_blueprint
# 需要导入模块: from flaskext.login import LoginManager [as 别名]
# 或者: from flaskext.login.LoginManager import setup_app [as 别名]
def create_users_blueprint(app, _db, login_redirect_view='main'):
global db
db = _db
from .models import User
from .forms import LoginForm, RegisterForm
users_blueprint = Blueprint('users', __name__, template_folder='templates', static_folder='static')
bcrypt = Bcrypt(app)
login_manager = LoginManager()
login_manager.setup_app(app)
login_manager.login_view = 'users.login'
@login_manager.user_loader
def user_loader(user_id):
return User.query.get(user_id)
@users_blueprint.route('/login/', methods=['GET', 'POST'])
def login():
form = LoginForm()
if form.validate_on_submit():
user = User.query.filter_by(email=form.email.data).first()
if user is None or bcrypt.check_password_hash(user.password, form.password):
flash("Invalid email or password", "error")
else:
login_user(user)
flash("Login successful", 'success')
return redirect(url_for(login_redirect_view))
return render_template('users/login.html', form=form)
@users_blueprint.route('/logout/')
@login_required
def logout():
logout_user()
return redirect(url_for(login_redirect_view))
@users_blueprint.route('/register/', methods=['GET', 'POST'])
def register():
form = RegisterForm()
if form.validate_on_submit():
user = User(form.email.data, bcrypt.generate_password_hash(form.password.data))
db.session.add(user)
db.session.commit()
login_user(user)
flash("Login successful")
return redirect(url_for(login_redirect_view))
return render_template('users/register.html', form=form)
return users_blueprint
示例8: init_app
# 需要导入模块: from flaskext.login import LoginManager [as 别名]
# 或者: from flaskext.login.LoginManager import setup_app [as 别名]
def init_app(self, app):
if app is None:
return
blueprint = Blueprint(AUTH_CONFIG_KEY.lower(), __name__)
config = default_config.copy()
try:
config.update(app.config.get(AUTH_CONFIG_KEY, {}))
except:
pass
app.config[AUTH_CONFIG_KEY] = config
app.logger.debug("Auth Configuration: %s" % config)
# setup the login manager extension
login_manager = LoginManager()
login_manager.anonymous_user = Anonymous
login_manager.login_view = config[LOGIN_VIEW_KEY]
login_manager.setup_app(app)
# get some things form the config
Provider = get_class_from_config(AUTH_PROVIDER_KEY, config)
Encryptor = get_class_from_config(PASSWORD_ENCRYPTOR_KEY, config)
Form = get_class_from_config(LOGIN_FORM_CLASS_KEY, config)
# create the service and auth provider and add it to the app
# so it can be referenced elsewhere
app.login_manager = login_manager
app.password_encryptor = Encryptor(config[SALT_KEY])
app.auth_provider = Provider(Form)
DEBUG_LOGIN = "User %s logged in. Redirecting to: %s"
ERROR_LOGIN = "Unsuccessful auth attempt: %s. Redirecting to: %s"
DEBUG_LOGOUT = "User logged out, redirecting to: %s"
FLASH_INACTIVE = "Inactive user"
@login_manager.user_loader
def load_user(id):
try:
return user_service.get_user_with_id(id)
except Exception, e:
current_app.logger.error("Error getting user: %s" % e)
return None
示例9: LoginManager
# 需要导入模块: from flaskext.login import LoginManager [as 别名]
# 或者: from flaskext.login.LoginManager import setup_app [as 别名]
from flask.views import MethodView
from flaskext.login import LoginManager, login_required, login_user, logout_user
from flask.ext.sqlalchemy import *
import ldap
from lib.ldapuser import LDAPUser
import json
from apps.addressbook.addressbook import addressbook
login_manager = LoginManager()
app = Flask(__name__)
app.debug = True
app.secret_key = 'foobar'
login_manager.setup_app(app)
login_manager.login_view = 'login'
#app.config.from_pyfile('test1.cfg')
#db = SQLAlchemy(app)
server = 'ldap://ford.fachschaft.cs.uni-kl.de'
l = ldap.initialize(server)
@login_manager.user_loader
def load_user(user_id):
user = LDAPUser(l, user_id)
if user.get_id:
return user
else:
return None
示例10: LoginManager
# 需要导入模块: from flaskext.login import LoginManager [as 别名]
# 或者: from flaskext.login.LoginManager import setup_app [as 别名]
import json
from urllib import urlencode
from urlparse import parse_qs, parse_qsl, urlsplit, urlunsplit
from flask import redirect, request, session, url_for
from flaskext.login import LoginManager, login_user, logout_user
import oauth2
import requests
from makerbase import app
from makerbase.models import User
login_manager = LoginManager()
login_manager.setup_app(app, add_context_processor=True)
login_manager.user_loader(User.get)
@app.route('/signin/github')
def signin_github():
try:
next_url = request.args['next']
except KeyError:
pass
else:
session['signin_next_url'] = next_url
urlparts = urlsplit(request.base_url)
params = {
'client_id': app.config['GITHUB_CLIENT_ID'],
'redirect_url': urlunsplit((urlparts.scheme, urlparts.netloc, url_for('complete_github'), None, None)),
示例11: Flask
# 需要导入模块: from flaskext.login import LoginManager [as 别名]
# 或者: from flaskext.login.LoginManager import setup_app [as 别名]
from flask import Flask, redirect, request, url_for
www = Flask(__name__)
www.config.from_pyfile('../config.cfg')
from flaskext.login import LoginManager, current_user
login = LoginManager()
login.setup_app(www, add_context_processor=True)
login.login_view = 'login'
from flaskext.sqlalchemy import SQLAlchemy
db = SQLAlchemy(www)
from flaskext.mail import Mail
mail = Mail(www)
from flaskext.bcrypt import Bcrypt
bcrypt = Bcrypt(www)
from www import tweaks
from www import main
from www import user
from www.menu import register
from werkzeug.utils import import_string
from flask.ext import admin
from flask.ext.admin.datastore.sqlalchemy import SQLAlchemyDatastore
'''
example config line:
WWW_BLUEPRINTS=[('www.blog',{'url_prefix': '/blog'}, ('blog', '/blog')),\
('www.contact',{'url_prefix': '/contact'}, ('contact', '/contact')]
'''
示例12: unauthorized_401
# 需要导入模块: from flaskext.login import LoginManager [as 别名]
# 或者: from flaskext.login.LoginManager import setup_app [as 别名]
def unauthorized_401(app):
lm = LoginManager()
lm.setup_app(app)
with raises(Unauthorized):
with assert_fired(user_unauthorized):
res = lm.unauthorized()
示例13: lm_creation_and_setup
# 需要导入模块: from flaskext.login import LoginManager [as 别名]
# 或者: from flaskext.login.LoginManager import setup_app [as 别名]
def lm_creation_and_setup(app):
lm = LoginManager()
lm.setup_app(app)
assert app.login_manager is lm
assert lm._load_user in app.before_request_funcs[None]
assert lm._update_remember_cookie in app.after_request_funcs[None]
示例14: LoginManager
# 需要导入模块: from flaskext.login import LoginManager [as 别名]
# 或者: from flaskext.login.LoginManager import setup_app [as 别名]
import os
from flaskext.login import LoginManager
from flaskext.openid import OpenID
from config import basedir
lm = LoginManager()
lm.setup_app(app)
oid = OpenID(app, os.path.join(basedir, 'tmp'))
示例15: Flask
# 需要导入模块: from flaskext.login import LoginManager [as 别名]
# 或者: from flaskext.login.LoginManager import setup_app [as 别名]
from __future__ import with_statement
import json
from contextlib import closing
from flask import Flask, render_template, g, request, session, flash, redirect, url_for, get_flashed_messages
from flaskext.login import LoginManager, current_user, login_user, logout_user
from flaskext.wtf import Form, PasswordField, TextField, validators
from models import db, User, ListPage
VIMES = Flask(__name__)
VIMES.config.from_object(__name__)
VIMES.config.from_envvar('VIMES_SETTINGS')
db.init_app(VIMES)
login_manager = LoginManager()
login_manager.setup_app(VIMES)
@login_manager.user_loader
def load_user(userid):
return User.query.filter_by(id=userid).first()
if VIMES.config['SINGLE_USER']:
multi_user_path = ''
else:
multi_user_path = '/<username>'
#Forms
class LoginForm(Form):
username = TextField('Username', [validators.Required()])
password = PasswordField('Password', [validators.Required()])