예제 #1
0
def reset_token(token):
    if current_user.is_authenticated:
        return redirect(url_for('home'))
    username = validate_token(token)

    if username:
        user = User.query.filter_by(username=username).first()

        form = ResetPasswordForm()
        if request.method == "POST":
            if form.validate_on_submit():
                if form.password.data == form.confirm_password.data:
                    update = User.query.filter_by(id=user.id).update({
                        User.password_hash:
                        user.set_password(password=form.password.data)
                    })
                    user.save(user)
                    print(update)
                    flash(
                        'Your password has been updated! You are now able to log in',
                        'success')
                    return redirect(url_for('login'))

                else:
                    flash('Password miss match', 'danger')

        return render_template('reset_token.html',
                               title='Reset Password',
                               form=form)

    return render_template('forgot_password.html',
                           title='Reset Password',
                           form=form)
예제 #2
0
def contact():
    form = LoginForm()
    token = request.cookies.get('token')
    if token:
        redis_token = redis_client.get(token)
        if redis_token:
            username = validate_token(redis_token)
            if username:
                user = User.query.filter_by(username=username).first()
                return render_template('contact.html', title='Account')
            else:

                return render_template('login.html', title='Login', form=form)
        else:

            return render_template('login.html', title='Login', form=form)
    else:

        return render_template('login.html', title='Login', form=form)
    return render_template('login.html', title='Login', form=form)