Example #1
0
def register():
        form=RegistrationForm() 
        if form.validate_on_submit():
            user=User(username=form.username.data)
            user.set_password(form.password.data)
            db.session.add(user)
            db.session.commit()
            flash("User registered.You may login now")
            return redirect(url_for("index"))
        else:
            return render_template ("register.html",form=form)
Example #2
0
def register():
    if current_user.is_authenticated:
        return redirect(url_for('index'))
    form = RegistrationForm()
    if form.validate_on_submit():
        user = User(username=form.username.data, email=form.email.data)
        user.set_password(form.password.data)
        db.session.add(user)
        db.session.commit()
        flash('Congratulations, you are now a registered user!')
        return redirect(url_for('login'))
    return render_template('register.html', title='Register', form = form)
Example #3
0
def register():
    form = RegisterForm()
    if form.validate_on_submit():
        # 注册,设置密码
        u = User(username=form.username.data, email=form.email.data)
        u.set_password(form.password.data)
        db.session.add(u)
        db.session.commit()

        # 跳转到用户列表
        flash('Congratulations, you are now a registered user!')
        return redirect(url_for('login'))
    return render_template("register.html", title="register", form=form)
Example #4
0
def register():

    # If the user is already logged in, there is no point using the password reset so I'm redirecting them to the index
    if current_user.is_authenticated:
        return redirect(url_for('main.index'))
    form = RegistrationForm()
    if form.validate_on_submit():
        user = User(username=form.username.data, email=form.email.data)
        user.set_password(form.password.data)
        db.session.add(user)
        db.session.commit()
        flash('Congratulations, you are now regisTURD!')
        return redirect(url_for('auth.login'))
    return render_template('auth/register.html', title='Register', form=form)
Example #5
0
def register():
    form = RegistrationForm()
    if request.method == 'POST' and form.validate():
        hashed_password = bcrypt.generate_password_hash(form.password.data).decode('utf-8')
        user = User(username=form.username.data, password=hashed_password, firstname=form.first_name.data, lastname=form.last_name.data, email=form.email.data)
        db.session.add(user)
        db.session.commit()
        flash(f'Account created for {form.username.data}!', 'success')
        return redirect(url_for('users.login'))
    return render_template('register.html', title='Register', form=form)
Example #6
0
def registration(user):
    """
    Registeration of new user
    :param user:
    :return:
    """
    new_user = User(Username=user['Username'], Password=user['Password'], Email=user['Email'])
    try:
        db.session.add(new_user)
        db.session.commit()
    except:  # ########################### Unique Constraint breaks ##################################
        print("This user already registered")
        abort(400)
Example #7
0
def reset_password(token):
    if current_user.is_authenticated:
        return redirect(url_for('index'))
    user = User.verify_reset_password_token(token)
    if not user:
        return redirect(url_for('index'))
    form = ResetPasswordForm()
    if form.validate_on_submit():
        user.set_password(form.password.data)
        db.session.commit()
        flash('Your password has been reset.')
        return redirect(url_for('login'))
    return render_template('reset_password.html', form=form)