本文整理汇总了Python中model.User.user_from_name方法的典型用法代码示例。如果您正苦于以下问题:Python User.user_from_name方法的具体用法?Python User.user_from_name怎么用?Python User.user_from_name使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类model.User
的用法示例。
在下文中一共展示了User.user_from_name方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get
# 需要导入模块: from model import User [as 别名]
# 或者: from model.User import user_from_name [as 别名]
def get(self, verify_code_hash):
user_id, user = self.get_user()
data = {
'user': user,
'page_title': 'User Verification'
}
if '/' not in verify_code_hash:
self.render('verify_fail.html', **data)
return
username, verify_code = verify_code_hash.split('/')
test_user = User.user_from_name(username)
if not test_user:
logging.warning('VerifyUser: user not found in db.')
self.render('verify_fail.html', **data)
return
if test_user.verify_code == verify_code:
test_user.verified = True
test_user.verify_code = None
test_user.put()
logging.info('VerifyUser: user succesfully verified.')
self.render('verify.html', **data)
else:
self.render('verify_fail.html', **data)
示例2: post
# 需要导入模块: from model import User [as 别名]
# 或者: from model.User import user_from_name [as 别名]
def post(self):
email = self.request.get('email', '')
password = self.request.get('password', '')
other_username = self.request.get('other-user')
logging.info('%s, %s' % (email, other_username))
user = User.user_from_email(email)
if not user:
logging.info('not a valid email address')
self.render('error.html', **{'error_msg': 'You cannot do this'})
return
if not self.validate_user(user, password):
logging.info('username password fail')
self.render('error.html', **{'error_msg': 'You cannot do this'})
return
if not user.admin:
logging.info('Need to be admin to login as other user')
self.render('error.html', **{'error_msg': 'You cannot do this'})
return
other_user = User.user_from_name(other_username)
logging.info('Other user: %s' % other_user)
if not other_user:
logging.info('cannot find other user')
self.render('error.html', **{'error_msg': "Can't find other user"})
return
self.set_cookie(other_user)
self.redirect('/user/%d' % other_user.key.id())
示例3: input_errors
# 需要导入模块: from model import User [as 别名]
# 或者: from model.User import user_from_name [as 别名]
def input_errors(self, username, password, validate, email):
'''Return a list of errors with user registration data.'''
# collect error text strings
errors = []
# username errors
if not username:
errors.append('You forgot to enter a username.')
logging.warning('Register: forgot username.')
elif not self.valid_name(username):
errors.append(
'A Valid user name can contain only the characters '
'a-z, A-Z, 0-9, _ (underscore) and - (dash) and must be at '
'least 3 characters long.'
)
logging.warning('Register: invalid username: %s.', username)
user = User.user_from_name(username)
if user:
# user name already exists
errors.append(
'That user name already exists, please choose another one.'
)
logging.warning('Register: username already in use. %s', user)
# email errors
if not email:
errors.append('You forgot to enter an email address.')
logging.warning('Register: forgot email.')
elif not self.valid_email(email):
errors.append(
'Check your email address - it may not '
'be correct.')
logging.warning('Register: invalid email: %s', email)
else:
# maybe the email address is being used by another user - can't
# have more than one user with the same email address because the
# email address is used as login id
user = User.user_from_email(email)
if user:
# email address is attached to other user
errors.append(
'This email address is used by another user.'
)
msg = 'Register: email address already in use: %s'
logging.warning(msg, email)
# password errors
if not password or not validate:
errors.append('You forgot to enter your password twice.')
logging.warning('Register: forgot to enter password twice.')
elif password != validate:
msg = "Your password confirmation doesn't match your password."
errors.append(msg)
logging.warning('Register: validate != password.')
if not self.valid_pass(password):
errors.append(
'Not a valid password - it must contain at least '
'3 characters.')
logging.warning('Register: invalid password.')
return errors