Example #1
0
def password_reset(token=None):
    reset_request = PasswordResetRequest.query.filter_by(token=token).first()
    if (reset_request is None) or reset_request.used:
        flash("Invalid password reset link", "danger")
        return redirect(url_for('.password_reset_request'))

    form = PasswordResetForm()
    if form.validate_on_submit():
        delta = datetime.now() - reset_request.time
        if delta.days > 0:
            flash("Trying to use expired password reset token", "danger")
            return redirect(url_for('.password_reset_request'))

        user = reset_request.user
        if user.email != form.email.data:
            flash("Email doesn't match password reset link", "danger")
            return render_template("auth/password_reset.html",
                                   form=form,
                                   token=token)

        user.set_password(form.password.data)
        reset_request.used = True
        db.session.add_all([user, reset_request])
        db.session.commit()
        flash("Your password has been changed", "success")
        return redirect(url_for('.login'))

    return render_template("auth/password_reset.html",
                           form=form,
                           token=token)
Example #2
0
def reset_password(token):
    if not current_user.is_anonymous:
        return redirect(url_for('dashboard.dashboard'))
    form = PasswordResetForm()
    if form.validate_on_submit():
        s = Serializer(current_app.config['SECRET_KEY'])
        try:
            data = s.loads(token)
        except:
            flash(
                'The password reset link is invalid or has expired, please tray again.',
                'danger')
            return redirect(url_for('dashboard.dashboard'))

        user = User.query.get(data.get('reset'))

        if user is None:
            flash(
                'The password reset link is invalid or has expired, please tray again.',
                'danger')
            return redirect(url_for('dashboard.dashboard'))
        if user.reset_password(token, form.password.data):
            flash('Your password has been updated.', 'success')
            login_user(user.seen())
        return redirect(url_for('dashboard.dashboard'))

    return render_template(
        'auth/reset_password.html',
        title="Reset your password",
        form=form,
    )
Example #3
0
def reset_password(token):
    form = PasswordResetForm()
    if form.validate_on_submit():
        if User.reset_password(token, form.password.data):
            flash('Password reset! use it to login.', 'success')
            return redirect(url_for('auth.login'))
        else:
            return redirect(url_for('main.home'))

    return render_template('account/reset_password.html', form=form)
Example #4
0
def password_reset(token):
    form = PasswordResetForm()
    if form.validate_on_submit():
        if User.reset_password(token, form.password.data):
            db.session.commit()
            flash('密码重置成功')
            return redirect(url_for('auth.login'))
        else:
            return redirect(url_for('main.index'))
    return render_template('auth/reset_password.html', form=form)
Example #5
0
def reset_password(token):
    if not current_user.is_anonymous:
        return redirect(url_for('main.index'))
    form = PasswordResetForm()
    if form.validate_on_submit():
        if User.reset_password(token, form.password.data):
            db.session.commit()
            flash('重置密码成功,请登录!')
            return redirect(url_for('auth.login'))
        else:
            flash('重置密码失败!')
    return render_template('auth/change_password.html', form=form)
Example #6
0
def password_reset(token):
    if not current_user.is_anonymous:
        return redirect(url_for('main.index'))
    form = PasswordResetForm()
    if form.validate_on_submit():
        if User.reset_password(token, form.password.data):
            db.session.commit()
            flash('Your password has been updated.')
            return redirect(url_for('auth.login'))
        else:
            return redirect(url_for('main.index'))
    return render_template('auth/reset_password.html', form=form)
Example #7
0
def password_reset(token: str):
    if current_user.is_authenticated:
        return redirect(url_for("users.home"))

    # user = User.verify_reset_token(token)
    # if not user:
    #     flash("invalid or expired token", "warning")
    #     return redirect(url_for("auth.reset_request"))

    form = PasswordResetForm()
    if form.validate_on_submit():
        pass
    return render_template("auth/password-reset.html", form=form)
Example #8
0
def password_reset(token):
    if current_user.is_authenticated:
        return redirect(url_for('main.index'))
    user = User.verify_password_reset_token(token)
    if not user:
        return redirect(url_for('main.index'))
    form = PasswordResetForm()
    if form.validate_on_submit():
        user.set_password(form.password.data)
        db.session.commit()
        flash('Your password has been reset.')
        return redirect(url_for('auth.login'))
    return render_template('auth/password_reset.html', form=form)
Example #9
0
def password_reset(token):
    if not current_user.is_anonymous:
        return redirect(url_for('main.index'))
    form = PasswordResetForm()
    if form.validate_on_submit():
        user = User.query.filter_by(email=form.email.data).first()
        if user is None:
            return redirect(url_for('main.index'))
        if user.reset_password(token, form.password.data):
            flash('Your password has been updated.')
            return redirect(url_for('auth.login'))
        else:
            return redirect(url_for('main.index'))
    return render_template('auth/reset_password.html', form=form)
Example #10
0
def password_reset(token):
    if not current_user.is_anonymous():
        return redirect(url_for('main.index'))
    form = PasswordResetForm()
    if form.validate_on_submit():
        user = User.query.filter_by(email=form.email.data).first()
        if user is None:
            return redirect(url_for('main.index'))
        if user.reset_password(token, form.password.data):
            flash(_('Mật khẩu của bạn đã được thay đổi'))
            return redirect(url_for('auth.login'))
        else:
            return redirect(url_for('main.index'))
    return render_template('auth/reset_password.html', form=form)
