本文整理汇总了Python中models.account.Account.validate方法的典型用法代码示例。如果您正苦于以下问题:Python Account.validate方法的具体用法?Python Account.validate怎么用?Python Account.validate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.account.Account
的用法示例。
在下文中一共展示了Account.validate方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: create
# 需要导入模块: from models.account import Account [as 别名]
# 或者: from models.account.Account import validate [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 validate [as 别名]
def bootstrap():
"""
Implicitly creates a user account and logs them in by processing a Stripe
payment and email. If the email address belongs to a registered account, it
requires the account password to authorize the payment and login attempt.
"""
import json
import stripe
import sys
import traceback
from library.mailer import email_payment
from datetime import datetime
stripe.api_key = os.environ.get('STRIPE_SECRET_KEY')
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,
#.........这里部分代码省略.........
示例3: profile_edit
# 需要导入模块: from models.account import Account [as 别名]
# 或者: from models.account.Account import validate [as 别名]
def profile_edit(account_id=None):
from models.account import Account, Group
from helpers.account import AccountHelper
account = None
if not account_id:
if not app.access('profile', action='create'):
abort(403)
account = Account()
account.status = Account.STATUS_ACTIVE
account.group_id = Group.query.filter_by(alias=Group.GROUP_DEFAULT).first().id
else:
account_id = urllib.unquote_plus(account_id)
account = Account.query.filter_by(id=account_id).first()
if not account:
abort(404)
elif not app.access('profile', action='update', account=account):
abort(403)
print '[GROUP]',account.group_id, account.group
validationErrors = []
if request.method == 'POST' and request.form.get('csrf_token', None):
account.alias = request.values.get('account_alias', account.alias).strip()
account.first_name = request.values.get('account_first_name', account.first_name).strip()
account.last_name = request.values.get('account_last_name', account.last_name).strip()
account.email = request.values.get('account_email', account.email).strip()
account.info = request.values.get('account_info', account.info).strip()
account_group_id = request.values.get('account_group_id', '').strip()
account.status = int(request.form.get('account_status', account.status).strip())
account_group = None
if account_group_id:
account_group = Group.query.filter_by(id=account_group_id).first()
if not account_group:
account_group = Group.query.filter_by(alias=Group.GROUP_DEFAULT).first()
account.group_id = account_group.id
validationErrors = account.validate()
if not validationErrors:
account.save()
flash(g._t('profile submit success'))
if account_id:
return redirect(url_for('profile_view', account_id=urllib.quote_plus(account_id)))
else:
return redirect(url_for('profile_employees'))
if account_id:
title = g._t('edit profile')
else:
title = g._t('new profile')
if account_id:
breadcrumbs = (
(((not app.access('authenticated', account=account)) and g._t('employees') or ''), url_for('profile_employees')),
((app.access('authenticated', account=account) and g._t('me') or account.__str__()), url_for('profile_view', account_id=account_id)),
(title, "#")
)
else:
breadcrumbs = (
(g._t('employees'), url_for('profile_employees')),
(title, "#")
)
if app.access('profile', action='administer'):
groupList = AccountHelper.listGroups()
else:
groupList = AccountHelper.listActiveGroups()
return render_template('profile/edit.html', account_id=account_id, account=account, groupList=groupList, title=title, breadcrumbs=breadcrumbs, errors=validationErrors)