本文整理汇总了Python中app.users.models.User.banned方法的典型用法代码示例。如果您正苦于以下问题:Python User.banned方法的具体用法?Python User.banned怎么用?Python User.banned使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app.users.models.User
的用法示例。
在下文中一共展示了User.banned方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: register
# 需要导入模块: from app.users.models import User [as 别名]
# 或者: from app.users.models.User import banned [as 别名]
def register():
"""
Registration Form
"""
form = RegisterForm(request.form)
errors = []
if form.is_submitted():
is_validated = True
if form.name.data.strip() == '':
is_validated = False
errors.append(gettext('Username is required'))
#validate email
if form.email.data.strip() == '':
is_validated = False
errors.append(gettext('Email is required'))
#validate valid email
match = re.search(r'^[email protected]([^[email protected]][^@]+)$', form.email.data.strip())
if not match:
is_validated = False
errors.append(gettext('Invalid email address'))
if form.password.data.strip() == '':
is_validated = False
errors.append(gettext('Password field is required'))
if form.confirm.data.strip() == '':
is_validated = False
errors.append(gettext('You have to confirm your password'))
if form.confirm.data != form.password.data:
is_validated = False
errors.append(gettext('Passwords must match'))
if len(form.recaptcha.errors) > 0:
is_validated = False
errors.append(gettext('Captcha was incorrect'))
if is_validated:
same_username_user = User.query.filter_by(username=form.name.data).first()
same_email_user = User.query.filter_by(email=form.email.data).first()
if same_email_user is not None:
errors.append(gettext('Duplicate email address'))
if same_username_user is not None:
errors.append(gettext('Duplicate username'))
if len(errors) > 0:
return render_template("users/register.html", form=form, errors=errors)
# Insert the record in our database and commit it
user = User(username=form.name.data.lower(), email=form.email.data,
password=generate_password_hash(form.password.data))
user.verification_code = utilities.generate_random_string(50)
user.banned = 2
db.session.add(user)
db.session.commit()
# send confirm email and redirect to confirm page
email_activation = Journal.query.filter(Journal.id==120).first().get_journal_content(session['locale'])
send_mail([user.email], email_activation.title, render_template_string(email_activation.content, activate_link=url_for('users.verify_account', code=user.verification_code, _external=True)))
return render_template("users/register_finish.html", email=user.email)
else:
return render_template("users/register.html", form=form, errors=errors)
return render_template("users/register.html", form=form, errors=[])