当前位置: 首页>>代码示例>>Python>>正文


Python User.get_current方法代码示例

本文整理汇总了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'})
开发者ID:pheelixx,项目名称:konvert,代码行数:10,代码来源:views.py

示例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)
开发者ID:ChasBurg,项目名称:familytree-sample-app,代码行数:44,代码来源:auth.py

示例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)
开发者ID:pheelixx,项目名称:konvert,代码行数:25,代码来源:views.py

示例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)
开发者ID:pheelixx,项目名称:konvert,代码行数:7,代码来源:views.py


注:本文中的models.user.User.get_current方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。