本文整理汇总了Python中flaskext.login.LoginManager.login_view方法的典型用法代码示例。如果您正苦于以下问题:Python LoginManager.login_view方法的具体用法?Python LoginManager.login_view怎么用?Python LoginManager.login_view使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类flaskext.login.LoginManager
的用法示例。
在下文中一共展示了LoginManager.login_view方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: login_message
# 需要导入模块: from flaskext.login import LoginManager [as 别名]
# 或者: from flaskext.login.LoginManager import login_view [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 login_view [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 login_view [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 login_view [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 login_view [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 login_view [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 login_view [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 login_view [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: Flask
# 需要导入模块: from flaskext.login import LoginManager [as 别名]
# 或者: from flaskext.login.LoginManager import login_view [as 别名]
# shut up useless SA warning:
import warnings;
warnings.filterwarnings('ignore', 'Unicode type received non-unicode bind param value.')
from sqlalchemy.exc import SAWarning
warnings.filterwarnings('ignore', category=SAWarning)
from migrate.versioning.util import construct_engine
from flask import Flask
from flaskext.login import LoginManager, current_user
from flaskext.sqlalchemy import SQLAlchemy
from grano import default_settings
app = Flask(__name__)
app.config.from_object(default_settings)
app.config.from_envvar('GRANO_SETTINGS', silent=True)
db = SQLAlchemy(app)
login_manager = LoginManager()
login_manager.setup_app(app)
login_manager.login_view = 'account.login'
示例10: is_active
# 需要导入模块: from flaskext.login import LoginManager [as 别名]
# 或者: from flaskext.login.LoginManager import login_view [as 别名]
self.id = id
self.name = name
self.active = active
def is_active(self):
return self.active
class Anonymous(AnonymousUser):
name = u"Anonymous"
login_manager = LoginManager()
login_manager.anonymous_user = Anonymous
login_manager.login_view = "account"
login_manager.login_message = u"Please log in to access this page."
login_manager.refresh_view = "reauth"
from ims import app
login_manager.setup_app(app)
@login_manager.user_loader
def load_user(id):
try:
return LoginUser(int(id), User.query.get(id).username)
except:
return None
示例11: SMTPHandler
# 需要导入模块: from flaskext.login import LoginManager [as 别名]
# 或者: from flaskext.login.LoginManager import login_view [as 别名]
ADMINS = app.config.get('ADMINS', '')
if not app.debug and ADMINS:
mail_handler = SMTPHandler('127.0.0.1',
'[email protected]',
ADMINS, 'error')
mail_handler.setLevel(logging.ERROR)
app.logger.addHandler(mail_handler)
from logging.handlers import RotatingFileHandler
from logging import Formatter
def setup_logging(app):
log_file_path = app.config.get('LOG_FILE')
log_level = app.config.get('LOG_LEVEL', logging.WARN)
if log_file_path:
file_handler = RotatingFileHandler(log_file_path)
file_handler.setFormatter(Formatter(
'%(name)s:%(levelname)s:[%(asctime)s] %(message)s '
'[in %(pathname)s:%(lineno)d]'
))
file_handler.setLevel(log_level)
app.logger.addHandler(file_handler)
logger = logging.getLogger('pybossa')
logger.setLevel(log_level)
logger.addHandler(file_handler)
login_manager = LoginManager()
login_manager.login_view = "/account/signin"
login_manager.login_message = u"Please sign in to access this page."
app = create_app()
示例12: LoginManager
# 需要导入模块: from flaskext.login import LoginManager [as 别名]
# 或者: from flaskext.login.LoginManager import login_view [as 别名]
# encoding=utf-8
from flask import g
from flaskext.login import LoginManager, AnonymousUser
from calepin.models import Blog
login_manager = LoginManager()
AnonymousUser.json = {}
login_manager.anonymous_user = AnonymousUser
login_manager.login_view = "frontend.site"
@login_manager.user_loader
def get_user(id):
return Blog.query.get(id)
示例13: page_not_found
# 需要导入模块: from flaskext.login import LoginManager [as 别名]
# 或者: from flaskext.login.LoginManager import login_view [as 别名]
@app.errorhandler(404)
def page_not_found(e):
return render_template('cms_404.html'), 404
@app.errorhandler(500)
def page_not_found(e):
return render_template('cms_500.html'), 500
########################## User Authentication and Registration ##########################
login_manager = LoginManager()
login_manager.setup_app(app)
login_manager.login_view = "/login/"
login_manager.login_message = u"You need to login to access this resource."
class User(UserMixin):
def __init__(self, email, key_id):
self.name = email
self.id = key_id
self.user = db.get(self.id)
def is_active(self):
if self.user.active == True:
return True
else:
return False
示例14: Flask
# 需要导入模块: from flaskext.login import LoginManager [as 别名]
# 或者: from flaskext.login.LoginManager import login_view [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')]
'''
示例15: create_app
# 需要导入模块: from flaskext.login import LoginManager [as 别名]
# 或者: from flaskext.login.LoginManager import login_view [as 别名]
app = create_app()
app.secret_key = str(uuid.uuid4())
login_manager = LoginManager()
login_manager.setup_app(app)
@login_manager.user_loader
def load_user(userid):
return HubUser.find(userid)
#load up some configuration settings
app.config.from_object('hubology.settings')
login_manager.login_view = "/sign-in"
login_manager.login_message = u"Please sign in to access hub-ology."
#Setup 404 handler
@app.errorhandler(404)
def page_not_found(e):
return render_template('404.html'), 404
#Setup 500 handler
@app.errorhandler(500)
def internal_server_error(e):
if current_user:
from hubology.views.sign_out import sign_out
sign_out()
return render_template('500.html'), 500