def reset_token(token):
    """reset password's token

    Arguments:
        token {Token} -- Object

    Returns:
        page -- If user is authenticated then redirect to home page.
        If user is none then shows warning.else show a message with updated password and
        redirect to login page.
    """
    if current_user.is_authenticated:
        return redirect(url_for("papers.home"))
    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 = bcrypt.generate_password_hash(
            form.password.data).decode("utf-8")
        user.password = hashed_password
        db.session.commit()
        flash("Your password has been updated! You are now able to log in",
              "success")
        return redirect(url_for("users.login"))
    return render_template(
        "users/reset_token.html",
        title="Reset Password",
        form=form,
        js_files=["js/users/reset_password.js"],
    )
示例#2
0
def reset_token(token):
    if current_user.is_authenticated:
        flash('Youre already logged in.', 'success')
        return redirect(url_for('home'))

    user = User.verify_reset_token(token)
    if user is None:
        flash('This is an invalid or expired token, please try again.',
              'warning')
        return redirect(url_for('reset_request'))
    form = ResetPasswordForm()

    if form.validate_on_submit():
        hashed_password = bcrypt.generate_password_hash(
            form.password.data).decode('utf-8')
        user.password = hashed_password
        db.session.commit()
        flash('Your password has been reset, log in to verify the change!',
              'success')
        return redirect(url_for('login'))

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


#@app.route() ///UPLOAD IMAGES\\\ https://www.youtube.com/watch?v=6WruncSoCdI
示例#3
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('That is an invalid or expired token', 'warning')
        return redirect(url_for('users.reset_request'))
    form = ResetPasswordForm()
    if form.validate_on_submit():
        hashed_password = bcrypt.generate_password_hash(form.password.data).decode('utf-8')
        user.password = hashed_password
        db.session.commit()
        flash('Your password has been updated! You are now able to log in.', 'success')
        return redirect(url_for('users.login'))
    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('The token is invalid or expired.', 'danger')
        return redirect(url_for('users.reset_request'))
    form = PasswordResetForm()
    if form.validate_on_submit():
        hashed_password = bcrypt.generate_password_hash(
            form.password.data).decode('utf-8')
        user.password = hashed_password
        db.session.commit()
        flash('The password has been updated.', 'success')
        return redirect(url_for('users.login'))
    return render_template('users/reset_token.html', form=form)
示例#5
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('That is an invalid or expired token', 'warning')
        return redirect(url_for('users.reset_request'))
    form = ResetPasswordForm()
    if form.validate_on_submit():
        hash_password = sha256_crypt.encrypt(str(form.password.data))
        user.password = hash_password
        db.session.commit()
        flash('Your password has been updated. You can log in', 'success')
        return redirect(url_for('users.login'))

    return render_template('reset_token.html',
                           title='Reset Password',
                           form=form)
示例#6
0
def reset_token(token):
    if current_user.is_authenticated:
        return redirect(url_for('home'))
    user = User.verify_reset_token(token)
    if not user:
        flash('Invalid or expired token', 'warning')
        return redirect(url_for('reset_request'))
    form = ResetPasswordForm()
    if form.validate_on_submit():
        hashed_password = bcrypt.generate_password_hash(
            form.password.data).decode('utf-8')
        user.password = hashed_password
        db.session.commit()
        flash(f'Your password has been updated! You can log in now.',
              "success")
        return redirect(url_for('login'))
    return render_template('reset_token.html',
                           title='Password Reset',
                           form=form)
示例#7
0
def reset_token(token):
    if current_user.is_authenticated:
        return redirect(url_for('main.home'))
    user = User.verify_reset_token(token)
    print('This is an invalid or expire token, Because user is or token :',
          user)
    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():
        password = bcrypt.generate_password_hash(
            form.password.data).decode('utf-8')
        user.password = password
        db.session.commit()
        flash('You password updated.', 'success')
        return redirect(url_for('users.login'))
    return render_template('reset_token.html',
                           token=token,
                           title='Reset Password',
                           form=form)