本文整理汇总了Python中models.user.User.validate方法的典型用法代码示例。如果您正苦于以下问题:Python User.validate方法的具体用法?Python User.validate怎么用?Python User.validate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.user.User
的用法示例。
在下文中一共展示了User.validate方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_user_name_required
# 需要导入模块: from models.user import User [as 别名]
# 或者: from models.user.User import validate [as 别名]
def test_user_name_required(db_conn):
"""
Ensure a name is required.
"""
user = User()
errors = user.validate()
assert len(errors) > 0
assert "name" in [e["name"] for e in errors]
示例2: test_user_password_minlength
# 需要导入模块: from models.user import User [as 别名]
# 或者: from models.user.User import validate [as 别名]
def test_user_password_minlength(db_conn):
"""
Ensure an password is long enough.
"""
user = User({"password": "abcd"})
errors = user.validate()
assert "password" in [e["name"] for e in errors]
assert "Must have minimum length of 8." in [e["message"] for e in errors]
示例3: test_user_email_format
# 需要导入模块: from models.user import User [as 别名]
# 或者: from models.user.User import validate [as 别名]
def test_user_email_format(db_conn):
"""
Ensure an email is formatted.
"""
user = User({"email": "other"})
errors = user.validate()
assert "email" in [e["name"] for e in errors]
assert "Must be an email." in [e["message"] for e in errors]
示例4: post
# 需要导入模块: from models.user import User [as 别名]
# 或者: from models.user.User import validate [as 别名]
def post(self):
try:
email = self.get_argument("email")
try:
user = User.objects.get(email=email)
except User.DoesNotExist:
raise ValidationError('dup_email')
user = User()
user.email = email
user.validate()
except ValidationError as e:
self.error()
self.ERRORS[str(e)] = True
self.render_signup()
else:
self.render_password(email=email)
示例5: signup
# 需要导入模块: from models.user import User [as 别名]
# 或者: from models.user.User import validate [as 别名]
def signup():
next_url = request.args.get('next') or request.form.get('next') or ''
if not g.user.is_anonymous():
return redirect(next_url or url_for('home'))
user = User()
if request.method == 'POST':
username = request.form.get('username') or ''
password = request.form.get('password') or ''
#discoverable = request.form.get('discoverable_by_email', True, bool) == True
user = User(username=username, password=password)
if user.validate():
user.save_new_user()
login_user(user, True)
return redirect(next_url or url_for('home'))
return render(page='signup', title=gettext('Sign up'), section='signup', user=user, next_url=next_url)
示例6: login
# 需要导入模块: from models.user import User [as 别名]
# 或者: from models.user.User import validate [as 别名]
def login():
'''
username: string
passwd: 32bit md5 code
'''
try:
username = request.form['username']
passwd = request.form['passwd']
except KeyError:
return error(400, u'参数错误')
if len(passwd) == 0 or len(username) == 0:
return error(10005, u'用户名密码不能为空')
user = User.validate(username, passwd)
if not user:
return error(10006, u'用户名或密码错误')
login_user(user)
# login_user(user, remember = remember_me)
return user.dict()