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


Python Account.authorize方法代码示例

本文整理汇总了Python中models.account.Account.authorize方法的典型用法代码示例。如果您正苦于以下问题:Python Account.authorize方法的具体用法?Python Account.authorize怎么用?Python Account.authorize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在models.account.Account的用法示例。


在下文中一共展示了Account.authorize方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: list

# 需要导入模块: from models.account import Account [as 别名]
# 或者: from models.account.Account import authorize [as 别名]
def list():
    """List faxes"""

    v = request.values.get

    account_id = Account.authorize(v('api_key'))
    if not account_id:
        return jsonify(api_error('API_UNAUTHORIZED')), 401

    try:
        page = int(v('page', 1))
        if page < 1:
            raise
    except:
        return jsonify(api_error('INCOMING_BAD_PAGINATION_VALUE')), 400


    faxes = IncomingFax.query.filter_by(account_id= account_id)
    faxes = faxes.order_by(IncomingFax.create_date.desc()).paginate(page, 20,
            False)

    return jsonify({
        'page':     faxes.page,
        'pages':    faxes.pages,
        'per_page': faxes.per_page,
        'total':    faxes.total,
        'has_next': faxes.has_next,
        'has_prev': faxes.has_prev,
        'faxes':    [fax.public_data() for fax in faxes.items]
    })
开发者ID:lyonbros,项目名称:faxrobot,代码行数:32,代码来源:incoming.py

示例2: restart

# 需要导入模块: from models.account import Account [as 别名]
# 或者: from models.account.Account import authorize [as 别名]
def restart(access_key):
    """Restarts a failed job"""

    account_id = Account.authorize(request.values.get('api_key'))

    jobs = Job.query.filter_by(access_key = access_key)
    job = jobs.first()
    
    if job == None or not account_id or not account_id == job.account_id:
        return jsonify(api_error('API_UNAUTHORIZED')), 401

    if not job.failed:
        return jsonify(api_error('JOBS_NOT_RESTARTABLE')), 400

    if job.data_deleted:
        return jsonify(api_error('JOBS_DATA_DELETED')), 400

    ip = fix_ip(request.headers.get('x-forwarded-for', request.remote_addr))

    job.ip_address = ip
    job.failed = 0
    job.fail_code = 0
    job.status = 'queued'
    db.session.commit()
    redis_conn = Redis.from_url(os.environ.get('REDIS_URI'))
    q = Queue(connection=redis_conn)
    q.enqueue_call(func=send_fax, args=(job.id,), timeout=600)

    return jsonify(job.public_data())
开发者ID:objcguy,项目名称:faxrobot,代码行数:31,代码来源:jobs.py

示例3: delete

# 需要导入模块: from models.account import Account [as 别名]
# 或者: from models.account.Account import authorize [as 别名]
def delete():
    """Delete an incoming fax"""

    from library.mailer import email_admin
    from boto.s3.connection import S3Connection
    from boto.s3.key import Key

    v = request.values.get

    access_key = v('access_key')
    account_id = Account.authorize(v('api_key'))

    if not account_id:
        return jsonify(api_error('API_UNAUTHORIZED')), 401

    faxes = IncomingFax.query.filter_by(access_key = access_key)
    fax = faxes.first()

    db.session.delete(fax)
    db.session.commit()

    try:
        conn = S3Connection(os.environ.get('AWS_ACCESS_KEY'),
                            os.environ.get('AWS_SECRET_KEY'))
        bucket = conn.get_bucket(os.environ.get('AWS_S3_BUCKET'))
        k = Key(bucket)
        k.key ='incoming/' + access_key + '/fax.pdf'
        k.delete()
    except:
        email_admin("AWS S3 connect fail for fax deletion: %s" % access_key)

    return jsonify({"success": True})
开发者ID:lyonbros,项目名称:faxrobot,代码行数:34,代码来源:incoming.py

示例4: transactions

# 需要导入模块: from models.account import Account [as 别名]
# 或者: from models.account.Account import authorize [as 别名]
def transactions():
    """List transactions"""

    v = request.values.get

    page = int(v('page', 1))

    account_id = Account.authorize(v('api_key'))
    if not account_id:
        return jsonify(api_error('API_UNAUTHORIZED')), 401

    account = Account.query.get(account_id)

    res = Transaction.query.filter_by(account_id= account_id)
    res = res.order_by(Transaction.create_date.desc()).paginate(page, 15, False)

    return jsonify({
        'page':         res.page,
        'pages':        res.pages,
        'per_page':     res.per_page,
        'total':        res.total,
        'has_next':     res.has_next,
        'has_prev':     res.has_prev,
        'transactions': [trans.public_data() for trans in res.items]
    })
