本文整理汇总了Python中models.user.User.get_current方法的典型用法代码示例。如果您正苦于以下问题:Python User.get_current方法的具体用法?Python User.get_current怎么用?Python User.get_current使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.user.User
的用法示例。
在下文中一共展示了User.get_current方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: download
# 需要导入模块: from models.user import User [as 别名]
# 或者: from models.user.User import get_current [as 别名]
def download(id):
user = User.get_current()
if user.id == g.user.id:
file = File.query.get(id)
if file is not None:
filename = file.name.encode('cp1251')
return send_file(file.path, as_attachment=True, attachment_filename=filename)
return jsonify({'result': 'oops, fail'})
示例2: oauth
# 需要导入模块: from models.user import User [as 别名]
# 或者: from models.user.User import get_current [as 别名]
def oauth():
if 'error' in request.args:
# TBD: log error_description
# print "error"
return render_template("redirect.html",callback=url_for('auth.down'))
if not 'code' in request.args:
# TBD: log the error
# print "no code"
return render_template("redirect.html",callback=url_for('auth.down'))
code = request.args['code']
uri = session['discovery']['links']['http://oauth.net/core/2.0/endpoint/token']['href']
try:
params = {
'grant_type':'authorization_code',
'code':code,
'client_id':key,
}
data = urllib.urlencode(params)
response = eval(urllib.urlopen(uri,data).read().replace('null', 'None'))
access_token = response['access_token']
except:
return render_template("redirect.html",callback=url_for('auth.down'))
# store session information
session['app'] = True
session['access_token'] = access_token
session['ajax'] = False
# get current user ID for session
user = User.get_current()
session['userID'] = user.api_id
# TBD: callback
callback = request.args.get('callback',default='/')
if callback == '/':
callback = '/ancestors/' + session['userID']
return render_template('redirect.html',callback=callback)
示例3: file
# 需要导入模块: from models.user import User [as 别名]
# 或者: from models.user.User import get_current [as 别名]
def file(id):
file = File.query.get(id)
if file is None:
return error_not_found(error='File not found')
user = User.get_current()
if user.is_anonymous() or file.user_id != user.id:
return error_forbidden(error='Have not permissions')
settings = file.get_settings()
selected = settings.keys()[0]
jsoned = json.dumps({
'user': user.to_json(),
'file': file.to_json(),
'settings': settings,
'selected': selected,
'statistics': file.get_statistics()
})
return render_template('index.html',
view='view/file.html',
user=user,
file=file,
settings=settings,
selected=selected,
jsoned=jsoned)
示例4: user
# 需要导入模块: from models.user import User [as 别名]
# 或者: from models.user.User import get_current [as 别名]
def user(id):
user = User.get_current()
if user.is_anonymous() or user.id != id:
return error_forbidden(error='Have not permissions')
return render_template('index.html', view='view/user.html', user=user)