當前位置: 首頁>>代碼示例>>Python>>正文


Python User.verification_code方法代碼示例

本文整理匯總了Python中app.users.models.User.verification_code方法的典型用法代碼示例。如果您正苦於以下問題:Python User.verification_code方法的具體用法?Python User.verification_code怎麽用?Python User.verification_code使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在app.users.models.User的用法示例。


在下文中一共展示了User.verification_code方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: register

# 需要導入模塊: from app.users.models import User [as 別名]
# 或者: from app.users.models.User import verification_code [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=[])
開發者ID:DF-thangld,項目名稱:SketchupOulu,代碼行數:67,代碼來源:views.py


注:本文中的app.users.models.User.verification_code方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。