开发者ID:lyonbros,项目名称:faxrobot,代码行数:27,代码来源:accounts.py

示例5: remove_card

# 需要导入模块: from models.account import Account [as 别名]
# 或者: from models.account.Account import authorize [as 别名]
def remove_card():
    """Removes stored credit card info from the account"""

    from datetime import datetime
    import json
    import stripe

    stripe.api_key = os.environ.get('STRIPE_SECRET_KEY')

    account_id = Account.authorize(request.values.get('api_key'))
    if not account_id:
        return jsonify(api_error('API_UNAUTHORIZED')), 401

    account = Account.query.get(account_id)

    if account.stripe_token and account.stripe_card:
        try:
            customer = stripe.Customer.retrieve(account.stripe_token)
            customer.sources.retrieve(account.stripe_card).delete()
        except:
            pass # oh well, whatever. fuck it.

    account.stripe_token = None
    account.stripe_card = None
    account.last4 = None
    account.auto_recharge = 0
    account.mod_date = datetime.now()
    db.session.commit()

    return jsonify(account.public_data())
开发者ID:lyonbros,项目名称:faxrobot,代码行数:32,代码来源:accounts.py

示例6: list

# 需要导入模块: from models.account import Account [as 别名]
# 或者: from models.account.Account import authorize [as 别名]
def list():
    """List faxes"""

    v = request.values.get

    account_id = Account.authorize(v('api_key'))
    if not account_id:
        return jsonify(api_error('API_UNAUTHORIZED')), 401

    try:
        page = int(v('page', 1))
        if page < 1:
            raise
    except:
        return jsonify(api_error('JOBS_BAD_PAGINATION_VALUE')), 400

    if v('filter'):
        jobs = Job.query.filter_by(account_id= account_id, status= v('filter'))
    else:
        jobs = Job.query.filter_by(account_id= account_id)
    jobs = jobs.order_by(Job.create_date.desc()).paginate(page, 20, False)

    return jsonify({
        'page':     jobs.page,
        'pages':    jobs.pages,
        'per_page': jobs.per_page,
        'total':    jobs.total,
        'has_next': jobs.has_next,
        'has_prev': jobs.has_prev,
        'jobs':     [job.public_data() for job in jobs.items]
    })
开发者ID:objcguy,项目名称:faxrobot,代码行数:33,代码来源:jobs.py

示例7: get

# 需要导入模块: from models.account import Account [as 别名]
# 或者: from models.account.Account import authorize [as 别名]
def get():
    """Gets the account information, provided a correct api_key is specified."""
    account_id = Account.authorize(request.values.get('api_key'))
    if account_id == None:
        return jsonify(api_error('API_UNAUTHORIZED')), 401

    account = Account.query.get(account_id)

    return jsonify(account.public_data())
开发者ID:lyonbros,项目名称:faxrobot,代码行数:11,代码来源:accounts.py

示例8: get_by_id

# 需要导入模块: from models.account import Account [as 别名]
# 或者: from models.account.Account import authorize [as 别名]
def get_by_id(id):
    """Get the status of a job by id"""

    account_id = Account.authorize(request.values.get('api_key'))

    jobs = Job.query.filter_by(id = id)
    job = jobs.first()

    if job == None or not account_id or job.account_id != account_id:
        return jsonify(api_error('API_UNAUTHORIZED')), 401

    return jsonify(job.public_data())
开发者ID:objcguy,项目名称:faxrobot,代码行数:14,代码来源:jobs.py

示例9: get

# 需要导入模块: from models.account import Account [as 别名]
# 或者: from models.account.Account import authorize [as 别名]
def get(access_key):
    """Get the status of a job"""

    account_id = Account.authorize(request.values.get('api_key'))

    jobs = Job.query.filter_by(access_key = access_key)
    job = jobs.first()

    if job == None or (job.account_id != 0 and (not account_id or \
            account_id != job.account_id)):
        return jsonify(api_error('API_UNAUTHORIZED')), 401

    return jsonify(job.public_data())
开发者ID:objcguy,项目名称:faxrobot,代码行数:15,代码来源:jobs.py

示例10: delete

# 需要导入模块: from models.account import Account [as 别名]
# 或者: from models.account.Account import authorize [as 别名]
def delete(access_key):
    """Deletes data associated with a job."""

    account_id = Account.authorize(request.values.get('api_key'))

    jobs = Job.query.filter_by(access_key = access_key)
    job = jobs.first()
    
    if job == None or (job.account_id != 0 and (not account_id or \
            account_id != job.account_id)):
        return jsonify(api_error('API_UNAUTHORIZED')), 401

    if not job.status == 'ready' and not job.status == 'sent' and \
            not job.status == 'failed':
        return jsonify(api_error('JOBS_CANNOT_DELETE_NOW')), 401   

    job.delete_data()

    return jsonify(job.public_data())
