示例#1
0
def reset(key):
    form = ResetPasswordForm()
    if form.validate_on_submit():
        form.user.reset_password(form.password.data)
        flash(
            "Your password has been successfully reset!",
            "alert-success",
        )
        login_user(form.user, force=True)
        return redirect(url_for('default.home'))
    else:
        flash_form_errors(form)
        form.key.data = key
        return render_template('auth/reset.html', form=form, key=key)
示例#2
0
def forgot(key=None):
    pw = PasswordReset.query.filter_by(key=key or 'invalid').first()
    if pw:
        form = ResetPasswordForm()
        if form.validate_on_submit():
            form.user.reset_password(form.password)
            db.session.commit()
            login_user(form.user, remember=True)
            flash('Your password has been reset!', 'alert-success')
            return redirect(url_for('default.home'))
        else:
            return render_template('auth/reset.html', key=key, form=form)
    else:
        form = ForgotForm()
        if form.validate_on_submit():
            form.user.send_password_reset()
            flash('A password reset link has been sent to your email.', 'alert-success')
            return redirect(url_for('default.home'))
        else:
            return render_template('auth/forgot.html', form=form, key=key)