Пример #1
0
def register():
    if current_user.is_authenticated:
        return redirect(url_for('home'))
    form = RegistrationForm()
    if form.validate_on_submit():
        hashed_password = brcypt.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(f' Your Account has been creted . You can login now', 'success')
        return redirect(url_for('login'))
    return render_template('register.html', title='Register', form=form)
Пример #2
0
def reset_token(token):
    if current_user.is_authenticated:
        return redirect(url_for('home'))
    user = User.verify_reset_token(token)
    if user is None:
        flash('That is an invalid or expired token','warning')
        return redirect(url_for('reset_request'))
    form = ResetPasswordForm()
    if form.validate_on_submit():
        hashed_password = brcypt.generate_password_hash(form.password.data).decode('utf-8')
        user.password = hashed_pasword
        db.session.commit()
        flash(f' Your Account has been creted . You can login now', 'success')
        return redirect(url_for('login'))
    return render_template('rest_token.html', title='Reset Pasword', form=form)
Пример #3
0
def reset_token(token):
    if current_user.is_authenticated:
        return redirect(url_for("main.home_page"))
    user = User.verify_reset_token(token)
    if user is None:
        flash("That is an invalid or expired token", "warning")
        return redirect(url_for("users.reset_request"))
    form = ResetPasswordForm()
    if form.validate_on_submit():
        hashed_password = brcypt.generate_password_hash(
            form.password.data).decode("utf-8")
        user.password = hashed_password
        db.session.commit()
        flash("Your password has been updated! You can now log in", "success")
        return redirect(url_for("users.login_page"))
    return render_template("reset_token.html",
                           title="Reset Password",
                           form=form)
Пример #4
0
def reset_token(token):
    if current_user.is_authenticated:
        return redirect(url_for('main.home'))
    user = User.verify_reset_token(token)
    if user is None:
        flash(f'That is an invalid or expired token!', 'danger')
        return redirect(url_for('users.reset_request'))
    form = ResetPasswordForm()
    if form.validate_on_submit():
        hash_password = brcypt.generate_password_hash(
            form.password.data).decode('utf-8')
        user.password = hash_password
        db.session.commit()
        flash(f'Your password has been updated! You are now able to log in ',
              'success')
        return redirect(url_for('users.login'))
    return render_template('reset_password.html',
                           title='Reset Password',
                           form=form)
Пример #5
0
def register_page():
    if current_user.is_authenticated:
        return redirect(url_for("main.home_page"))
    form = RegistrationForm()
    if form.validate_on_submit():
        hashed_password = brcypt.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 can now Login!".format(
                {form.username.data}),
            "success",
        )
        return redirect(url_for("users.login_page"))
    return render_template("register.html", title="Register", form=form)