def test_valid_reset_token(self):
     u = User(password='******')
     db.session.add(u)
     db.session.commit()
     token = u.generate_reset_token()
     self.assertTrue(User.reset_password(token, 'dog'))
     self.assertTrue(u.verify_password('dog'))
 def test_invalid_reset_token(self):
     u = User(password='******')
     db.session.add(u)
     db.session.commit()
     token = u.generate_reset_token()
     self.assertFalse(User.reset_password(token + 'a', 'horse'))
     self.assertTrue(u.verify_password('cat'))
Exemple #3
0
def password_reset(token):
    """
    遗忘密码后收到邮件后重置密码
    :param token:
    :return:
    """
    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)