Example #1
0
def register():
    if current_user.is_authenticated:
        return redirect(url_for('home'))

    form = RegistrationForm()
    if form.validate_on_submit():
        hashed_password = bcrypt.generate_password_hash(form.password.data).decode('utf-8')
        user = User(username=form.username.data, email=form.email.data, password=hashed_password)
        db.session.add(user)
        db.session.commit()
        flash('Your account has beencreated! You are now able to log in', 'success')
        return redirect(url_for('login'))
    return render_template('register.html', title='Register', form=form)
Example #2
0
def register():
    form = RegistrationForm()
    if form.validate_on_submit():
        hashed_pwd = \
            bcrypt.generate_password_hash(form.password.data).decode('utf-8')
        user = User(username=form.username.data,
                    email=form.email.data,
                    password=hashed_pwd,
                    role=form.role.data)
        db.session.add(user)
        db.session.commit()
        flash('Your account has been created!', 'check')
        return redirect(url_for('login'))
    return render_template('register.html', form=form, title='Register')
Example #3
0
def register():
    form = RegistrationForm()
    
    if form.validate_on_submit():
        hashed_password = bcrypt.generate_password_hash(form.password.data).decode('utf-8')
        user = User(username=form.username.data, email=form.email.data, password=hashed_password)
        db.session.add(user)
        db.session.commit()
        flash('Your account has been created! You are now able to log in', 'success')
        print("'" + form.username.data + "' has created a accont")
        
        return redirect(url_for("login"))
    
    return render_template("register.html", title="Register", form=form)
Example #4
0
def first():
    db.create_all()
    form = RegistrationForm()
    if form.validate_on_submit():
        print('true')
        pett = Pet(kind=form.kind.data,
                   nickname=form.nickname.data,
                   age=form.age.data)
        db.session.add(pett)
        db.session.commit()
        # print(form.kind.data)
        # print(form.nickname.data)
        # print(form.age.data)
        print(db.session.query(Pet).count())
        flash(u'Питомец {} записан!'.format(form.nickname.data))
        return redirect(url_for('second'))
    print(db.session.query(Pet).count())
    return render_template('first.html', form=form)
Example #5
0
def register():
    '''
    注册,并发送激活邮件。
    即使通过配置程序已经可以在末尾自动提交数据库变化,这里也要添加db.session.commit(),因为后续确定令牌要用到id。
    '''
    form = RegistrationForm()
    if form.validate_on_submit():
        user = User(email=form.email.data, name=form.name.data, password=form.password.data, confirmed=1, image='img/default_avatar.jpg')
        if User.query.filter_by(email=form.email.data).first():
            flash('该邮箱已注册')
        else:
            db.session.add(user)
            db.session.commit()
            # token = user.generate_confirmation_token()
            # send_email(user.email, '激活邮箱', 'email/confirm', user=user, token=token)
            # flash('一封激活邮件已发往您的注册邮箱,请尽快前往确认。')
            return redirect(url_for('main.signin'))
    return render_template('register.html', form=form)
Example #6
0
def register():
    if current_user.is_authenticated:
        flash("Already registered", "success")
        return redirect(url_for("home"))
    form = RegistrationForm()
    if form.validate_on_submit():
        hashed_password = bcrypt.generate_password_hash(
            form.password.data).decode("utf-8")
        user = User(
            username=form.username.data,
            email=form.email.data,
            password=hashed_password,
            category=form.category.data,
            company=form.company.data,
            position=form.position.data,
        )
        db.session.add(user)
        db.session.commit()
        flash(f"Your account has been created you can now login!", "success")
        return redirect(url_for("login"))
    return render_template("register.html", form=form)
Example #7
0
def register():
    if current_user.is_authenticated:
        return redirect(url_for('main.home'))
    form = RegistrationForm()
    try:
        if form.validate_on_submit():

            hashed_password = bcrypt.generate_password_hash(
                form.password.data).decode('utf-8')
            user = User(name=form.name.data,
                        password=hashed_password,
                        api_code=form.api_code.data)  #add new user, 要符合form
            db.session.add(user)  #寫入資料庫
            db.session.commit()

            flash('Your account has been created! You are now able to log in',
                  'success')
            return redirect(url_for('main.login'))
    except:
        flash('Your account name already used!', 'warning')
    return render_template('register.html', title='Register', form=form)
Example #8
0
def register():
	form = RegistrationForm()
	if form.validate_on_submit():
		flash(f"Account created for {form.name.data}!", 'success')
		return redirect(url_for('home'))
	return render_template('register.html', form=form)