Example #11
0
def password_reset(token):
    if not current_user.is_anonymous:
        return redirect(url_for("main.index"))
    form = PasswordResetForm()
    if form.validate_on_submit():
        user = User.query.filter_by(email=form.email.data).first()
        if user is None:
            return redirect(url_for("main.index"))
        if user.reset_password(token, form.password.data):
            flash("Your password has been updated.")
            return redirect(url_for("auth.login"))
        else:
            return redirect(url_for("main.index"))
    return render_template("auth/reset_password.html", form=form)
Example #12
0
def passwordreset(token):
    if current_user.is_authenticated:
        return redirect(url_for('main.index'))
    user = User.verify_password_reset_token(token)
    if not user:
        return redirect(url_for('auth.welcome'))
    form = PasswordResetForm()
    if form.validate_on_submit():
        user.set_password(form.password_new.data)
        user.save()
        flash("Your password has been reset.")
        return redirect(url_for('auth.welcome'))
    if not form.validate():
        flash("Password reset failed.  Please correct errors.")
    return render_template('auth/reset_password.html', form=form)
def password_reset():
    if current_user.is_authenticated():
        return redirect(url_for("main.home"))

    form = PasswordResetForm()
    if form.validate_on_submit():
        email = form.email.data
        user = User.query.filter_by(email=email).first()
        user.create_token_for("reset")
        db.session.commit()
        send_password_reset_mail(user)
        flash("The password reset instructions are sent to your email.",
              "success")
        return redirect(url_for("main.home"))

    return render_template("password_reset.html", form=form)
Example #14
0
def reset_password(token):
    if current_user.is_authenticated:
        return redirect(url_for("lobby.lobby"))

    user = users.verify_password_reset_token(token)
    if not user:
        return redirect(url_for("lobby.lobby"))

    form = PasswordResetForm()
    if form.validate_on_submit():
        user.set_password(form.password.data)
        db.session.commit()
        flash("You successfully reset your password.")
        return redirect(url_for("auth.login"))

    return render_template("reset_password.html", title="Reset My Password", form=form)
Example #15
0
def password_reset(token):
    #如果当前用户非匿名,重返主页面
    if not current_user.is_anonymous:
        return redirect(url_for('main.index'))
#表单实例化
    form = PasswordResetForm()
    #如果提交
    if form.validate_on_submit():
        #通过token验证
        if User.reset_password(token, form.password.data):
            db.session.commit()
            flash('Your password has been updated.')
            return redirect(url_for('auth.login'))
        #未通过验证,定向回主页
        else:
            return redirect(url_for('main.index'))
    return render_template('auth/reset_password.html', form=form)
def reset_password(token):
    # Prevent already logged in users resetting password
    if current_user.is_authenticated:
        return redirect(url_for('main.home'))
    # Verify token and on success get user object
    user = User.verify_reset_password_token(token)
    # If token is wrong redirect to home page
    if not user:
        return redirect(url_for('main.home'))
    form = PasswordResetForm()
    # Check if form is ok. Password must be min 10 char
    if form.validate_on_submit():
        # Set new password and redirect to login page
        user.set_password(form.password.data)
        db.session.commit()
        flash('Your password has been reset.')
        return redirect(url_for('auth.login'))
    return render_template('auth/password_reset.html', form=form)
Example #17
0
def password_reset(token):
    """View function to reset user passwords if the token is valid"""

    user = User.verify_password_reset_token(token)
    if not user:
        flash('Invalid link for password reset. '
              'Please double check your email and try again.')
        return redirect(url_for('auth.login'))

    form = PasswordResetForm()
    if form.validate_on_submit():
        user.set_password(form.password.data)
        db.session.commit()
        flash('Your password has been successfully reset. Please log in.')
        return redirect(url_for('auth.login'))

    return render_template('auth/password_reset.html', form=form,
                           title='Reset Password')
Example #18
0
def password_reset(token):
    if not current_user.is_anonymous:
        return redirect(url_for("auth.portal"))
    form = PasswordResetForm()
    if form.validate_on_submit():
        user = User.query.filter_by(
            email=form.email.data.lower().strip()).first()
        if user is None:
            return redirect(url_for("main.index"))
        if user.reset_password(token, form.password.data):

            flash("Your password has been updated", "success")
            return redirect(url_for("auth.login"))
        else:
            flash(
                "We were unable to update your password. Please try again or contact support.",
                "danger")
            return redirect(url_for("main.index"))
    return render_template("auth.html",
                           form_title="Reset Your Password",
                           form=form)
Example #19
0
def reset_password(token):
    """Corfirm password reset token."""
    try:
        email = User.confirm_password_reset_token(token)
    except BadSignature:
        flash('The password reset link is invalid or has expired.', 'danger')
        return redirect(url_for('main.index'))

    pass_form = PasswordResetForm(reset_token=token)

    if pass_form.validate_on_submit():
        user = User.query.filter_by(email=email).first()
        if user is not None:
            try:
                user.confirm_security_token(pass_form.reset_token.data)
            except BadSignature:
                flash('The password reset link is invalid or has expired.',
                      'danger')
                return redirect(url_for('main.index'))

            user.password = pass_form.password.data

            if not user.confirmed:
                user.confirmed = True

            sql.session.add(user)
            sql.session.commit()
            flash('Your password has been successfully reset. You can now \
                  login using your new password.', 'success')
            return redirect(url_for('auth.login'))

    page_vars = {
        'title': 'Set New Password',
        'page_header': 'Set your new password',
        'form': pass_form
    }
    return render_template('auth/new-password.html', **page_vars)