开发者ID:objcguy,项目名称:faxrobot,代码行数:21,代码来源:jobs.py

示例11: reset_api_key

# 需要导入模块: from models.account import Account [as 别名]
# 或者: from models.account.Account import authorize [as 别名]
def reset_api_key():
    """Resets the API key for an account"""

    from library.mailer import email_api_key_change
    from datetime import datetime

    account_id = Account.authorize(request.values.get('api_key'))
    if not account_id:
        return jsonify(api_error('API_UNAUTHORIZED')), 401

    account = Account.query.get(account_id)
    if account.password != password_hash(request.values.get('password')):
        return jsonify(api_error('ACCOUNTS_LOGIN_ERROR')), 401

    account.api_key = random_hash("%s%s" % (account.email, account.password))
    account.mod_date = datetime.now()
    db.session.commit()

    email_api_key_change(account)

    return jsonify({
        'api_key': account.api_key
    })
开发者ID:lyonbros,项目名称:faxrobot,代码行数:25,代码来源:accounts.py

示例12: deprovision

# 需要导入模块: from models.account import Account [as 别名]
# 或者: from models.account.Account import authorize [as 别名]
def deprovision():
    """Derovision a Phaxio fax number"""

    from library.mailer import email_registration

    ip = fix_ip(request.headers.get('x-forwarded-for', request.remote_addr))

    account_id = Account.authorize(request.values.get('api_key'))
    if account_id == None:
        return jsonify(api_error('API_UNAUTHORIZED')), 401

    account = Account.query.get(account_id)

    if len(account.incoming_numbers) == 0:
        return jsonify(api_error('INCOMING_CANNOT_REMOVE')), 400

    if not delete_number_from_phaxio(account.incoming_numbers[0].fax_number):
        return jsonify(api_error('INCOMING_FAILED_TO_DEPROVISION')), 500

    db.session.delete(account.incoming_numbers[0])
    db.session.commit()

    return jsonify({"success": True})
开发者ID:lyonbros,项目名称:faxrobot,代码行数:25,代码来源:incoming.py

示例13: view

# 需要导入模块: from models.account import Account [as 别名]
# 或者: from models.account.Account import authorize [as 别名]
def view():
    """View a fax"""

    import urllib
    from library.mailer import email_admin

    v = request.values.get

    ip = fix_ip(request.headers.get('x-forwarded-for', request.remote_addr))

    account_id = Account.authorize(v('api_key'))
    if not account_id:
        return jsonify(api_error('API_UNAUTHORIZED')), 401

    try:
        faxes = IncomingFax.query.filter_by(access_key = v('access_key'))
        fax = faxes.first()

        f = urllib.urlopen(fax.hosted_url)
        data = f.read()

        response = make_response(data)
        response.headers['Content-Type'] = 'application/pdf'
        response.headers['Content-Disposition'] = 'attachment; filename=fax.pdf'
        return response
    except:
        msg = ("<h1>Something weird is going on.</h1>"
               "<p><strong>endpoint:</strong> /incoming/view<br/>"
               "<strong>api_key:</strong> %s<br/>"
               "<strong>access_key:</strong> %s<br/>"
               "<strong>ip:</strong> %s<br/>") % (v('api_key'), v('access_key'),
               ip)

        email_admin(msg, "Security alert!")

        return ("<h1>File not found.</h1><p>Apologies for the glitch! Our staff"
                " has been notified in order to better assist you.</p>"), 401
开发者ID:lyonbros,项目名称:faxrobot,代码行数:39,代码来源:incoming.py

示例14: create

