本文整理汇总了Python中models.user.User.by_name方法的典型用法代码示例。如果您正苦于以下问题:Python User.by_name方法的具体用法?Python User.by_name怎么用?Python User.by_name使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.user.User
的用法示例。
在下文中一共展示了User.by_name方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: done
# 需要导入模块: from models.user import User [as 别名]
# 或者: from models.user.User import by_name [as 别名]
def done(self):
u = User.by_name(self.username)
if u:
msg = " The user already exists"
self.render('signup_page.html', error1=msg)
else:
u = User.register(self.username, self.password, self.email)
u.put()
self.login(u)
self.redirect('/welcome')
示例2: post
# 需要导入模块: from models.user import User [as 别名]
# 或者: from models.user.User import by_name [as 别名]
def post(self):
'''
creates a new user instance and inserts it into the db.
logs the user in, then redirects the user to the welcome page.
if there are any errors, render the signup form again with
the appropriate saved data and error messages
'''
have_error = False
self.username = self.request.get("username").encode("latin-1")
self.password = self.request.get("password").encode("latin-1")
self.verify = self.request.get("verify").encode("latin-1")
self.email = self.request.get("email").encode("latin-1")
params = dict(username=self.username,
email=self.email)
# check for any errors
if not valid_username(self.username):
params['username_error'] = "That's not a valid username"
have_error = True
elif User.by_name(self.username):
params['username_error'] = 'That user already exists'
have_error = True
if not valid_password(self.password):
params['password_error'] = "That's not a valid password"
have_error = True
elif self.password != self.verify:
params['verify_error'] = "Your passwords don't match"
if not valid_email(self.email):
params['email_error'] = "That's not a valid email"
have_error = True
# there's some error(s)
if have_error:
self.render("users/signup.html", **params)
# succest!!
else:
user = User.register(self.username, self.password, self.email)
user.put()
self.login(user)
self.redirect('/welcome')
示例3: post
# 需要导入模块: from models.user import User [as 别名]
# 或者: from models.user.User import by_name [as 别名]
def post(self):
username_error = invalid_email = invalid_password = verify_password_error = None
#Retrieve form information from user sign up submission
user_username = self.request.get("username")
user_password = self.request.get("password")
user_verify_password = self.request.get("verify")
user_email = self.request.get("email")
params = dict(username = user_username,
email = user_email)
username = valid_name(user_username)
password = valid_password(user_password)
verify_password = None
email = None
if user_email:
email = valid_email(user_email)
if not email:
params['invalid_email'] = "That's not a valid email."
if not username:
params['username_error'] = "That's not a valid username."
elif (User.by_name(user_username)):
username = None
params['username_error'] = "User already exists !"
if password:
verify_password = valid_verify_password(user_password, user_verify_password)
if not verify_password:
params['verify_password_error'] = "Your passwords didn't match."
else:
params['invalid_password'] = "That wasn't a valid password."
if username and password and verify_password and not invalid_email:
password_hash = hash_pwd(user_username, user_password)
user = User(username = user_username, password = password_hash, email = user_email)
user.put()
self.response.headers.add_header('Set-Cookie','user_id=%s; Path=/' % make_secure_value(str(user.key().id())))
self.redirect("/blog/welcome")
else:
self.render("signup.html", **params)
示例4: post
# 需要导入模块: from models.user import User [as 别名]
# 或者: from models.user.User import by_name [as 别名]
def post(self):
params = {}
have_error = False
params['username'] = user_username = self.request.get('username')
user_password = self.request.get('password')
user_verify = self.request.get('verify')
params['email'] = user_email = self.request.get('email')
valid_user = valid_username(user_username)
valid_pass = valid_password(user_password)
valid_mail = valid_email(user_email)
if not valid_user:
have_error = True
params['error_username'] = 'That was not a valid username'
if User.by_name(user_username):
have_error = True
params['error_username'] = 'Username already exists'
if not valid_pass:
have_error = True
params['error_password'] = 'Not a valid password'
if user_password != user_verify:
have_error = True
params['error_verify'] = "Your passwords didn't match"
if not valid_mail:
have_error = True
params['error_email'] = 'That was not a valid e-mail'
if have_error:
self.render('signup.html', **params)
else:
new_user = User.register(user_username, user_password, user_email)
new_user.put()
self.user = new_user
self.login(self.user)
self.redirect('/welcome')