本文整理汇总了Python中flask.ext.login.current_user.is_authenticated方法的典型用法代码示例。如果您正苦于以下问题:Python current_user.is_authenticated方法的具体用法?Python current_user.is_authenticated怎么用?Python current_user.is_authenticated使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类flask.ext.login.current_user
的用法示例。
在下文中一共展示了current_user.is_authenticated方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: view
# 需要导入模块: from flask.ext.login import current_user [as 别名]
# 或者: from flask.ext.login.current_user import is_authenticated [as 别名]
def view(tag_name):
criteria = {}
tag = Tag.objects.get_or_404(key=tag_name)
if request.args.get('filter', None) != 'mine' or not current_user.is_authenticated:
criteria['is_private'] = False
syntax = Syntax.objects(key=tag_name).first()
if syntax:
criteria['codes__syntax'] = syntax
else:
criteria['tags'] = tag
pastes = Paste.objects(**criteria).order_by('-updated_at')
page = get_page()
pagination = pastes.paginate(page, per_page=20)
return render_template('tags/view.html',
tag=tag,
hot_pastes=Paste.objects(is_private=False).order_by('-views')[:10],
pagination=pagination)
示例2: chat_initialize
# 需要导入模块: from flask.ext.login import current_user [as 别名]
# 或者: from flask.ext.login.current_user import is_authenticated [as 别名]
def chat_initialize():
first_words = ['True', 'False', 'For', 'While', 'If', 'Else', 'Elif', 'Undefined', 'Do', 'Virtual', 'Inline',
'Exit', 'Continue', 'Super', 'Break', 'Switch', 'Try', 'Catch', 'Class', 'Object', 'Abstract', 'Interface',
'Def', 'Var', 'Pass', 'Return', 'Static', 'Const', 'Template', 'Delete', 'Int',
'Float', 'Struct', 'Void', 'Self', 'This']
second_words = ['C', 'C++', 'Lisp', 'Python', 'Java', 'JavaScript', 'Pascal', 'Objective-C',
'C#', 'Perl', 'Ruby', 'Ada', 'Haskell', 'Octave', 'Basic', 'Fortran', 'PHP', 'R',
'Assembly', 'COBOL', 'Rust', 'Swift', 'Bash', 'Brainfuck', 'OCaml', 'Clojure']
if current_user.is_authenticated():
session['username'] = current_user.reddit_username
elif 'username' not in session or session['username'] in chat_users:
while True:
session['username'] = random.choice(first_words) + ' ' + random.choice(second_words)
if session['username'] not in chat_users:
chat_users.add(session['username'])
break
db.session.close()
示例3: executar_funcao_sat
# 需要导入模块: from flask.ext.login import current_user [as 别名]
# 或者: from flask.ext.login.current_user import is_authenticated [as 别名]
def executar_funcao_sat(funcaosat):
resultado = None
if funcaosat in FUNCOES_RESTRITAS:
if not current_user.is_authenticated:
return app.login_manager.unauthorized()
funcao = FUNCOES_RESTRITAS.get(funcaosat)
else:
funcao = FUNCOES_ABERTAS.get(funcaosat)
if not funcao:
abort(404)
form = funcao.get('form_class', EmptyForm)(request.form)
if request.method == 'POST' and form.validate():
resultado = getattr(executor, funcao.get('funcao').lower())(form)
return render_template('funcao.html',
funcao=funcao,
form=form,
resultado=resultado)
示例4: index
# 需要导入模块: from flask.ext.login import current_user [as 别名]
# 或者: from flask.ext.login.current_user import is_authenticated [as 别名]
def index():
form = PostForm()
if current_user.can(Permission.WRITE_ARTICLES) and \
form.validate_on_submit():
post = Post(body=form.body.data,
author=current_user._get_current_object())
db.session.add(post)
return redirect(url_for('.index'))
page = request.args.get('page', 1, type=int)
show_followed = False
if current_user.is_authenticated():
show_followed = bool(request.cookies.get('show_followed', ''))
if show_followed:
query = current_user.followed_posts
else:
query = Post.query
pagination = query.order_by(Post.timestamp.desc()).paginate(
page, per_page=current_app.config['FLASKY_POSTS_PER_PAGE'],
error_out=False)
posts = pagination.items
return render_template('index.html', form=form, posts=posts,
show_followed=show_followed, pagination=pagination)
示例5: before_request
# 需要导入模块: from flask.ext.login import current_user [as 别名]
# 或者: from flask.ext.login.current_user import is_authenticated [as 别名]
def before_request():
g.started_at = time.time()
g.unread_messages_count = 0
if current_user.is_authenticated:
g.unread_messages_count = current_user.user.unread_messages_count
示例6: view
# 需要导入模块: from flask.ext.login import current_user [as 别名]
# 或者: from flask.ext.login.current_user import is_authenticated [as 别名]
def view(hash_id):
bookmark = Bookmark.objects(hash_id=hash_id).get_or_404()
bookmark.views += 1
bookmark.save()
bookmark_hash_id = None
if current_user.is_authenticated and current_user.user == bookmark.user:
bookmark_hash_id = bookmark.hash_id
return render_template('bookmarks/view.html',
bookmark=bookmark,
bookmark_hash_id=bookmark_hash_id)
示例7: validate_username
# 需要导入模块: from flask.ext.login import current_user [as 别名]
# 或者: from flask.ext.login.current_user import is_authenticated [as 别名]
def validate_username(self, field):
if current_user.is_authenticated and current_user.user.username == field.data:
return True
user = User.objects(username=field.data).first()
if user:
raise ValidationError(u'用户名已被使用')
示例8: validate_email
# 需要导入模块: from flask.ext.login import current_user [as 别名]
# 或者: from flask.ext.login.current_user import is_authenticated [as 别名]
def validate_email(self, field):
if current_user.is_authenticated:
field.data = current_user.user.email
return True
if session['email']:
if session['email'] != field.data:
raise ValidationError(u'不能修改第三方登录的email地址')
user = User.objects(email=field.data).first()
if user:
raise ValidationError(u'Email地址已被使用')
示例9: before_request
# 需要导入模块: from flask.ext.login import current_user [as 别名]
# 或者: from flask.ext.login.current_user import is_authenticated [as 别名]
def before_request():
if current_user.is_authenticated:
current_user.ping()
if not current_user.confirmed and request.endpoint not in req_endpoint:
return redirect(url_for('unconfirmed'))
示例10: complete
# 需要导入模块: from flask.ext.login import current_user [as 别名]
# 或者: from flask.ext.login.current_user import is_authenticated [as 别名]
def complete(format='json'):
if not current_user.is_authenticated():
msg = _("You are not authorized to see that page")
return jsonify({'status': 'error', 'message': msg}, status=403)
query = db.session.query(Account)
filter_string = request.args.get('q', '') + '%'
query = query.filter(or_(Account.name.ilike(filter_string),
Account.fullname.ilike(filter_string)))
return jsonify(Pager(query))
示例11: session
# 需要导入模块: from flask.ext.login import current_user [as 别名]
# 或者: from flask.ext.login.current_user import is_authenticated [as 别名]
def session():
data = {
'logged_in': current_user.is_authenticated(),
'user': None
}
if current_user.is_authenticated():
data['user'] = current_user
data['api_key'] = current_user.api_key
return jsonify(data)
示例12: logged_in
# 需要导入模块: from flask.ext.login import current_user [as 别名]
# 或者: from flask.ext.login.current_user import is_authenticated [as 别名]
def logged_in():
return current_user.is_authenticated() and current_user.is_active()
示例13: is_accessible
# 需要导入模块: from flask.ext.login import current_user [as 别名]
# 或者: from flask.ext.login.current_user import is_authenticated [as 别名]
def is_accessible(self):
"""
Determines if the current user is logged in as an admin.
Returns:
A boolean indicating if the current user is an admin.
"""
if current_user.is_authenticated and current_user.admin:
return True
return False
# Defines column labels to be shared between resource views.
示例14: body_tag_args
# 需要导入模块: from flask.ext.login import current_user [as 别名]
# 或者: from flask.ext.login.current_user import is_authenticated [as 别名]
def body_tag_args():
from flask.ext.login import current_user
classes = []
args = {}
if current_user.is_authenticated():
classes.append('loggedin')
args['dataUserName'] = current_user.full_name()
args['dataUserEmail'] = current_user.email
args['dataUserId'] = current_user.id
args['class_'] = ' '.join(classes)
return args
示例15: default_analysis_nature_id
# 需要导入模块: from flask.ext.login import current_user [as 别名]
# 或者: from flask.ext.login.current_user import is_authenticated [as 别名]
def default_analysis_nature_id():
from flask.ext.login import current_user
if current_user.is_authenticated() and current_user.default_analysis_nature_id:
return current_user.default_analysis_nature_id
return 1