# 需要导入模块: from models.account import Account [as 别名]
# 或者: from models.account.Account import authorize [as 别名]
def create():
    """Creates a new outgoing fax"""

    account_id = Account.authorize(request.values.get('api_key'))
    if account_id == None:
        return jsonify(api_error('API_UNAUTHORIZED')), 401

    ip = fix_ip(request.headers.get('x-forwarded-for', request.remote_addr))

    if request.method == 'POST':

        uploaded_file = request.files['file']
        v = request.values.get

        if uploaded_file or v('body'):

            data = {
                'account_id':       account_id,
                'ip_address':       ip,
                'destination':      v('destination'),
                'send_authorized':  v('send_authorized', 0),
                'cover':            v('cover', 0),
                'cover_name':       v('cover_name'),
                'cover_address':    v('cover_address'),
                'cover_city':       v('cover_city'),
                'cover_state':      v('cover_state'),
                'cover_zip':        v('cover_zip'),
                'cover_country':    v('cover_country'),
                'cover_phone':      v('cover_phone'),
                'cover_email':      v('cover_email'),
                'cover_company':    v('cover_company'),
                'cover_to_name':    v('cover_to_name'),
                'cover_cc':         v('cover_cc'),
                'cover_subject':    v('cover_subject'),
                'cover_status':     v('cover_status','review'),
                'cover_comments':   v('cover_comments'),
                'callback_url':     v('callback_url')
            }
            if uploaded_file:
                data['filename']    = uploaded_file.filename
            else:
                data['body']        = v('body')

            o(data)

            try:
                job = Job(**data);
                job.validate()
            except ValidationError, err:
                return jsonify(api_error(err.ref)), 400

            db.session.add(job)
            db.session.commit()

            if uploaded_file:
                binary = uploaded_file.stream.read()
            else:
                binary = job.body.replace("\r\n", "\n").encode('utf-8')

            redis_conn = Redis.from_url(current_app.config['REDIS_URI'])
            q = Queue('high', connection=redis_conn)
            q.enqueue_call(func=initial_process, args=(job.id, binary),
                           timeout=300)

            return jsonify(job.public_data())
        else:
            return jsonify(api_error("JOBS_NO_ATTACHMENT")), 400
开发者ID:objcguy,项目名称:faxrobot,代码行数:69,代码来源:jobs.py

示例15: update

# 需要导入模块: from models.account import Account [as 别名]
# 或者: from models.account.Account import authorize [as 别名]
def update():
    """Updates an account"""

    from datetime import datetime
    import stripe
    import traceback
    import json
    from library.mailer import email_password_change

    stripe.api_key = os.environ.get('STRIPE_SECRET_KEY')

    ip = fix_ip(request.headers.get('x-forwarded-for', request.remote_addr))

    account_id = Account.authorize(request.values.get('api_key'))
    if not account_id:
        return jsonify(api_error('API_UNAUTHORIZED')), 401

    account = Account.query.get(account_id)

    v = request.values.get

    try:
        if v('email'):

            existing = Account.query.filter_by(email=v('email'))

            if existing.first() and not existing.first().id == account.id:
                raise ValidationError('ACCOUNTS_EMAIL_TAKEN')

            account.email = v('email')

        if v('password'):

            if not v('old_password'):
                raise ValidationError('ACCOUNTS_INVALID_OLD_PASSWORD')

            if not account.password == password_hash(v('old_password')):
                raise ValidationError('ACCOUNTS_INVALID_OLD_PASSWORD')

            account.password = password_hash(v('password'))

        if v('first_name'):
            account.first_name = v('first_name')

        if v('last_name'):
            account.last_name = v('last_name')

        if v('address'):
            account.address = v('address')

        if v('address2'):
            account.address2 = v('address2')

        if v('city'):
            account.city = v('city')

        if v('state'):
            account.state = v('state')

        if v('zip'):
            account.zip = v('zip')

        if v('auto_recharge') != None:
            account.auto_recharge = 1 if v('auto_recharge') == "1" else 0

        if v('email_success') != None:
            account.email_success = 1 if v('email_success') == "1" else 0

        if v('email_fail') != None:
            account.email_fail = 1 if v('email_fail') == "1" else 0

        if v('email_list') != None:
            account.email_list = 1 if v('email_list') == "1" else 0

        if v('stripe_token') and v('last4'):
            try:
                customer = stripe.Customer.create(
                    description="%s Customer %s" % (
                        os.environ.get('PROJECT_NAME'), account.id),
                    email=account.email,
                    source=v('stripe_token') # 'trol'
                )
                account.stripe_token = customer["id"]
                account.stripe_card = customer["sources"]["data"][0]["id"]
                account.last4 = v('last4')
            except:
                payment = {'_DEBUG': traceback.format_exc()}
                data = {
                    'amount':       0,
                    'account_id':   account.id,
                    'source':       'stripe',
                    'debug':        json.dumps(payment),
                    'ip_address':   ip,
                    'payment_type': 'stored_payment'
                }
                failed_payment = FailedPayment(**data)
                db.session.add(failed_payment)
                db.session.commit()
                return jsonify(api_error('ACCOUNTS_STORED_PAYMENT_FAIL')), 400

#.........这里部分代码省略.........
开发者ID:lyonbros,项目名称:faxrobot,代码行数:103,代码来源:accounts.py


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