Example #1
0
def reset_password(token):

    if current_user.is_authenticated:
        return redirect(url_for('main.home'))

    user = User.verify_reset_token(token)

    if not (user):
        flash('The Token Expired or token is invalid', 'warning')
        return redirect(url_for('users.reset_password_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 successfully updated!You can login now.',
              'success')

        return redirect(url_for('users.login'))
    form.email.data = user.email
    return render_template('reset_password.htm',
                           title='Reset Password',
                           form=form)
Example #2
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 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)
Example #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 token is invalid or expired', '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('password created. you can log in now','success')
        return redirect(url_for('users.login'))
    return render_template('reset_token.html', title='Reset Password', form=form)
Example #4
0
def reset_password(token):
    if current_user.is_authenticated:
        return redirect(url_for("main.home"))
    user = User.verify_reset_password_token(token)
    if not user:
        flash("Token is expired or invalid", "warning")
        return redirect(url_for('users.request_reset_password'))
    form = ResetPasswordForm()
    if request.method == "POST":
        if form.validate_on_submit():
            hashed_new_pass = bcrypt.generate_password_hash(form.new_password.data).decode('utf-8')
            user.password = hashed_new_pass
            db.session.commit()
            flash(f"Password updated successfully", 'success')
            return redirect(url_for("main.login"))
    return render_template("reset_password.html", title="Create New Password", form=form)
Example #5
0
def reset_token(token):
    if current_user.is_authenticated:
        return redirect(url_for('main.index'))
    user = User.verify_user_token(token)
    if user is None:
        flash('That token is invalid or has already expired', 'warning')
        return redirect(url_for('users.reset_request'))
    form = ResetPasswordForm()
    if form.validate_on_submit():
        hashed_pw = bcrypt.generate_password_hash(
            form.password.data).decode('utf-8')
        user.password = hashed_pw
        db.session.commit()
        flash('Your password has been changed!', 'success')
        return redirect(url_for('users.login'))
    return render_template('reset_token.html', form=form)
Example #6
0
def reset_token(token):
    if current_user.is_authenticated:
        return redirect(url_for('home'))
    # static method from User model, returns User or None
    user = User.verify_reset_token(token)
    if user is None:
        flash('This is an invalid or expired token', 'warning')
        # redirect to the page to generate token
        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 albe to log in', 'success')
        return redirect(url_for('users.login'))
    return render_template('reset_token.html', title='Reset Password', form=form)
Example #7
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("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(f'修改密码成功,现在可以登录', 'success')
        return redirect(url_for("users.login"))
    return render_template("reset_token.html",
                           title="Reset Password",
                           form=form)
Example #8
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("Invalid or expired token!", category="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()
        user.password = hashed_password
        db.session.commit()
        flash(f"Your password has been updated!", category="success")
        return redirect(url_for("users.login"))
    return render_template("reset_token.html",
                           form=form,
                           title="Reset Password")
Example #9
0
def reset_token():
    if current_user.is_authenticated:
        return redirect(url_for('main.home'))
    user = User.verify_reset_token(token)
    if user is None:
        flash('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(f'Password Updated for {form.username.data}, login now',
              'success')
        return redirect(url_for('users.login'))
    return render_template(
        url_for('users.reset_token.html', title='Reset Password', form=form))
Example #10
0
def reset_token(token):
    if current_user.is_authenticated:
        return redirect(url_for('main.home'))
    user = User.verify_reset_token(token)
    if not user:
        flash('Invalid or expired token', 'danger')
        return redirect(url_for('users.reset_request'))
    form = ResetPasswordForm()
    if form.validate_on_submit():
        hashed_pass = bcrypt.generate_password_hash(
            form.password.data).decode('utf-8')
        user.password = hashed_pass
        db.session.commit()
        flash('Your password has been updated! Be ready to log in', 'success')
        return redirect(url_for('users.login'))
    return render_template('reset_token.html',
                           title='Reset password',
                           form=form)
def reset_token(token):
    if current_user.is_authenticated:
        return redirect(url_for('main.index'))
    user = User.verify_reset_token(token)
    if user is None:
        flash("Il token non è valido o potrebbe essere scaduto", "warning")
        return redirect(url_for('users.reset_request'))
    form = ResetPasswordForm()
    if form.validate_on_submit():
        hashed_pw = bcrypt.generate_password_hash(
            form.password.data).decode('utf-8')
        user.password = hashed_pw
        db.session.commit()
        flash(f'Password modificata, prova ad accedere', 'success')
        return redirect(url_for('users.login'))

    return render_template('reset_token.html',
                           title="Reset Password",
                           form=form)
Example #12
0
def resetpassword(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 link", "warning")
        return redirect(url_for("users.request_reset"))
    form = ResetPasswordForm()
    if form.validate_on_submit():
        hashed_password = bcrypt.generate_password_hash(form.password.data)
        user.password = hashed_password
        db.session.commit()
        flash(
            "Your password has been changed,you can now login with your new password",
            "success")
        return redirect(url_for("users.login"))
    return render_template("reset_password.html",
                           form=form,
                           legend="Reset Password")
Example #13
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 valid 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
        user.save()
        flash(f'Your password have been updated! Then, you can login Now',
              'success')
        return redirect(url_for('users.login'))
    return render_template('reset_token.html',
                           form=form,
                           title='Reset Password Page')
Example #14
0
def reset_token(token):
    if current_user.is_authenticated:
        return redirect(url_for('main.home'))
    # token verfication method from User model
    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 new password and commit changes
        hashed_password = bcrypt.generate_password_hash(
            form.password.data).decode('utf-8')
        user.password = hashed_password
        db.session.commit()
        flash('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)