本文整理汇总了Python中flaskext.login.LoginManager.login_message方法的典型用法代码示例。如果您正苦于以下问题:Python LoginManager.login_message方法的具体用法?Python LoginManager.login_message怎么用?Python LoginManager.login_message使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类flaskext.login.LoginManager
的用法示例。
在下文中一共展示了LoginManager.login_message方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: login_message
# 需要导入模块: from flaskext.login import LoginManager [as 别名]
# 或者: from flaskext.login.LoginManager import login_message [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: configure_login_manager
# 需要导入模块: from flaskext.login import LoginManager [as 别名]
# 或者: from flaskext.login.LoginManager import login_message [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
示例3: dict
# 需要导入模块: from flaskext.login import LoginManager [as 别名]
# 或者: from flaskext.login.LoginManager import login_message [as 别名]
USER_NAMES = dict((u.name, u) for u in USERS.itervalues())
app = Flask(__name__)
SECRET_KEY = "yeah, not actually a secret"
DEBUG = True
app.config.from_object(__name__)
login_manager = LoginManager()
login_manager.anonymous_user = Anonymous
login_manager.login_view = "login"
login_manager.login_message = u"Please log in to access this page."
login_manager.refresh_view = "reauth"
@login_manager.user_loader
def load_user(id):
return USERS.get(int(id))
login_manager.setup_app(app)
@app.route("/")
def index():
return render_template("index.html")
示例4: page_not_found
# 需要导入模块: from flaskext.login import LoginManager [as 别名]
# 或者: from flaskext.login.LoginManager import login_message [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
def email(self):
示例5: create_app
# 需要导入模块: from flaskext.login import LoginManager [as 别名]
# 或者: from flaskext.login.LoginManager import login_message [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
def templated(template=None):
示例6: FileHandler
# 需要导入模块: from flaskext.login import LoginManager [as 别名]
# 或者: from flaskext.login.LoginManager import login_message [as 别名]
if not app.debug:
import logging
from logging import FileHandler
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
file_handler = FileHandler('%s/app.logger.log' % app.config['APPROOT'])
file_handler.setLevel(logging.WARNING)
file_handler.setFormatter(formatter)
app.logger.addHandler(file_handler)
# Auth
from flaskext.login import LoginManager
from user.models import User
login_manager = LoginManager()
login_manager.setup_app(app)
login_manager.login_message = u'请先登录'
login_manager.login_view = 'user.login'
@login_manager.user_loader
def load_user(user_id):
return User.query.get(user_id)
# Principal 权限控制器
from user.models import User
from flaskext.principal import Principal, identity_loaded, RoleNeed, \
UserNeed
principals = Principal(app)
@identity_loaded.connect_via(app)
def on_identity_loaded(sender, identity):
user = User.query.get(identity.name)
示例7: file_string
# 需要导入模块: from flaskext.login import LoginManager [as 别名]
# 或者: from flaskext.login.LoginManager import login_message [as 别名]
g.deploy = file_string(os.path.join(os.path.dirname(__file__), 'deploy'))
except IOError, e:
g.deploy = ''
from gcm.models import Person
from gcm.extensions import db
db.init_app(app)
login_manager = LoginManager()
AnonymousUser.json = {}
AnonymousUser.id = None
AnonymousUser.graph_id = None
login_manager.anonymous_user = AnonymousUser
# login_manager.login_view = ".login"
login_manager.login_message = u"This content is not available."
@login_manager.user_loader
def load_user(id):
return Person.query.filter_by(id=int(id)).first()
login_manager.setup_app(app)
from gcm.views import *
if __name__ == '__main__':
app.run(host='0.0.0.0', port=5066, debug=True)