本文整理匯總了Python中openspending.model.account.Account.public_email方法的典型用法代碼示例。如果您正苦於以下問題:Python Account.public_email方法的具體用法?Python Account.public_email怎麽用?Python Account.public_email使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類openspending.model.account.Account
的用法示例。
在下文中一共展示了Account.public_email方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: register
# 需要導入模塊: from openspending.model.account import Account [as 別名]
# 或者: from openspending.model.account.Account import public_email [as 別名]
def register(self):
"""
Perform registration of a new user
"""
# We must allow account creation
require.account.create()
# We add the config as a context variable in case anything happens
# (like with login we need this to allow subscriptions to mailing lists)
c.config = config
# Disable the cache (don't want anything getting in the way)
self._disable_cache()
# Initial values and errors
errors, values = {}, None
# If this is a POST operation somebody is trying to register
if request.method == 'POST':
try:
# Get the account register schema (for validation)
schema = AccountRegister()
# Set values from the request parameters
# (for validation and so we can autofill forms)
values = request.params
# Grab the actual data and validate it
data = schema.deserialize(values)
# Check if the username already exists, return an error if so
if Account.by_name(data['name']):
raise colander.Invalid(
AccountRegister.name,
_("Login name already exists, please choose a "
"different one"))
# Check if passwords match, return error if not
if not data['password1'] == data['password2']:
raise colander.Invalid(AccountRegister.password1,
_("Passwords don't match!"))
# Create the account
account = Account()
# Set username and full name
account.name = data['name']
account.fullname = data['fullname']
# Set email and if email address should be public
account.email = data['email']
account.public_email = data['public_email']
# Hash the password and store the hash
account.password = generate_password_hash(data['password1'])
# Commit the new user account to the database
db.session.add(account)
db.session.commit()
# Perform a login for the user
who_api = get_api(request.environ)
authenticated, headers = who_api.login({
"login": account.name,
"password": data['password1']
})
# Add the login headers
response.headers.extend(headers)
# Subscribe the user to the mailing lists
errors = subscribe_lists(('community', 'developer'), data)
# Notify if the mailing list subscriptions failed
if errors:
h.flash_notice(_("Subscription to the following mailing " +
"lists probably failed: %s.") % ', '.join(errors))
# Registration successful - Redirect to the front page
return redirect("/")
except colander.Invalid, i:
# Mark colander errors
errors = i.asdict()