Ejemplo n.º 1
0
def password_reset(token):
    ##如果用户已经认证,则转到主页
    if current_user.is_authenticated:
        return redirect(url_for('main.home'))
    ##使用User Model里的verify_reset_token函数来验证
    ##验证通过则返回相应的user对象
    user = User.verify_reset_token(token)
    ##如果验证不通过,返回None
    if not user:
        flash('Your token is invalid or expired', 'warning')
        return redirect(url_for('users.request_reset'))
    form = PasswordResetForm()
    ##提交后在数据库中更新密码
    if form.validate_on_submit():
        ## 算出密码的HASH值
        Hashed_password = bcrypt.generate_password_hash(
            form.password.data).decode('utf-8')
        ## 将hash值密码存入数据库
        user.password = Hashed_password
        db.session.commit()
        flash('Account password has been reset !', 'success')
        return redirect(url_for('users.login'))
    return render_template('password_reset.html',
                           title='Password Reset',
                           form=form,
                           user=user)
Ejemplo n.º 2
0
def reset_password(token):
    if current_user.is_authenticated:
        return redirect(url_for('main.home'))
    user = User.verify_reset_token(token)
    if user is None:
        flash('Böyle bir kullanıcı yok veya talebin süresi bitmiş', 'warning')
        return redirect(url_for('users.reset_request'))
    form = PasswordResetForm()
    if form.validate_on_submit():
        hash_pw = bcrypt.generate_password_hash(form.password.data).decode('utf-8')
        user.password = hash_pw
        db.session.commit()
        flash('Şifre başarılı bir şekilde değiştirildi', 'success')
        return redirect(url_for('users.login'))
    return render_template('request_password.html', form=form, legend='Şifre Yenileme')
Ejemplo n.º 3
0
def reset_token(token):
    if current_user.is_authenticated:  # User has to logout to reset the password.
        return redirect(url_for('main.home'))
    user = User.verify_reset_token(token)
    if not user:
        flash('That is an invalid or expired token!', 'warning')
        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('Your password has been updated! You can now login.', 'success')
        return redirect(url_for('users.login'))
    return render_template('reset_token.html',
                           title='Reset Password',
                           form=form)
Ejemplo n.º 4
0
def password_reset(token):
    if current_user.is_authenticated:
        return redirect(url_for('main.home'))
    user = User.validate_reset_token(token)
    if user is None:
        flash('Invalid or expired token, Kindly try again', 'warning')
        return redirect(url_for('users.password_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('Password has been updated', 'success')
        return redirect(url_for('users.login'))
    return render_template('password_reset.html',
                           form=form,
                           title='Password Reset')
Ejemplo n.º 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 a invalid or expired token", "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(f"You password has been updated! You are now be able to log in",
              "success")
        return redirect(url_for("users.login"))
    return render_template("reset_token.html",
                           title="Reset Password",
                           form=form)
Ejemplo n.º 6
0
def reset_token(token):
    if current_user.is_authenticated:
        return redirect(url_for('main.home'))
    user = User.verify_auth_token(token)
    if user is None:
        flash('Invalid or Expired token', 'danger')
        return redirect(url_for('users.reset_request'))

    form = PasswordResetForm()
    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'Your Password has been updated. Now you can login', 'success')
        return redirect(url_for('users.login'))
    return render_template('reset_password.html',
                           title='Update Password',
                           form=form)