本文整理汇总了Python中models.account.Account.public_data方法的典型用法代码示例。如果您正苦于以下问题:Python Account.public_data方法的具体用法?Python Account.public_data怎么用?Python Account.public_data使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.account.Account
的用法示例。
在下文中一共展示了Account.public_data方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: create
# 需要导入模块: from models.account import Account [as 别名]
# 或者: from models.account.Account import public_data [as 别名]
def create():
"""Creates a new user account"""
from library.mailer import email_registration
ip = fix_ip(request.headers.get('x-forwarded-for', request.remote_addr))
if request.method == 'POST':
v = request.values.get
data = {
'email': v('email'),
'password': v('password'),
'first_name': v('first_name'),
'last_name': v('last_name'),
'address': v('address'),
'address2': v('address2'),
'city': v('city'),
'state': v('state'),
'zip': v('zip'),
}
try:
account = Account(**data)
account.validate()
except ValidationError, err:
return jsonify(api_error(err.ref)), 400
try:
db.session.add(account)
db.session.commit()
except IntegrityError:
return jsonify(api_error('ACCOUNTS_CREATE_FAIL')), 400
email_registration(account)
return jsonify(account.public_data())
示例2: bootstrap
# 需要导入模块: from models.account import Account [as 别名]
# 或者: from models.account.Account import public_data [as 别名]
#.........这里部分代码省略.........
account_id = Account.authorize(request.values.get('api_key'))
ip = fix_ip(request.headers.get('x-forwarded-for', request.remote_addr))
if request.method == 'POST':
v = request.values.get
emails = Account.query.filter_by(email=v('email'))
account = emails.first()
o("Received bootstrap payment login: %s" % v('email'))
if account_id and account != None and account.id != account_id:
o("Account exists but user is logged in as someone else. Error.")
return jsonify(api_error('ACCOUNTS_LOGIN_ERROR')), 401
if account != None and account.password != password_hash(v('password'))\
and not account_id:
o("Account exists but password mismatch. Erroring out.")
return jsonify(api_error('ACCOUNTS_LOGIN_ERROR')), 401
temporary_password = None
if account == None:
o("Creating account with temporary password.")
temporary_password = random_hash(v('email'))[:8]
data = {
'email': v('email'),
'password': temporary_password
}
try:
account = Account(**data)
except ValidationError, err:
return jsonify(api_error(err.ref)), 400
try:
account.validate()
db.session.add(account)
except IntegrityError:
return jsonify(api_error('ACCOUNTS_CREATE_FAIL')), 400
o("Verifying payment with Stripe API.")
failed = False
try:
payment = stripe.Charge.create(
amount=int(float(v('amount')) * 100),
currency="usd",
source=v('stripe_token'),
description="Bootstrap payment"
)
except:
o("STRIPE UNEXPECTED ERROR:", sys.exc_info()[0])
failed = True
payment = {'_DEBUG': traceback.format_exc()}
o(payment)
if not failed and payment and payment.status == "succeeded":
o("Payment success.")
db.session.commit()
data = {
'account_id': account.id,
'amount': v('amount'),
'source': 'stripe',
'source_id': payment.id,
'ip_address': ip,
'initial_balance': account.credit,
'trans_type': 'payment'
}
trans = Transaction(**data)
db.session.add(trans)
db.session.commit()
o("Adding credit to account.")
charged = float(payment.amount) / float(100)
account.add_credit(charged)
email_payment(account, charged, trans.id, payment.source.last4,
temporary_password)
else:
o("--- PAYMENT FAIL. LOGGING INFO ---")
db.session.expunge_all()
data = {
'amount': v('amount'),
'account_id': account.id,
'source': 'stripe',
'debug': json.dumps(payment),
'ip_address': ip,
'payment_type': 'bootstrap'
}
failed_payment = FailedPayment(**data)
db.session.add(failed_payment)
db.session.commit()
return jsonify(api_error('ACCOUNTS_PAYMENT_FAIL')), 400
result = account.public_data()
if temporary_password:
result['temporary_password'] = temporary_password
return jsonify(result)