本文整理汇总了Python中database.User.put方法的典型用法代码示例。如果您正苦于以下问题:Python User.put方法的具体用法?Python User.put怎么用?Python User.put使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类database.User
的用法示例。
在下文中一共展示了User.put方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: create_user
# 需要导入模块: from database import User [as 别名]
# 或者: from database.User import put [as 别名]
def create_user(username, password, email):
salt = make_salt()
hashed = hash_password(password, salt)
u = User(username=username,
email=email,
salt=salt,
password=hashed)
u.put()
示例2: post
# 需要导入模块: from database import User [as 别名]
# 或者: from database.User import put [as 别名]
def post(self):
username = self.request.get('user')
password = self.request.get('password')
password_repeated = self.request.get('verify')
email = self.request.get('email')
# Validate input and generate needed error messages
if not validations.is_valid_username:
username_error = 'Invalid Username'
elif User.username_exists(username):
username_error = 'That username is already in use.'
else:
username_error = ''
password_error = ('' if validations.is_valid_password(password)
else 'Invalid Password.')
password_repeated_error = ('' if (password_error or
password == password_repeated)
else 'Passwords do not match.')
email_error = ('' if (not email or validations.is_valid_email(email))
else 'Invalid Email Address.')
errors = [username_error, password_error,
password_repeated_error, email_error]
# If success, send to welcome page
if all(not error for error in errors):
# Success!
# Hash password
hashed_pwd = auth.make_pw_hash(username, password)
# Add to database
new_user_entry = User(username=username,
password=hashed_pwd,
email=email,
parent=ndb.Key('Users', 'user_group'))
# if email:
# new_user_entry.email = email
new_user_entry.put()
# Add cookie
self.force_login(username)
redirect_when_finished = self.request.get('redirect_when_finished')
return self.redirect_with_queries(
'/welcome',
[('redirect_when_finished', redirect_when_finished)])
else:
# If any checks failed, send back to the signup page
# with error messages. Repopulate fields except for passwords.
self.response.out.write(self.template.render(
entered_username=username,
email=email,
username_error=username_error,
password_error=password_error,
password_repeated_error=password_repeated_error,
email_error=email_error
))